ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
6502.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSì COM'è", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "cpu.h"
36
37#include <math.h>
38#include <stddef.h>
39#include <ctype.h>
40
41/****************************************************************************
42 * CODE SECTION
43 ****************************************************************************/
44
45#if defined(__c64__) || defined(__plus4__) || defined(__atari__) || defined(__atarixl__) || defined(__vic20__) || defined(__c128__) || defined(__c64reu__) || defined(__c16__)
46
47void cpu_init( Environment * _environment ) {
48
49 _environment->stackSize = 256;
50
51}
52
53void cpu_nop( Environment * _environment ) {
54
55 outline0("NOP");
56
57}
58void cpu_ztoa( Environment * _environment ) {
59
61
62 inline( cpu_ztoa )
63
64 outline1("BEQ %syes", label );
65 outline0("LDA #0");
66 outline1("JMP %s", label );
67 outhead1("%syes:", label );
68 outline0("LDA #$ff");
69 outhead1("%s:", label );
70
72
73}
74
75void cpu_ctoa( Environment * _environment ) {
76
78
79 inline( cpu_ctoa )
80
81 outline1("BCS %syes", label );
82 outline0("LDA #0");
83 outline1("JMP %s", label );
84 outhead1("%syes:", label );
85 outline0("LDA #$ff");
86 outhead1("%s:", label );
87
89
90}
91
92void cpu_beq( Environment * _environment, char * _label ) {
93
95
96 inline( cpu_beq )
97
98 outline1("BNE %s", label);
99 outline1("JMP %s", _label);
100 outline1("%s:", label);
101
103
104}
105
112void cpu_bneq( Environment * _environment, char * _label ) {
113
115
116 inline( cpu_bneq )
117
118 outline1("BEQ %s", label);
119 outline1("JMP %s", _label);
120 outline1("%s:", label);
121
123
124}
125
126void cpu_bveq( Environment * _environment, char * _value, char * _label ) {
127
128 inline( cpu_bveq )
129
130 outline1("LDA %s", _value);
131 cpu_beq( _environment, _label );
132
134
135}
136
137void cpu_bvneq( Environment * _environment, char * _value, char * _label ) {
138
139 inline( cpu_bvneq )
140
141 outline1("LDA %s", _value);
142 cpu_bneq( _environment, _label );
143
145
146}
147
148void cpu_label( Environment * _environment, char * _label ) {
149
150 inline( cpu_label )
151
152 outhead1("%s:", _label);
153
155
156}
157
158void cpu_peek( Environment * _environment, char * _address, char * _target ) {
159
160 inline( cpu_peek )
161
162 outline1("LDA %s", _address);
163 outline0("STA TMPPTR");
164 outline1("LDA %s", address_displacement(_environment, _address, "1") );
165 outline0("STA TMPPTR+1");
166 outline0("LDY #0");
167 outline0("LDA (TMPPTR),Y");
168 outline1("STA %s", _target);
169
171
172}
173
174void cpu_poke( Environment * _environment, char * _address, char * _source ) {
175
176 inline( cpu_poke )
177
179
180 outline1("LDA %s", _address);
181 outline1("STA %s+1", label);
182 outline1("LDA %s", address_displacement(_environment, _address, "1") );
183 outline1("STA %s+2", label);
184 outline1("LDA %s", _source);
185 outhead1("%s:", label);
186 outline0("STA $FFFF");
187
189
190}
191
192void cpu_poke_const( Environment * _environment, char * _address, int _source ) {
193
194 // inline( cpu_poke )
195
196 outline1("LDA %s", _address);
197 outline0("STA TMPPTR");
198 outline1("LDA %s", address_displacement(_environment, _address, "1") );
199 outline0("STA TMPPTR+1");
200 outline0("LDY #0");
201 outline1("LDA #$%2.2x", (unsigned char)(_source & 0xff));
202 outline0("STA (TMPPTR),Y");
203
204 // no_embedded( cpu_poke );
205
206}
207
208void cpu_peekw( Environment * _environment, char * _address, char * _target ) {
209
210 inline( cpu_peek )
211
212 outline1("LDA %s", _address);
213 outline0("STA TMPPTR");
214 outline1("LDA %s", address_displacement(_environment, _address, "1") );
215 outline0("STA TMPPTR+1");
216 outline0("LDY #0");
217 outline0("LDA (TMPPTR),Y");
218 outline1("STA %s", _target);
219 outline0("INY");
220 outline0("LDA (TMPPTR),Y");
221 outline1("STA %s", address_displacement( _environment, _target, "1" ) );
222
224
225}
226
227void cpu_pokew( Environment * _environment, char * _address, char * _source ) {
228
229 inline( cpu_poke )
230
231 outline1("LDA %s", _address);
232 outline0("STA TMPPTR");
233 outline1("LDA %s", address_displacement(_environment, _address, "1") );
234 outline0("STA TMPPTR+1");
235 outline0("LDY #0");
236 outline1("LDA %s", _source);
237 outline0("STA (TMPPTR),Y");
238 outline0("LDY #1");
239 outline1("LDA %s", address_displacement(_environment, _source, "1"));
240 outline0("STA (TMPPTR),Y");
241
243
244}
245
246void cpu_pokew_const( Environment * _environment, char * _address, int _source ) {
247
248 // inline( cpu_poke )
249
250 outline1("LDA %s", _address);
251 outline0("STA TMPPTR");
252 outline1("LDA %s", address_displacement(_environment, _address, "1") );
253 outline0("STA TMPPTR+1");
254 outline0("LDY #0");
255 outline1("LDA #$%2.2x", (unsigned char)(_source&0xff));
256 outline0("STA (TMPPTR),Y");
257 outline0("LDY #1");
258 outline1("LDA #$%2.2x", (unsigned char)((_source>>8)&0xff));
259 outline0("STA (TMPPTR),Y");
260
261 // no_embedded( cpu_poke );
262
263}
264
265void cpu_peekd( Environment * _environment, char * _address, char * _target ) {
266
267 inline( cpu_peek )
268
269 outline1("LDA %s", _address);
270 outline0("STA TMPPTR");
271 outline1("LDA %s", address_displacement(_environment, _address, "1") );
272 outline0("STA TMPPTR+1");
273 outline0("LDY #0");
274 outline0("LDA (TMPPTR),Y");
275 outline1("STA %s", _target);
276 outline0("INY");
277 outline0("LDA (TMPPTR),Y");
278 outline1("STA %s", address_displacement(_environment, _target, "1") );
279 outline0("INY");
280 outline0("LDA (TMPPTR),Y");
281 outline1("STA %s", address_displacement(_environment, _target, "2") );
282 outline0("INY");
283 outline0("LDA (TMPPTR),Y");
284 outline1("STA %s", address_displacement(_environment, _target, "3") );
285
287
288}
289
290void cpu_poked( Environment * _environment, char * _address, char * _source ) {
291
292 inline( cpu_poke )
293
294 outline1("LDA %s", _address);
295 outline0("STA TMPPTR");
296 outline1("LDA %s", address_displacement(_environment, _address, "1") );
297 outline0("STA TMPPTR+1");
298 outline0("LDY #0");
299 outline1("LDA %s", _source);
300 outline0("STA (TMPPTR),Y");
301 outline0("INY");
302 outline1("LDA %s", address_displacement(_environment, _source, "1") );
303 outline0("STA (TMPPTR),Y");
304 outline0("INY");
305 outline1("LDA %s", address_displacement(_environment, _source, "2") );
306 outline0("STA (TMPPTR),Y");
307 outline0("INY");
308 outline1("LDA %s", address_displacement(_environment, _source, "3") );
309 outline0("STA (TMPPTR),Y");
310
312
313}
314
315void cpu_poked_const( Environment * _environment, char * _address, int _source ) {
316
317 // inline( cpu_poke )
318
319 outline1("LDA %s", _address);
320 outline0("STA TMPPTR");
321 outline1("LDA %s", address_displacement(_environment, _address, "1") );
322 outline0("STA TMPPTR+1");
323 outline0("LDY #0");
324 outline1("LDA #$%2.2x", (unsigned char)(_source&0xff));
325 outline0("STA (TMPPTR),Y");
326 outline0("INY");
327 outline1("LDA #$%2.2x", (unsigned char)((_source>>8)&0xff));
328 outline0("STA (TMPPTR),Y");
329 outline0("INY");
330 outline1("LDA #$%2.2x", (unsigned char)((_source>>16)&0xff));
331 outline0("STA (TMPPTR),Y");
332 outline0("INY");
333 outline1("LDA #$%2.2x", (unsigned char)((_source>>24)&0xff));
334 outline0("STA (TMPPTR),Y");
335
336 // no_embedded( cpu_poke );
337
338}
339
353void cpu_fill_blocks( Environment * _environment, char * _address, char * _blocks, char * _pattern ) {
354
356
357 inline( cpu_fill_blocks )
358
359 // Use the current bitmap address as starting address for filling routine.
360 outline1("LDA %s", _address);
361 outline0("STA TMPPTR");
362 outline1("LDA %s", address_displacement(_environment, _address, "1") );
363 outline0("STA TMPPTR+1");
364
365 // Fill the bitmap with the given pattern.
366 outline1("LDX %s", _blocks );
367 outhead1("%sx:", label);
368 outline0("LDY #0");
369 outline1("LDA %s", _pattern );
370 outhead1("%sy:", label);
371 outline0("STA (TMPPTR),y");
372 outline0("INY");
373 outline1("BNE %sy", label);
374 outline0("INC TMPPTR+1");
375 outline0("DEX");
376 outline1("BNE %sx", label);
377
379
380 outline1("LDA %s", _address);
381 outline0("STA TMPPTR");
382 outline1("LDA %s", address_displacement(_environment, _address, "1"));
383 outline0("STA TMPPTR+1");
384 outline1("LDX %s", _blocks );
385 outline1("LDA %s", _pattern );
386
387 outline0("JSR CPUFILLBLOCKS");
388
389 done()
390
391}
392
406void cpu_fill( Environment * _environment, char * _address, char * _bytes, int _bytes_width, char * _pattern ) {
407
409
411
413
414 outline1("LDA %s", _address);
415 outline0("STA TMPPTR");
416 outline1("LDA %s", address_displacement(_environment, _address, "1"));
417 outline0("STA TMPPTR+1");
418
419 if ( _bytes_width == 8 ) {
420
421 outline1("LDY %s", _bytes);
422 if ( _pattern ) {
423 outline1("LDA %s", _pattern );
424 } else {
425 outline0("LDA #0");
426 }
427 outline0("JSR CPUFILL8");
428
429 } else {
430
431 outline1("LDA %s", _bytes);
432 outline0("STA MATHPTR0");
433 outline1("LDA %s", address_displacement(_environment, _bytes, "1"));
434 outline0("STA MATHPTR0+1");
435
436 if ( _pattern ) {
437 outline1("LDA %s", _pattern );
438 } else {
439 outline0("LDA #0");
440 }
441 outline0("JSR CPUFILL16");
442
443 }
444
445 done()
446
447}
448
462void cpu_fill_size( Environment * _environment, char * _address, int _bytes, char * _pattern ) {
463
465
467
469
470 outline1("LDA %s", _address);
471 outline0("STA TMPPTR");
472 outline1("LDA %s", address_displacement(_environment, _address, "1") );
473 outline0("STA TMPPTR+1");
474 if ( _bytes < 256 ) {
475 outline1("LDX #$%2.2x", (unsigned char)( _bytes & 0xff ) );
476 if ( _pattern ) {
477 outline1("LDA %s", _pattern );
478 } else {
479 outline0("LDA #0");
480 }
481 outline0("JSR CPUFILL8");
482 } else {
483 outline1("LDA #$%2.2x", (unsigned char)( _bytes & 0xff ) );
484 outline0("STA MATHPTR0");
485 outline1("LDA #$%2.2x", ( unsigned char) ( ( _bytes >> 8 ) & 0xff ) );
486 outline0("STA MATHPTR0+1");
487 if ( _pattern ) {
488 outline1("LDA %s", _pattern );
489 } else {
490 outline0("LDA #0");
491 }
492 outline0("JSR CPUFILL16");
493 }
494
495 done()
496
497}
498
512void cpu_fill_size_value( Environment * _environment, char * _address, int _bytes, int _pattern ) {
513
515
517
519
520 outline1("LDA %s", _address);
521 outline0("STA TMPPTR");
522 outline1("LDA %s", address_displacement(_environment, _address, "1") );
523 outline0("STA TMPPTR+1");
524
525 if ( _bytes < 256 ) {
526 outline1("LDX #$%2.2x", (unsigned char)( _bytes & 0xff ) );
527 outline1("LDA #$%2.2x", (unsigned char) (_pattern & 0xff ) );
528 outline0("JSR CPUFILL8");
529 } else {
530 outline1("LDA #$%2.2x", (unsigned char)( _bytes & 0xff ) );
531 outline0("STA MATHPTR0");
532 outline1("LDA #$%2.2x", ( unsigned char) ( ( _bytes >> 8 ) & 0xff ) );
533 outline0("STA MATHPTR0+1");
534 outline1("LDA #$%2.2x", (unsigned char) (_pattern & 0xff ) );
535 outline0("JSR CPUFILL16");
536 }
537
538 done()
539
540}
541
555void cpu_fill_direct( Environment * _environment, char * _address, char * _bytes, char * _pattern ) {
556
558
560
562
563 outline1("LDA #<%s", _address);
564 outline0("STA TMPPTR");
565 outline1("LDA #>%s", _address);
566 outline0("STA TMPPTR+1");
567 outline1("LDA %s", _bytes);
568 outline0("STA MATHPTR0");
569 outline1("LDA %s", address_displacement(_environment, _bytes, "1"));
570 outline0("STA MATHPTR0+1");
571 if ( _pattern ) {
572 outline1("LDA %s", _pattern );
573 } else {
574 outline0("LDA #0");
575 }
576 outline0("JSR CPUFILL16");
577
578 done()
579
580}
581
595void cpu_fill_direct_size( Environment * _environment, char * _address, int _bytes, char * _pattern ) {
596
598
600
602
603 outline1("LDA #<%s", _address);
604 outline0("STA TMPPTR");
605 outline1("LDA #>%s", _address);
606 outline0("STA TMPPTR+1");
607
608 if ( _bytes < 256 ) {
609 outline1("LDX #$%2.2x", (unsigned char)( _bytes & 0xff ) );
610 if ( _pattern ) {
611 outline1("LDA %s", _pattern );
612 } else {
613 outline0("LDA #0");
614 }
615 outline0("JSR CPUFILL8");
616 } else {
617 outline1("LDA #$%2.2x", (unsigned char)( _bytes & 0xff ) );
618 outline0("STA MATHPTR0");
619 outline1("LDA #$%2.2x", ( unsigned char) ( ( _bytes >> 8 ) & 0xff ) );
620 outline0("STA MATHPTR0+1");
621 if ( _pattern ) {
622 outline1("LDA %s", _pattern );
623 } else {
624 outline0("LDA #0");
625 }
626 outline0("JSR CPUFILL16");
627 }
628
629 done()
630
631}
632
646void cpu_fill_direct_size_value( Environment * _environment, char * _address, int _bytes, int _pattern ) {
647
649
651
653
654 outline1("LDA #<%s", _address);
655 outline0("STA TMPPTR");
656 outline1("LDA #>%s", _address);
657 outline0("STA TMPPTR+1");
658
659 if ( _bytes < 256 ) {
660 outline1("LDX #$%2.2x", (unsigned char)( _bytes & 0xff ) );
661 outline1("LDA #$%2.2x", ( _pattern & 0xff ) );
662 outline0("JSR CPUFILL8");
663 } else {
664 outline1("LDA #$%2.2x", (unsigned char)( _bytes & 0xff ) );
665 outline0("STA MATHPTR0");
666 outline1("LDA #$%2.2x", ( unsigned char) ( ( _bytes >> 8 ) & 0xff ) );
667 outline0("STA MATHPTR0+1");
668 outline1("LDA #$%2.2x", (unsigned char) (_pattern & 0xff ) );
669 outline1("LDA #$%2.2x", ( _pattern & 0xff ) );
670 outline0("JSR CPUFILL16");
671 }
672
673 done()
674
675}
676
677/*****************************************************************************
678 * 8 BIT MANIPULATION
679 ****************************************************************************/
680
688void cpu_move_8bit( Environment * _environment, char *_source, char *_destination ) {
689
690 inline( cpu_move_8bit )
691
692 outline1("LDA %s", _source);
693 outline1("STA %s", _destination);
694
696
697}
698
706void cpu_store_8bit( Environment * _environment, char *_destination, int _value ) {
707
708 inline( cpu_store_8bit )
709
710 outline1("LDA #$%2.2x", (_value & 0xff));
711 outline1("STA %s", _destination);
712
714
715}
716
724void cpu_store_char( Environment * _environment, char *_destination, int _value ) {
725
726 inline( cpu_store_char )
727
728 if ( _value >=32 ) {
729 outline1("LDA #'%c'", (_value & 0xff));
730 } else {
731 outline1("LDA #$%2.2x", (_value & 0xff));
732 }
733 outline1("STA %s", _destination);
734
736
737}
738
748void cpu_compare_8bit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive ) {
749
751
752 inline( cpu_compare_8bit )
753
754 outline1("LDA %s", _source);
755 outline1("CMP %s", _destination);
756 outline1("BNE %s", label);
757 outline1("LDA #$%2.2x", 0xff*_positive );
758 if ( _other ) {
759 outline1("STA %s", _other);
760 } else {
761 outline1("STA %s", _destination);
762 }
763 outline1("JMP %s_2", label);
764 outhead1("%s:", label);
765 outline1("LDA #$%2.2x", 0xff*(1-_positive) );
766 if ( _other ) {
767 outline1("STA %s", _other);
768 } else {
769 outline1("STA %s", _destination);
770 }
771 outhead1("%s_2:", label);
772
774
775}
776
786void cpu_compare_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive ) {
787
789
790 inline( cpu_compare_8bit )
791
792 outline1("LDA %s", _source);
793 outline1("CMP #$%2.2x", (unsigned char)( _destination & 0xff ) );
794 outline1("BNE %s", label);
795 outline1("LDA #$%2.2x", (unsigned char)( (0xff*_positive) & 0xff ) );
796 outline1("STA %s", _other);
797 outline1("JMP %s_2", label);
798 outhead1("%s:", label);
799 outline1("LDA #$%2.2x", (unsigned char)( (0xff*(1-_positive)) & 0xff ) );
800 outline1("STA %s", _other);
801 outhead1("%s_2:", label);
802
804
805}
806
807void cpu_prepare_for_compare_and_branch_8bit( Environment * _environment, char *_source ) {
808
810
812
813 outline1("LDA %s", _source);
814
816
817}
818
819void cpu_compare_and_branch_8bit( Environment * _environment, char *_source, char * _destination, char *_label, int _positive ) {
820
822
824
825 outline1("LDA %s", _source);
826 outline1("CMP %s", _destination);
827 if ( _positive ) {
828 outline1("BNE %s", label);
829 } else {
830 outline1("BEQ %s", label);
831 }
832 outline1("JMP %s", _label);
833 outhead1("%s:", label);
834
836
837}
838
848void cpu_compare_and_branch_8bit_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
849
851
853
854 outline1("LDA %s", _source);
855 outline1("CMP #$%2.2x", (unsigned char)(_destination&0xff));
856 if ( _positive ) {
857 outline1("BNE %s", label);
858 } else {
859 outline1("BEQ %s", label);
860 }
861 outline1("JMP %s", _label);
862 outhead1("%s:", label);
863
865
866}
867
877void cpu_execute_compare_and_branch_8bit_const( Environment * _environment, int _destination, char *_label, int _positive ) {
878
880
882
883 outline1("CMP #$%2.2x", (unsigned char)(_destination & 0xff));
884 if ( _positive ) {
885 outline1("BNE %s", label);
886 } else {
887 outline1("BEQ %s", label);
888 }
889 outline1("JMP %s", _label);
890 outhead1("%s:", label);
891
893
894}
895
905void cpu_compare_and_branch_char_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
906
908
910
911 outline1("LDA %s", _source);
912 outline1("CMP #'%c'", (unsigned char)(_destination&0xff));
913 if ( _positive ) {
914 outline1("BNE %s", label);
915 } else {
916 outline1("BEQ %s", label);
917 }
918 outline1("JMP %s", _label);
919 outhead1("%s:", label);
920
922
923}
924
934void cpu_less_than_8bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
935
937
938 inline( cpu_less_than_8bit )
939
940 if ( _signed ) {
941 outline1("LDA %s", _source);
942 outline0("SEC" );
943 outline1("SBC %s", _destination);
944 outline1("BVC %sv0", label );
945 outline0("EOR #$80" );
946 outhead1("%sv0:", label );
947 outline1("BMI %smi", label );
948 if ( _equal ) {
949 outline1("BEQ %smi", label );
950 }
951 outhead1("%spl:", label );
952 outline0("LDA #0" );
953 if ( _other ) {
954 outline1("STA %s", _other);
955 } else {
956 outline1("STA %s", _destination);
957 }
958 outline1("JMP %sen", label );
959 outhead1("%smi:", label );
960 outline0("LDA #$ff" );
961 if ( _other ) {
962 outline1("STA %s", _other);
963 } else {
964 outline1("STA %s", _destination);
965 }
966 outhead1("%sen:", label);
967 } else {
968 outline1("LDA %s", _source);
969 outline1("CMP %s", _destination );
970 outline1("BCC %s", label);
971 if ( _equal ) {
972 outline1("BEQ %s", label);
973 }
974 outline0("LDA #0" );
975 if ( _other ) {
976 outline1("STA %s", _other);
977 } else {
978 outline1("STA %s", _destination);
979 }
980 outline1("JMP %s_2", label);
981 outhead1("%s:", label);
982 outline0("LDA #$FF" );
983 if ( _other ) {
984 outline1("STA %s", _other);
985 } else {
986 outline1("STA %s", _destination);
987 }
988 outhead1("%s_2:", label);
989 }
990
992
993}
994
995void cpu_less_than_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
996
998
1000
1001 if ( _signed ) {
1002 outline1("LDA %s", _source);
1003 outline0("SEC" );
1004 outline1("SBC #$%2.2x", ( _destination & 0xff ) );
1005 outline1("BVC %sv0", label );
1006 outline0("EOR #$80" );
1007 outhead1("%sv0:", label );
1008 outline1("BMI %smi", label );
1009 if ( _equal ) {
1010 outline1("BEQ %smi", label );
1011 }
1012 outhead1("%spl:", label );
1013 outline0("LDA #0" );
1014 outline1("STA %s", _other);
1015 outline1("JMP %sen", label );
1016 outhead1("%smi:", label );
1017 outline0("LDA #$ff" );
1018 outline1("STA %s", _other);
1019 outhead1("%sen:", label);
1020 } else {
1021 outline1("LDA %s", _source);
1022 outline1("CMP #$%2.2x", (unsigned char)( _destination & 0xff ) );
1023 outline1("BCC %s", label);
1024 if ( _equal ) {
1025 outline1("BEQ %s", label);
1026 }
1027 outline0("LDA #0" );
1028 outline1("STA %s", _other);
1029 outline1("JMP %s_2", label);
1030 outhead1("%s:", label);
1031 outline0("LDA #$FF" );
1032 outline1("STA %s", _other);
1033 outhead1("%s_2:", label);
1034 }
1035
1037
1038}
1039
1040void cpu_less_than_and_branch_8bit_const( Environment * _environment, char *_source, int _destination, char *_label, int _equal, int _signed ) {
1041
1043
1044 inline( cpu_less_than_8bit_const )
1045
1046 if ( _signed ) {
1047 outline1("LDA %s", _source);
1048 outline0("SEC" );
1049 outline1("SBC #$%2.2x", ( _destination & 0xff ) );
1050 outline1("BVC %sv0", label );
1051 outline0("EOR #$80" );
1052 outhead1("%sv0:", label );
1053 outline1("BMI %smi", label );
1054 if ( _equal ) {
1055 outline1("BEQ %smi", label );
1056 }
1057 outhead1("%spl:", label );
1058 outline1("JMP %sen", label );
1059 outhead1("%smi:", label );
1060 outline1("JMP %s", _label );
1061 outhead1("%sen:", label);
1062 } else {
1063 outline1("LDA %s", _source);
1064 outline1("CMP #$%2.2x", (unsigned char)( _destination & 0xff ) );
1065 outline1("BCC %s", label);
1066 if ( _equal ) {
1067 outline1("BEQ %s", label);
1068 }
1069 outline1("JMP %s_2", label);
1070 outhead1("%s:", label);
1071 outline1("JMP %s", _label);
1072 outhead1("%s_2:", label);
1073 }
1074
1076
1077}
1078
1088void cpu_greater_than_8bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
1089
1090 inline( cpu_greater_than_8bit )
1091
1092 cpu_less_than_8bit( _environment, _source, _destination, _other, !_equal, _signed );
1093 if ( _other ) {
1094 cpu_not_8bit( _environment, _other, _other );
1095 } else {
1096 cpu_not_8bit( _environment, _destination, _destination );
1097 }
1098
1100
1101}
1102
1103void cpu_greater_than_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
1104
1105 inline( cpu_greater_than_8bit )
1106
1107 cpu_less_than_8bit_const( _environment, _source, _destination, _other, !_equal, _signed );
1108 cpu_not_8bit( _environment, _other, _other );
1109
1111
1112}
1113
1122void cpu_math_add_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
1123
1124 inline( cpu_math_add_8bit )
1125
1126 outline0("CLC");
1127 outline1("LDA %s", _source);
1128 outline1("ADC %s", _destination);
1129 if ( _other ) {
1130 outline1("STA %s", _other);
1131 } else {
1132 outline1("STA %s", _destination);
1133 }
1134
1136
1137}
1138
1147void cpu_math_add_8bit_const( Environment * _environment, char *_source, int _destination, char *_other ) {
1148
1149 inline( cpu_math_add_8bit_const )
1150
1151 outline0("CLC");
1152 outline1("LDA %s", _source);
1153 outline1("ADC #$%2.2x", ( _destination & 0xff ) );
1154 outline1("STA %s", _other);
1155
1157
1158}
1159
1168void cpu_math_sub_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
1169
1170 inline( cpu_math_add_8bit )
1171
1172 outline0("SEC");
1173 outline1("LDA %s", _source);
1174 outline1("SBC %s", _destination);
1175 if ( _other ) {
1176 outline1("STA %s", _other);
1177 } else {
1178 outline1("STA %s", _destination);
1179 }
1180
1182
1183}
1184
1192void cpu_math_double_8bit( Environment * _environment, char *_source, char *_other, int _signed ) {
1193
1194 inline( cpu_math_double_8bit )
1195
1196 if ( _signed ) {
1197 outline1("LDA %s", _source);
1198 outline0("AND #$80");
1199 outline0("TAX");
1200 outline1("LDA %s", _source);
1201 outline0("ASL A");
1202 if ( _other ) {
1203 outline1("STA %s", _other);
1204 outline0("TXA");
1205 outline1("ORA %s", _other);
1206 outline1("STA %s", _other);
1207 } else {
1208 outline1("STA %s", _source);
1209 outline0("TXA");
1210 outline1("ORA %s", _source);
1211 outline1("STA %s", _source);
1212 }
1213 } else {
1214 outline1("LDA %s", _source);
1215 outline0("ASL A");
1216 if ( _other ) {
1217 outline1("STA %s", _other);
1218 } else {
1219 outline1("STA %s", _source);
1220 }
1221 }
1222
1224
1225}
1226
1235void cpu_math_mul_8bit_to_16bit( Environment * _environment, char *_source, char *_destination, char *_other, int _signed ) {
1236
1238
1240
1241 if ( _signed ) {
1242 outline1("LDA %s", _source );
1243 outline1("EOR %s", _destination );
1244 outline0("AND #$80" );
1245 outline0("PHA");
1246 outline1("LDA %s", _source );
1247 outline0("AND #$80" );
1248 outline1("BEQ %ssecond", label );
1249 outline0("CLC" );
1250 outline1("LDA %s", _source );
1251 outline0("EOR #$ff" );
1252 outline0("ADC #1" );
1253 outline0("STA MATHPTR0" );
1254 outhead1("%ssecond:", label );
1255 outline1("LDA %s", _destination );
1256 outline0("AND #$80" );
1257 outline1("BEQ %sthird", label );
1258 outline0("CLC" );
1259 outline1("LDA %s", _destination );
1260 outline0("EOR #$ff" );
1261 outline0("ADC #1" );
1262 outline0("STA MATHPTR1" );
1263 outhead1("%sthird:", label );
1264
1265 outline0("LDA #0");
1266 outline0("LDX #8");
1267 outhead1("%sd1:", label);
1268 outline0("LSR MATHPTR1");
1269 outline1("BCC %s_2", label);
1270 outline0("CLC");
1271 outline0("ADC MATHPTR0");
1272 outline1("%s_2:", label);
1273 outline0("ROR A");
1274 outline1("ROR %s", _other);
1275 outline0("DEX" );
1276 outline1("BNE %sd1", label);
1277 outline1("STA %s", address_displacement(_environment, _other, "1") );
1278
1279 outline0("PLA");
1280 outline0("AND #$80");
1281 outline1("BEQ %sdone", label);
1282 outline1("LDA %s", _other );
1283 outline0("EOR #$ff" );
1284 outline1("STA %s", _other );
1285 outline1("LDA %s", address_displacement(_environment, _other, "1") );
1286 outline0("EOR #$ff" );
1287 outline1("STA %s", address_displacement(_environment, _other, "1") );
1288 outline0("CLC" );
1289 outline1("LDA %s", _other );
1290 outline0("ADC #1" );
1291 outline1("STA %s", _other );
1292 outline1("LDA %s", address_displacement(_environment, _other, "1") );
1293 outline0("ADC #0" );
1294 outline1("STA %s", address_displacement(_environment, _other, "1") );
1295 outhead1("%sdone:", label );
1296
1297 } else {
1298 outline0("LDA #0");
1299 outline0("LDX #8");
1300 outhead1("%sd1:", label);
1301 outline1("LSR %s", _destination);
1302 outline1("BCC %s_2", label);
1303 outline0("CLC");
1304 outline1("ADC %s", _source);
1305 outline1("%s_2:", label);
1306 outline0("ROR A");
1307 outline1("ROR %s", _other);
1308 outline0("DEX" );
1309 outline1("BNE %sd1", label);
1310 outline1("STA %s", address_displacement(_environment, _other, "1") );
1311 }
1312
1314
1315 if ( _signed ) {
1316 outline1("LDA %s", _source);
1317 outline0("STA CPUMATHMUL8BITTO16BIT_SOURCE");
1318 outline1("LDA %s", _destination);
1319 outline0("STA CPUMATHMUL8BITTO16BIT_DESTINATION");
1320 outline0("JSR CPUMATHMUL8BITTO16BIT_SIGNED")
1321 outline0("LDA CPUMATHMUL8BITTO16BIT_OTHER");
1322 outline1("STA %s", _other);
1323 outline0("LDA CPUMATHMUL8BITTO16BIT_OTHER+1");
1324 outline1("STA %s", address_displacement(_environment, _other, "1"));
1325 } else {
1326 outline1("LDA %s", _source);
1327 outline0("STA CPUMATHMUL8BITTO16BIT_SOURCE");
1328 outline1("LDA %s", _destination);
1329 outline0("STA CPUMATHMUL8BITTO16BIT_DESTINATION");
1330 outline0("JSR CPUMATHMUL8BITTO16BIT")
1331 outline0("LDA CPUMATHMUL8BITTO16BIT_OTHER");
1332 outline1("STA %s", _other);
1333 outline0("LDA CPUMATHMUL8BITTO16BIT_OTHER+1");
1334 outline1("STA %s", address_displacement(_environment, _other, "1"));
1335 }
1336
1337 done()
1338
1339}
1340
1341void cpu_math_div_8bit_to_8bit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _signed ) {
1342
1344
1346
1347 if ( _signed ) {
1348 outline1("LDA %s", _source );
1349 outline1("EOR %s", _destination );
1350 outline0("AND #$80" );
1351 outline0("PHA");
1352 outline1("LDA %s", _source );
1353 outline0("AND #$80" );
1354 outline1("BEQ %ssecond", label );
1355 outline0("CLC" );
1356 outline1("LDA %s", _source );
1357 outline0("EOR #$ff" );
1358 outline0("ADC #1" );
1359 outline0("STA MATHPTR0" );
1360 outhead1("%ssecond:", label );
1361 outline1("LDA %s", _destination );
1362 outline0("AND #$80" );
1363 outline1("BEQ %sthird", label );
1364 outline0("CLC" );
1365 outline1("LDA %s", _destination );
1366 outline0("EOR #$ff" );
1367 outline0("ADC #1" );
1368 outline0("STA MATHPTR1" );
1369 outhead1("%sthird:", label );
1370
1371 outline0("LDA MATHPTR0" );
1372 outline1("STA %s", _other );
1373 outline0("LDA #0" );
1374 outline1("STA %s", _other_remainder );
1375 outline0("LDX #8");
1376 outhead1("%sL1:", label );
1377 outline1("ASL %s", _other );
1378 outline1("ROL %s", _other_remainder );
1379 outline1("LDA %s", _other_remainder );
1380 outline0("SEC" );
1381 outline0("SBC MATHPTR1" );
1382 outline0("TAY" );
1383 outline1("BCC %sL2", label );
1384 outline1("STY %s", _other_remainder );
1385 outline1("INC %s", _other );
1386 outhead1("%sL2:", label );
1387 outline0("DEX" );
1388 outhead1("BNE %sL1", label );
1389
1390 outline0("PLA");
1391 outline0("AND #$80");
1392 outline1("BEQ %sdone", label);
1393 outline1("LDA %s", _other );
1394 outline0("EOR #$ff" );
1395 outline1("STA %s", _other );
1396 outline0("CLC" );
1397 outline1("LDA %s", _other );
1398 outline0("ADC #1" );
1399 outline1("STA %s", _other );
1400 outhead1("%sdone:", label );
1401
1402 } else {
1403 outline1("LDA %s", _source );
1404 outline1("STA %s", _other );
1405 outline0("LDA #0" );
1406 outline1("STA %s", _other_remainder );
1407 outline0("LDX #8");
1408 outhead1("%sL1:", label );
1409 outline1("ASL %s", _other );
1410 outline1("ROL %s", _other_remainder );
1411 outline1("LDA %s", _other_remainder );
1412 outline0("SEC" );
1413 outline1("SBC %s", _destination );
1414 outline0("TAY" );
1415 outline1("BCC %sL2", label );
1416 outline1("STY %s", _other_remainder );
1417 outline1("INC %s", _other );
1418 outhead1("%sL2:", label );
1419 outline0("DEX" );
1420 outhead1("BNE %sL1", label );
1421 }
1422
1424
1425 if ( _signed ) {
1426 outline1("LDA %s", _source);
1427 outline0("STA CPUMATHDIV8BITTO8BIT_SOURCE");
1428 outline1("LDA %s", _destination);
1429 outline0("STA CPUMATHDIV8BITTO8BIT_DESTINATION");
1430 outline0("JSR CPUMATHDIV8BITTO8BIT_SIGNED")
1431 outline0("LDA CPUMATHDIV8BITTO8BIT_OTHER");
1432 outline1("STA %s", _other);
1433 outline0("LDA CPUMATHDIV8BITTO8BIT_OTHER_REMAINDER");
1434 outline1("STA %s", _other_remainder);
1435 } else {
1436 outline1("LDA %s", _source);
1437 outline0("STA CPUMATHDIV8BITTO8BIT_SOURCE");
1438 outline1("LDA %s", _destination);
1439 outline0("STA CPUMATHDIV8BITTO8BIT_DESTINATION");
1440 outline0("JSR CPUMATHDIV8BITTO8BIT")
1441 outline0("LDA CPUMATHDIV8BITTO8BIT_OTHER");
1442 outline1("STA %s", _other);
1443 outline0("LDA CPUMATHDIV8BITTO8BIT_OTHER_REMAINDER");
1444 outline1("STA %s", _other_remainder);
1445 }
1446
1447 done()
1448
1449}
1450
1451void cpu_math_div_8bit_to_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _signed ) {
1452
1454
1456
1457 if ( _signed ) {
1458 outline1("LDA %s", _source );
1459 outline1("EOR #$%2.2x", _destination );
1460 outline0("AND #$80" );
1461 outline0("PHA");
1462 outline1("LDA %s", _source );
1463 outline0("AND #$80" );
1464 outline1("BEQ %ssecond", label );
1465 outline0("CLC" );
1466 outline1("LDA %s", _source );
1467 outline0("EOR #$ff" );
1468 outline0("ADC #1" );
1469 outline0("STA MATHPTR0" );
1470 outhead1("%ssecond:", label );
1471 outline1("LDA #$%2.2x", _destination );
1472 outline0("AND #$80" );
1473 outline1("BEQ %sthird", label );
1474 outline0("CLC" );
1475 outline1("LDA #$%2.2x", _destination );
1476 outline0("EOR #$ff" );
1477 outline0("ADC #1" );
1478 outline0("STA MATHPTR1" );
1479 outhead1("%sthird:", label );
1480
1481 outline0("LDA MATHPTR0" );
1482 outline1("STA %s", _other );
1483 outline0("LDA #0" );
1484 outline1("STA %s", _other_remainder );
1485 outline0("LDX #8");
1486 outhead1("%sL1:", label );
1487 outline1("ASL %s", _other );
1488 outline1("ROL %s", _other_remainder );
1489 outline1("LDA %s", _other_remainder );
1490 outline0("SEC" );
1491 outline0("SBC MATHPTR1" );
1492 outline0("TAY" );
1493 outline1("BCC %sL2", label );
1494 outline1("STY %s", _other_remainder );
1495 outline1("INC %s", _other );
1496 outhead1("%sL2:", label );
1497 outline0("DEX" );
1498 outhead1("BNE %sL1", label );
1499
1500 outline0("PLA");
1501 outline0("AND #$80");
1502 outline1("BEQ %sdone", label);
1503 outline1("LDA %s", _other );
1504 outline0("EOR #$ff" );
1505 outline1("STA %s", _other );
1506 outline0("CLC" );
1507 outline1("LDA %s", _other );
1508 outline0("ADC #1" );
1509 outline1("STA %s", _other );
1510 outhead1("%sdone:", label );
1511
1512 } else {
1513 outline1("LDA %s", _source );
1514 outline1("STA %s", _other );
1515 outline0("LDA #0" );
1516 outline1("STA %s", _other_remainder );
1517 outline0("LDX #8");
1518 outhead1("%sL1:", label );
1519 outline1("ASL %s", _other );
1520 outline1("ROL %s", _other_remainder );
1521 outline1("LDA %s", _other_remainder );
1522 outline0("SEC" );
1523 outline1("SBC #$%2.2x", _destination );
1524 outline0("TAY" );
1525 outline1("BCC %sL2", label );
1526 outline1("STY %s", _other_remainder );
1527 outline1("INC %s", _other );
1528 outhead1("%sL2:", label );
1529 outline0("DEX" );
1530 outhead1("BNE %sL1", label );
1531 }
1532
1534
1535 if ( _signed ) {
1536 outline1("LDA %s", _source);
1537 outline0("STA CPUMATHDIV8BITTO8BIT_SOURCE");
1538 outline1("LDA #$%2.2x", _destination);
1539 outline0("STA CPUMATHDIV8BITTO8BIT_DESTINATION");
1540 outline0("JSR CPUMATHDIV8BITTO8BIT_SIGNED")
1541 outline0("LDA CPUMATHDIV8BITTO8BIT_OTHER");
1542 outline1("STA %s", _other);
1543 outline0("LDA CPUMATHDIV8BITTO8BIT_OTHER_REMAINDER");
1544 outline1("STA %s", _other_remainder);
1545 } else {
1546 outline1("LDA %s", _source);
1547 outline0("STA CPUMATHDIV8BITTO8BIT_SOURCE");
1548 outline1("LDA #$%2.2x", _destination);
1549 outline0("STA CPUMATHDIV8BITTO8BIT_DESTINATION");
1550 outline0("JSR CPUMATHDIV8BITTO8BIT")
1551 outline0("LDA CPUMATHDIV8BITTO8BIT_OTHER");
1552 outline1("STA %s", _other);
1553 outline0("LDA CPUMATHDIV8BITTO8BIT_OTHER_REMAINDER");
1554 outline1("STA %s", _other_remainder);
1555 }
1556
1557 done()
1558
1559}
1560
1568void cpu_math_div2_const_8bit( Environment * _environment, char *_source, int _steps, int _signed, char *_remainder ) {
1569
1570 inline( cpu_math_div2_const_8bit )
1571
1573
1574 if ( _signed ) {
1575 if ( _remainder ) {
1576 outline1("LDA %s", _source);
1577 outline0("AND #$01" );
1578 outline1("STA %s", _remainder);
1579 }
1580 outline1("LDA %s", _source);
1581 outline0("AND #$80" );
1582 outline0("TAX");
1583 outline1("BEQ %snocomplement", label );
1584 cpu_complement2_8bit( _environment, _source, _source );
1585 outhead1("%snocomplement:", label );
1586 while( _steps ) {
1587 outline0("CLC");
1588 outline1("ROR %s", _source);
1589 --_steps;
1590 }
1591 outline0("TXA");
1592 outline1("BEQ %snocomplement", label );
1593 cpu_complement2_8bit( _environment, _source, _source );
1594 outhead1("%snocomplement:", label );
1595 } else {
1596 if ( _remainder ) {
1597 outline1("LDA %s", _source);
1598 outline0("AND #$01" );
1599 outline1("STA %s", _remainder);
1600 }
1601 while( _steps ) {
1602 outline0("CLC");
1603 outline1("ROR %s", _source);
1604 --_steps;
1605 }
1606 }
1607
1609
1610 if ( _remainder ) {
1611 outline1("LDA %s", _source);
1612 outline0("AND #$01" );
1613 outline1("STA %s", _remainder);
1614 }
1615 if ( _signed ) {
1616 outline1("LDA %s", _source);
1617 outline1("LDX #$%2.2x", _steps );
1618 outline0("JSR CPUMATHDIV2CONST8BIT_SIGNED")
1619 outline1("STA %s", _source);
1620 } else {
1621 outline1("LDA %s", _source);
1622 outline1("LDX #$%2.2x", _steps );
1623 outline0("JSR CPUMATHDIV2CONST8BIT")
1624 outline1("STA %s", _source);
1625 }
1626
1627 done()
1628
1629}
1630
1638void cpu_math_mul2_const_8bit( Environment * _environment, char *_source, int _steps, int _signed ) {
1639
1640 inline( cpu_math_mul2_const_8bit )
1641
1642 if ( _signed ) {
1643 outline1("LDA %s", _source);
1644 outline0("AND #$80" );
1645 outline0("TAX");
1646 while( _steps ) {
1647 outline0("CLC");
1648 outline1("ASL %s", _source);
1649 --_steps;
1650 }
1651 outline0("TXA");
1652 outline1("ORA %s", _source);
1653 outline1("STA %s", _source);
1654 } else {
1655 while( _steps ) {
1656 outline0("CLC");
1657 outline1("ASL %s", _source);
1658 --_steps;
1659 }
1660 }
1661
1663
1664 if ( _signed ) {
1665 outline1("LDA %s", _source);
1666 outline1("LDX #$%2.2x", _steps );
1667 outline0("JSR CPUMATHMUL2CONST8BIT_SIGNED")
1668 outline1("STA %s", _source);
1669 } else {
1670 outline1("LDA %s", _source);
1671 outline1("LDX #$%2.2x", _steps );
1672 outline0("JSR CPUMATHMUL2CONST8BIT")
1673 outline1("STA %s", _source);
1674 }
1675
1676 done()
1677
1678}
1679
1687void cpu_math_complement_const_8bit( Environment * _environment, char *_source, int _value ) {
1688
1690
1691 outline0("SEC");
1692 outline1("LDA #$%2.2x", ( _value & 0xff ) );
1693 outline1("SBC %s", _source);
1694 outline1("STA %s", _source );
1695
1697
1698}
1699
1707void cpu_math_and_const_8bit( Environment * _environment, char *_source, int _mask ) {
1708
1709 inline( cpu_math_and_const_8bit )
1710
1711 outline1("LDA %s", _source);
1712 outline1("AND #$%2.2x", (_mask & 0xff));
1713 outline1("STA %s", _source);
1714
1716
1717}
1718
1719/*****************************************************************************
1720 * 16 BIT MANIPULATION
1721 ****************************************************************************/
1722
1730void cpu_move_16bit( Environment * _environment, char *_source, char *_destination ) {
1731
1732 inline( cpu_move_16bit )
1733
1734 outline1("LDA %s", _source);
1735 outline1("STA %s", _destination);
1736 outline1("LDA %s", address_displacement(_environment, _source, "1"));
1737 outline1("STA %s", address_displacement(_environment, _destination, "1"));
1738
1740
1741}
1742
1743void cpu_addressof_16bit( Environment * _environment, char *_source, char *_destination ) {
1744
1745 inline( cpu_move_16bit )
1746
1747 outline1("LDA #<%s", _source);
1748 outline1("STA %s", _destination);
1749 outline1("LDA #>%s", _source);
1750 outline1("STA %s", address_displacement(_environment, _destination, "1"));
1751
1753
1754}
1755
1763void cpu_store_16bit( Environment * _environment, char *_destination, int _value ) {
1764
1765 inline( cpu_store_16bit )
1766
1767 outline1("LDA #$%2.2x", ( _value & 0xff ) );
1768 outline1("STA %s", _destination);
1769 outline1("LDA #$%2.2x", ( ( _value >> 8 ) & 0xff ) );
1770 outline1("STA %s", address_displacement(_environment, _destination, "1"));
1771
1773
1774}
1775
1785void cpu_compare_16bit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive ) {
1786
1788
1789 inline( cpu_compare_16bit )
1790
1791 outline1("LDA %s", _source);
1792 outline1("CMP %s", _destination);
1793 outline1("BNE %s", label);
1794 outline1("LDA %s", address_displacement(_environment, _source, "1"));
1795 outline1("CMP %s", address_displacement(_environment, _destination, "1"));
1796 outline1("BNE %s", label);
1797 outline1("LDA #$%2.2x", ( _positive ) ? 0xff : 0x00 );
1798 if ( _other ) {
1799 outline1("STA %s", _other);
1800 } else {
1801 outline1("STA %s", _destination);
1802 }
1803 outline1("JMP %s_2", label);
1804 outhead1("%s:", label);
1805 outline1("LDA #$%2.2x", ( _positive ) ? 0x00 : 0xff );
1806 if ( _other ) {
1807 outline1("STA %s", _other);
1808 } else {
1809 outline1("STA %s", _destination);
1810 }
1811 outhead1("%s_2:", label);
1812
1814
1815}
1816
1826void cpu_compare_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive ) {
1827
1829
1830 inline( cpu_compare_16bit )
1831
1832 outline1("LDA %s", _source);
1833 outline1("CMP #$%2.2x", (unsigned char)( _destination & 0xff ) );
1834 outline1("BNE %s", label);
1835 outline1("LDA %s", address_displacement(_environment, _source, "1"));
1836 outline1("CMP #$%2.2x", (unsigned char)( ( _destination >> 8 ) & 0xff ) );
1837 outline1("BNE %s", label);
1838 outline1("LDA #$%2.2x", ( _positive ) ? 0xff : 0x00 );
1839 outline1("STA %s", _other);
1840 outline1("JMP %s_2", label);
1841 outhead1("%s:", label);
1842 outline1("LDA #$%2.2x", ( _positive ) ? 0x00 : 0xff );
1843 outline1("STA %s", _other);
1844 outhead1("%s_2:", label);
1845
1847
1848}
1849
1850void cpu_compare_and_branch_16bit( Environment * _environment, char *_source, char * _destination, char *_label, int _positive ) {
1851
1853
1855
1856 outline1("LDA %s", address_displacement(_environment, _source, "1"));
1857 outline1("CMP %s", address_displacement(_environment, _destination, "1"));
1858 outline1("BNE %s", label);
1859 outline1("LDA %s", _source);
1860 outline1("CMP %s", _destination);
1861 outline1("BNE %s", label);
1862 if ( _positive ) {
1863 outline1("JMP %s", _label);
1864 outhead1("%s:", label);
1865 } else {
1866 outline1("JMP %snot", label);
1867 outhead1("%s:", label);
1868 outline1("JMP %s", _label);
1869 outhead1("%snot:", label);
1870 }
1871
1873
1874}
1875
1885void cpu_compare_and_branch_16bit_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
1886
1888
1890
1891 outline1("LDA %s", address_displacement(_environment, _source, "1"));
1892 outline1("CMP #$%2.2x", (unsigned char)(( _destination >> 8 ) & 0xff ));
1893 outline1("BNE %s", label);
1894 outline1("LDA %s", _source);
1895 outline1("CMP #$%2.2x", (unsigned char)( _destination & 0xff ) );
1896 outline1("BNE %s", label);
1897 if ( _positive ) {
1898 outline1("JMP %s", _label);
1899 outhead1("%s:", label);
1900 } else {
1901 outline1("JMP %snot", label);
1902 outhead1("%s:", label);
1903 outline1("JMP %s", _label);
1904 outhead1("%snot:", label);
1905 }
1906
1908
1909}
1910
1920void cpu_less_than_16bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
1921
1923
1924 inline( cpu_less_than_16bit )
1925
1926 if ( _signed ) {
1927
1928 outline0("SEC");
1929 outline1("LDA %s", address_displacement(_environment, _source, "1") );
1930 outline1("SBC %s", address_displacement(_environment, _destination, "1") );
1931 outline1("BVC %sLABEL1", label);
1932 outline0("EOR #$80" );
1933 outhead1("%sLABEL1:", label );
1934 outline1("BMI %sLABEL4", label );
1935 outline1("BVC %sLABEL2", label );
1936 outline0("EOR #$80" );
1937 outhead1("%sLABEL2:", label );
1938 outline1("BNE %sLABEL3", label );
1939 outline1("LDA %s", _source );
1940 outline1("SBC %s", _destination );
1941 if ( _equal ) {
1942 outline1("BEQ %sLABEL4", label );
1943 }
1944 outline1("BCC %sLABEL4", label );
1945 outhead1("%sLABEL3:", label );
1946 outline0("LDA #0" );
1947 if ( _other ) {
1948 outline1("STA %s", _other);
1949 } else {
1950 outline1("STA %s", _destination);
1951 }
1952 outline1("JMP %sen", label );
1953 outhead1("%sLABEL4:", label );
1954 outline0("LDA #$ff" );
1955 if ( _other ) {
1956 outline1("STA %s", _other);
1957 } else {
1958 outline1("STA %s", _destination);
1959 }
1960 outhead1("%sen:", label);
1961 } else {
1962 outline1("LDA %s", address_displacement(_environment, _source, "1"));
1963 outline1("CMP %s", address_displacement(_environment, _destination, "1") );
1964 outline1("BEQ %s_1", label);
1965 outline1("BCC %s", label);
1966 outline1("BCS %s_0", label);
1967 outhead1("%s_1:", label);
1968 outline1("LDA %s", _source);
1969 outline1("CMP %s", _destination );
1970 if ( _equal ) {
1971 outline1("BEQ %s", label);
1972 }
1973 outline1("BCC %s", label);
1974 outhead1("%s_0:", label);
1975 outline0("LDA #0" );
1976 if ( _other ) {
1977 outline1("STA %s", _other);
1978 } else {
1979 outline1("STA %s", _destination);
1980 }
1981 outline1("JMP %s_2", label);
1982 outhead1("%s:", label);
1983 outline0("LDA #$FF" );
1984 if ( _other ) {
1985 outline1("STA %s", _other);
1986 } else {
1987 outline1("STA %s", _destination);
1988 }
1989 outhead1("%s_2:", label);
1990 }
1991
1993
1994}
1995
1996void cpu_less_than_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
1997
1999
2001
2002 if ( _signed ) {
2003
2004 outline0("SEC");
2005 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2006 outline1("SBC #$%2.2x", ( ( _destination >> 8 ) & 0xff ) );
2007 outline1("BVC %sLABEL1", label);
2008 outline0("EOR #$80" );
2009 outhead1("%sLABEL1:", label );
2010 outline1("BMI %sLABEL4", label );
2011 outline1("BVC %sLABEL2", label );
2012 outline0("EOR #$80" );
2013 outhead1("%sLABEL2:", label );
2014 outline1("BNE %sLABEL3", label );
2015 outline1("LDA %s", _source );
2016 outline1("SBC #$%2.2x", ( _destination & 0xff ) );
2017 if ( _equal ) {
2018 outline1("BEQ %sLABEL4", label );
2019 }
2020 outline1("BCC %sLABEL4", label );
2021 outhead1("%sLABEL3:", label );
2022 outline0("LDA #0" );
2023 outline1("STA %s", _other);
2024 outline1("JMP %sen", label );
2025 outhead1("%sLABEL4:", label );
2026 outline0("LDA #$ff" );
2027 outline1("STA %s", _other);
2028 outhead1("%sen:", label);
2029 } else {
2030 outline1("LDA %s", address_displacement(_environment, _source, "1"));
2031 outline1("CMP #$%2.2x", (unsigned char)( ( _destination >> 8 ) & 0xff ) );
2032 outline1("BEQ %s_1", label);
2033 outline1("BCC %s", label);
2034 outline1("BCS %s_0", label);
2035 outhead1("%s_1:", label);
2036 outline1("LDA %s", _source);
2037 outline1("CMP #$%2.2x", (unsigned char)( _destination & 0xff ) );
2038 if ( _equal ) {
2039 outline1("BEQ %s", label);
2040 }
2041 outline1("BCC %s", label);
2042 outhead1("%s_0:", label);
2043 outline0("LDA #0" );
2044 outline1("STA %s", _other);
2045 outline1("JMP %s_2", label);
2046 outhead1("%s:", label);
2047 outline0("LDA #$FF" );
2048 outline1("STA %s", _other);
2049 outhead1("%s_2:", label);
2050 }
2051
2053
2054}
2055
2065void cpu_greater_than_16bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
2066
2067 inline( cpu_greater_than_16bit )
2068
2069 cpu_less_than_16bit( _environment, _source, _destination, _other, !_equal, _signed );
2070 if ( _other ) {
2071 cpu_not_8bit( _environment, _other, _other );
2072 } else {
2073 cpu_not_8bit( _environment, _destination, _destination );
2074 }
2075
2077
2078}
2079
2080void cpu_greater_than_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
2081
2082 inline( cpu_greater_than_16bit )
2083
2084 cpu_less_than_16bit_const( _environment, _source, _destination, _other, !_equal, _signed );
2085 cpu_not_8bit( _environment, _other, _other );
2086
2088
2089}
2090
2099void cpu_math_add_16bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
2100
2101 inline( cpu_math_add_16bit )
2102
2103 outline0("CLC");
2104 outline1("LDA %s", _source);
2105 outline1("ADC %s", _destination);
2106 if ( _other ) {
2107 outline1("STA %s", _other);
2108 } else {
2109 outline1("STA %s", _destination);
2110 }
2111 outline1("LDA %s", address_displacement(_environment, _source, "1"));
2112 outline1("ADC %s", address_displacement(_environment, _destination, "1"));
2113 if ( _other ) {
2114 outline1("STA %s", address_displacement(_environment, _other, "1"));
2115 } else {
2116 outline1("STA %s", address_displacement(_environment, _destination, "1"));
2117 }
2118
2120
2121}
2122
2131void cpu_math_add_16bit_const( Environment * _environment, char *_source, int _destination, char *_other ) {
2132
2133 inline( cpu_math_add_16bit_const )
2134
2135 outline0("CLC");
2136 outline1("LDA %s", _source);
2137 outline1("ADC #$%2.2x", ( _destination & 0xff ) );
2138 outline1("STA %s", _other);
2139 outline1("LDA %s", address_displacement(_environment, _source, "1"));
2140 outline1("ADC #$%2.2x", ( ( _destination >> 8 ) & 0xff ) );
2141 outline1("STA %s", address_displacement(_environment, _other, "1"));
2142
2144
2145}
2146
2155void cpu_math_add_16bit_with_16bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
2156
2158
2159 outline0("CLC");
2160 outline1("LDA %s", _source);
2161 outline1("ADC #<%s", _destination);
2162 outline1("STA %s", _other);
2163 outline1("LDA %s", address_displacement(_environment, _source, "1"));
2164 outline1("ADC #>%s", _destination);
2165 outline1("STA %s", address_displacement(_environment, _other, "1"));
2166
2168
2169}
2170
2171void cpu_math_add_16bit_with_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
2172
2174
2175 outline0("CLC");
2176 outline1("LDA %s", _source);
2177 outline1("ADC %s", _destination);
2178 if ( _other ) {
2179 outline1("STA %s", _other);
2180 } else {
2181 outline1("STA %s", _destination);
2182 }
2183 outline1("LDA %s", address_displacement(_environment, _source, "1"));
2184 outline0("ADC #$0");
2185 if ( _other ) {
2186 outline1("STA %s", address_displacement(_environment, _other, "1"));
2187 } else {
2188 outline1("STA %s", address_displacement(_environment, _destination, "1"));
2189 }
2190
2192
2193}
2194
2202void cpu_math_double_16bit( Environment * _environment, char *_source, char *_other, int _signed ) {
2203
2204 inline( cpu_math_double_16bit )
2205
2206 outline1("LDA %s", _source);
2207 outline0("ASL A");
2208 if ( _other ) {
2209 outline1("STA %s", _other);
2210 } else {
2211 outline1("STA %s", _source);
2212 }
2213 outline1("LDA %s", address_displacement(_environment, _source, "1"));
2214 outline0("ROL A");
2215 if ( _other ) {
2216 outline1("STA %s", address_displacement(_environment, _other, "1"));
2217 } else {
2218 outline1("STA %s", address_displacement(_environment, _source, "1"));
2219 }
2220
2222
2223
2224}
2225
2234void cpu_math_mul_16bit_to_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _signed ) {
2235
2237
2239
2240 if ( _signed ) {
2241
2242 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2243 outline1("EOR %s", address_displacement(_environment, _destination, "1") );
2244 outline0("AND #$80" );
2245 outline0("PHA");
2246
2247 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2248 outline0("AND #$80" );
2249 outline1("BEQ %ssecond", label );
2250 outline0("CLC" );
2251 outline1("LDA %s", _source );
2252 outline0("EOR #$ff" );
2253 outline0("STA MATHPTR0" );
2254 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2255 outline0("EOR #$ff" );
2256 outline0("STA MATHPTR1" );
2257 outline0("CLC" );
2258 outline0("LDA MATHPTR0" );
2259 outline0("ADC #1" );
2260 outline0("STA MATHPTR0" );
2261 outline0("LDA MATHPTR1" );
2262 outline0("ADC #0" );
2263 outline0("STA MATHPTR1" );
2264 outline1("JMP %ssecond2", label );
2265 outhead1("%ssecond:", label );
2266 outline1("LDA %s", _source );
2267 outline0("STA MATHPTR0");
2268 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2269 outline0("STA MATHPTR1");
2270 outline1("JMP %ssecond2", label );
2271
2272 outhead1("%ssecond2:", label );
2273 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2274 outline0("AND #$80" );
2275 outline1("BEQ %sthird", label );
2276 outline0("CLC" );
2277 outline1("LDA %s", _destination );
2278 outline0("EOR #$ff" );
2279 outline0("STA MATHPTR2" );
2280 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2281 outline0("EOR #$ff" );
2282 outline0("STA MATHPTR3" );
2283 outline0("CLC" );
2284 outline0("LDA MATHPTR2" );
2285 outline0("ADC #1" );
2286 outline0("STA MATHPTR2" );
2287 outline0("LDA MATHPTR3" );
2288 outline0("ADC #0" );
2289 outline0("STA MATHPTR3" );
2290 outline1("JMP %sthird2", label );
2291 outhead1("%sthird:", label );
2292 outline1("LDA %s", _destination );
2293 outline0("STA MATHPTR2");
2294 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2295 outline0("STA MATHPTR3");
2296 outline1("JMP %sthird2", label );
2297
2298 outhead1("%sthird2:", label );
2299 outline0("LDA #$00");
2300 outline0("STA MATHPTR4");
2301 outline0("STA MATHPTR5");
2302 outline0("STA MATHPTR6");
2303 outline0("STA MATHPTR7");
2304 outline0("LDX #$10");
2305
2306 outhead1("%s:", label);
2307 outline0("LSR MATHPTR1");
2308 outline0("ROR MATHPTR0");
2309 outline1("BCC %s_2", label);
2310 outline0("LDA MATHPTR6");
2311 outline0("CLC");
2312 outline0("ADC MATHPTR2");
2313 outline0("STA MATHPTR6");
2314 outline0("LDA MATHPTR7");
2315 outline0("ADC MATHPTR3");
2316
2317 outhead1("%s_2:", label);
2318 outline0("ROR");
2319 outline0("STA MATHPTR7");
2320 outline0("ROR MATHPTR6");
2321 outline0("ROR MATHPTR5");
2322 outline0("ROR MATHPTR4");
2323 outline0("DEX");
2324 outline1("BNE %s", label);
2325
2326 outline0("LDA MATHPTR4");
2327 outline1("STA %s", _other );
2328 outline0("LDA MATHPTR5");
2329 outline1("STA %s", address_displacement(_environment, _other, "1") );
2330 outline0("LDA MATHPTR6");
2331 outline1("STA %s", address_displacement(_environment, _other, "2") );
2332 outline0("LDA MATHPTR7");
2333 outline1("STA %s", address_displacement(_environment, _other, "3") );
2334
2335 outline0("PLA");
2336 outline0("AND #$80");
2337 outline1("BEQ %sdone", label);
2338 outline1("LDA %s", _other );
2339 outline0("EOR #$ff" );
2340 outline1("STA %s", _other );
2341 outline1("LDA %s", address_displacement(_environment, _other, "1") );
2342 outline0("EOR #$ff" );
2343 outline1("STA %s", address_displacement(_environment, _other, "1") );
2344 outline1("LDA %s", address_displacement(_environment, _other, "2") );
2345 outline0("EOR #$ff" );
2346 outline1("STA %s", address_displacement(_environment, _other, "2") );
2347 outline1("LDA %s", address_displacement(_environment, _other, "3") );
2348 outline0("EOR #$ff" );
2349 outline1("STA %s", address_displacement(_environment, _other, "3") );
2350 outline0("CLC" );
2351 outline1("LDA %s", _other );
2352 outline0("ADC #1" );
2353 outline1("STA %s", _other );
2354 outline1("LDA %s", address_displacement(_environment, _other, "1") );
2355 outline0("ADC #0" );
2356 outline1("STA %s", address_displacement(_environment, _other, "1") );
2357 outline1("LDA %s", address_displacement(_environment, _other, "2") );
2358 outline0("ADC #0" );
2359 outline1("STA %s", address_displacement(_environment, _other, "2") );
2360 outline1("LDA %s", address_displacement(_environment, _other, "3") );
2361 outline0("ADC #0" );
2362 outline1("STA %s", address_displacement(_environment, _other, "3") );
2363 outhead1("%sdone:", label );
2364
2365
2366 } else {
2367
2368 outline1("LDA %s", _source );
2369 outline0("STA MATHPTR0");
2370 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2371 outline0("STA MATHPTR1");
2372 outline1("LDA %s", _destination );
2373 outline0("STA MATHPTR2");
2374 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2375 outline0("STA MATHPTR3");
2376
2377 outline0("LDA #$00");
2378 outline0("STA MATHPTR4");
2379 outline0("STA MATHPTR5");
2380 outline0("STA MATHPTR6");
2381 outline0("STA MATHPTR7");
2382 outline0("LDX #$10");
2383
2384 outhead1("%s:", label);
2385 outline0("LSR MATHPTR1");
2386 outline0("ROR MATHPTR0");
2387 outline1("BCC %s_2", label);
2388 outline0("LDA MATHPTR6");
2389 outline0("CLC");
2390 outline0("ADC MATHPTR2");
2391 outline0("STA MATHPTR6");
2392 outline0("LDA MATHPTR7");
2393 outline0("ADC MATHPTR3");
2394
2395 outhead1("%s_2:", label);
2396 outline0("ROR");
2397 outline0("STA MATHPTR7");
2398 outline0("ROR MATHPTR6");
2399 outline0("ROR MATHPTR5");
2400 outline0("ROR MATHPTR4");
2401 outline0("DEX");
2402 outline1("BNE %s", label);
2403
2404 outline0("LDA MATHPTR4");
2405 outline1("STA %s", _other );
2406 outline0("LDA MATHPTR5");
2407 outline1("STA %s", address_displacement(_environment, _other, "1") );
2408 outline0("LDA MATHPTR6");
2409 outline1("STA %s", address_displacement(_environment, _other, "2") );
2410 outline0("LDA MATHPTR7");
2411 outline1("STA %s", address_displacement(_environment, _other, "3") );
2412
2413 }
2414
2416
2417 if ( _signed ) {
2418 outline1("LDA %s", _source );
2419 outline0("STA CPUMATHMUL16BITTO32BIT_SOURCE");
2420 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2421 outline0("STA CPUMATHMUL16BITTO32BIT_SOURCE+1");
2422 outline1("LDA %s", _destination );
2423 outline0("STA CPUMATHMUL16BITTO32BIT_DESTINATION");
2424 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2425 outline0("STA CPUMATHMUL16BITTO32BIT_DESTINATION+1");
2426 outline0("JSR CPUMATHMUL16BITTO32BIT_SIGNED");
2427 outline0("LDA CPUMATHMUL16BITTO32BIT_OTHER");
2428 outline1("STA %s", _other );
2429 outline0("LDA CPUMATHMUL16BITTO32BIT_OTHER+1");
2430 outline1("STA %s", address_displacement(_environment, _other, "1") );
2431 outline0("LDA CPUMATHMUL16BITTO32BIT_OTHER+2");
2432 outline1("STA %s", address_displacement(_environment, _other, "2") );
2433 outline0("LDA CPUMATHMUL16BITTO32BIT_OTHER+3");
2434 outline1("STA %s", address_displacement(_environment, _other, "3") );
2435 } else {
2436 outline1("LDA %s", _source );
2437 outline0("STA CPUMATHMUL16BITTO32BIT_SOURCE");
2438 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2439 outline0("STA CPUMATHMUL16BITTO32BIT_SOURCE+1");
2440 outline1("LDA %s", _destination );
2441 outline0("STA CPUMATHMUL16BITTO32BIT_DESTINATION");
2442 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2443 outline0("STA CPUMATHMUL16BITTO32BIT_DESTINATION+1");
2444 outline0("JSR CPUMATHMUL16BITTO32BIT");
2445 outline0("LDA CPUMATHMUL16BITTO32BIT_OTHER");
2446 outline1("STA %s", _other );
2447 outline0("LDA CPUMATHMUL16BITTO32BIT_OTHER+1");
2448 outline1("STA %s", address_displacement(_environment, _other, "1") );
2449 outline0("LDA CPUMATHMUL16BITTO32BIT_OTHER+2");
2450 outline1("STA %s", address_displacement(_environment, _other, "2") );
2451 outline0("LDA CPUMATHMUL16BITTO32BIT_OTHER+3");
2452 outline1("STA %s", address_displacement(_environment, _other, "3") );
2453 }
2454
2455 done()
2456
2457}
2458
2459void cpu_math_mul_nbit_to_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _bits ) {
2460
2462
2463 int i;
2464
2465 char afterLabel[MAX_TEMPORARY_STORAGE]; sprintf( afterLabel, "%safter", label);
2466 char destination[MAX_TEMPORARY_STORAGE]; sprintf( destination, "CPUMATHMULNBITTONBIT%d_DESTINATION", (_bits>>3));
2467 char source[MAX_TEMPORARY_STORAGE]; sprintf( source, "CPUMATHMULNBITTONBIT%d_SOURCE", (_bits>>3));
2468 char other[MAX_TEMPORARY_STORAGE]; sprintf( other, "CPUMATHMULNBITTONBIT%d_OTHER", (_bits>>3));
2469
2470 // no_inline( cpu_math_mul_nbit_to_nbit )
2471
2472 // embedded( cpu_math_mul_nbit_to_nbit, src_hw_6502_cpu_math_mul_nbit_to_nbit_asm )
2473
2474 if ( ! _environment->cpuOptimization.cpu_math_mul_nbit_to_nbit[_bits>>3] ) {
2475
2476 outline1("JMP %s", afterLabel );
2477
2478 outhead2("CPUMATHMULNBITTONBIT%d_SOURCE: .RES %d", _bits>>3, _bits>>3 );
2479 outhead2("CPUMATHMULNBITTONBIT%d_DESTINATION: .RES %d", _bits>>3, _bits>>3 );
2480 outhead2("CPUMATHMULNBITTONBIT%d_OTHER: .RES %d", _bits>>3, _bits>>3 );
2481
2482 outhead1("CPUMATHMULNBITTONBIT%d:", _bits>>3);
2483 outhead0("LDA #$00");
2484 for( i=0; i<(_bits>>3); ++i ) {
2485 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2486 outline1("STA %s", address_displacement( _environment, other, offset ) );
2487 }
2488 outline1("LDX #$%2.2x", _bits );
2489
2490 outhead1("CPUMATHMULNBITTONBIT%dL1:", _bits>>3);
2491
2492 // The process of multiplying binary numbers is similar and easier to do than
2493 // decimal multiplication as binary numbers consist of only two digits which
2494 // are 0 and 1. The method of multiplying binary numbers is given below. The
2495 // same set of rules also apply to binary numbers with a decimal point. Let
2496 // us take the example of multiplying (11101) and (1001).
2497 //
2498 // The decimal equivalent of (11101) is 29 and the decimal equivalent
2499 // of (1001) is 9. Now let us multiply these numbers.
2500
2501 // Step 1: Write down the multiplicand (11101) and the multiplier (1001)
2502 // one below the other in proper positions.
2503
2504 char multiplyByBit0Label[MAX_TEMPORARY_STORAGE]; sprintf( multiplyByBit0Label, "%sb%dbit0", label, _bits>>3 );
2505
2506 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", (_bits>>3)-1 );
2507
2508 outline1("LSR %s", address_displacement( _environment, destination, offset ) );
2509 for( i=(_bits>>3)-2; i>-1; --i ) {
2510 sprintf( offset, "%d", i );
2511 outline1("ROR %s", address_displacement( _environment, destination, offset ) );
2512 }
2513 outline1("BCS %sx", multiplyByBit0Label );
2514 outline1("JMP %s", multiplyByBit0Label );
2515 outhead1("%sx:", multiplyByBit0Label );
2516
2517 // Step 2: Multiply the rightmost digit or the least significant bit (LSB)
2518 // of the multiplier (1) with all the digits of the multiplicand (11101).
2519
2520 outline0("CLC" );
2521 for( i=0; i<(_bits>>3); ++i ) {
2522 sprintf( offset, "%d", i );
2523 outline1("LDA %s", address_displacement( _environment, source, offset ) );
2524 outline1("ADC %s", address_displacement( _environment, other, offset ) );
2525 outline1("STA %s", address_displacement( _environment, other, offset ) );
2526 }
2527
2528 // Step 3: Add a place holder of '0' or 'X' before multiplying the next
2529 // higher order digit of the multiplier& with the multiplicand.
2530
2531 outhead1("%s:", multiplyByBit0Label);
2532
2533 outline0("CLC" );
2534 outline1("ASL %s", address_displacement( _environment, source, "0" ) );
2535 for( i=1; i<(_bits>>3); ++i ) {
2536 sprintf( offset, "%d", i );
2537 outline1("ROL %s", address_displacement( _environment, source, offset ) );
2538 }
2539
2540 // Step 4: Repeat the same process for all the next higher-order digits
2541 // until we reach the most significant bit (MSB) which is the left-most
2542 // digit of the multiplicand with the multiplier.
2543
2544 outline0("DEX" );
2545 outline1("BEQ CPUMATHMULNBITTONBIT%dL1x", (_bits>>3) );
2546 outline1("JMP CPUMATHMULNBITTONBIT%dL1", (_bits>>3) );
2547 outhead1("CPUMATHMULNBITTONBIT%dL1x:", (_bits>>3) );
2548
2549 outline0("RTS" );
2550
2551 // Step 5: The product obtained in each row is called the partial product.
2552 // Finally, add all the partial products. To add all the binary numbers
2553 // use the rules of binary addition.
2554
2555 // (The rules for binary addition are listed as follows: 0 + 0 = 0, 0 + 1 = 1, and 1 + 1 = 0, with a carryover of 1. So, 1 + 1 = 10 and 1 + 1 + 1 = 11 in the binary number system)
2556 outhead1("%s:", afterLabel );
2557
2558 }
2559
2560 for( i=0; i<(_bits>>3); ++i ) {
2561 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2562 outline1("LDA %s", address_displacement( _environment, _source, offset ) );
2563 outline1("STA %s", address_displacement( _environment, source, offset ) );
2564 outline1("LDA %s", address_displacement( _environment, _destination, offset ) );
2565 outline1("STA %s", address_displacement( _environment, destination, offset ) );
2566 }
2567 outline1("JSR CPUMATHMULNBITTONBIT%d", _bits >> 3 );
2568 for( i=0; i<(_bits>>3); ++i ) {
2569 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2570 outline1("LDA %s", address_displacement( _environment, other, offset ) );
2571 if ( _other ) {
2572 outline1("STA %s", address_displacement( _environment, _other, offset ) );
2573 } else {
2574 outline1("STA %s", address_displacement( _environment, _destination, offset ) );
2575 }
2576 }
2577
2578 // done()
2579
2580}
2581
2582void cpu_math_div_16bit_to_16bit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _signed ) {
2583
2585
2587
2588 if ( _signed ) {
2589
2590 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2591 outline1("EOR %s", address_displacement(_environment, _destination, "1") );
2592 outline0("AND #$80" );
2593 outline0("PHA");
2594
2595 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2596 outline0("AND #$80" );
2597 outline1("BEQ %ssecond", label );
2598 outline0("CLC" );
2599 outline1("LDA %s", _source );
2600 outline0("EOR #$ff" );
2601 outline0("STA MATHPTR0" );
2602 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2603 outline0("EOR #$ff" );
2604 outline0("STA MATHPTR1" );
2605 outline0("CLC" );
2606 outline0("LDA MATHPTR0" );
2607 outline0("ADC #1" );
2608 outline0("STA MATHPTR0" );
2609 outline0("LDA MATHPTR1" );
2610 outline0("ADC #0" );
2611 outline0("STA MATHPTR1" );
2612 outline1("JMP %ssecond2", label );
2613 outhead1("%ssecond:", label );
2614 outline1("LDA %s", _source );
2615 outline0("STA MATHPTR0");
2616 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2617 outline0("STA MATHPTR1");
2618 outline1("JMP %ssecond2", label );
2619
2620 outhead1("%ssecond2:", label );
2621 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2622 outline0("AND #$80" );
2623 outline1("BEQ %sthird", label );
2624 outline0("CLC" );
2625 outline1("LDA %s", _destination );
2626 outline0("EOR #$ff" );
2627 outline0("STA MATHPTR2" );
2628 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2629 outline0("EOR #$ff" );
2630 outline0("STA MATHPTR3" );
2631 outline0("CLC" );
2632 outline0("LDA MATHPTR2" );
2633 outline0("ADC #1" );
2634 outline0("STA MATHPTR2" );
2635 outline0("LDA MATHPTR3" );
2636 outline0("ADC #0" );
2637 outline0("STA MATHPTR3" );
2638 outline1("JMP %sthird2", label );
2639 outhead1("%sthird:", label );
2640 outline1("LDA %s", _destination );
2641 outline0("STA MATHPTR2");
2642 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2643 outline0("STA MATHPTR3");
2644 outline1("JMP %sthird2", label );
2645
2646 outhead1("%sthird2:", label );
2647
2648 outline0("LDA MATHPTR0" );
2649 outline1("STA %s", _other );
2650 outline0("LDA MATHPTR1" );
2651 outline1("STA %s", address_displacement(_environment, _other, "1") );
2652
2653 outline0("LDA #0" );
2654 outline1("STA %s", _other_remainder );
2655 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2656 outline0("LDX #16" );
2657 outhead1("%sL1:", label );
2658 outline1("ASL %s", _other );
2659 outline1("ROL %s", address_displacement(_environment, _other, "1") );
2660 outline1("ROL %s", _other_remainder );
2661 outline1("ROL %s", address_displacement(_environment, _other_remainder, "1") );
2662 outline1("LDA %s", _other_remainder );
2663 outline0("SEC" );
2664 outline0("SBC MATHPTR2" );
2665 outline0("TAY" );
2666 outline1("LDA %s", address_displacement(_environment, _other_remainder, "1") );
2667 outline0("SBC MATHPTR3" );
2668 outline1("BCC %sL2", label );
2669 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2670 outline1("STY %s", _other_remainder );
2671 outline1("INC %s", _other );
2672 outhead1("%sL2:", label );
2673 outline0("DEX" );
2674 outhead1("BNE %sL1", label );
2675
2676 outline0("PLA");
2677 outline0("AND #$80");
2678 outline1("BEQ %sdone", label);
2679 outline1("LDA %s", _other );
2680 outline0("EOR #$ff" );
2681 outline1("STA %s", _other );
2682 outline1("LDA %s", address_displacement(_environment, _other, "1") );
2683 outline0("EOR #$ff" );
2684 outline1("STA %s", address_displacement(_environment, _other, "1") );
2685 outline0("CLC" );
2686 outline1("LDA %s", _other );
2687 outline0("ADC #1" );
2688 outline1("STA %s", _other );
2689 outline1("LDA %s", address_displacement(_environment, _other, "1") );
2690 outline0("ADC #0" );
2691 outline1("STA %s", address_displacement(_environment, _other, "1") );
2692 outhead1("%sdone:", label );
2693
2694 } else {
2695 outline1("LDA %s", _source );
2696 outline1("STA %s", _other );
2697 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2698 outline1("STA %s", address_displacement(_environment, _other, "1") );
2699
2700 outline0("LDA #0" );
2701 outline1("STA %s", _other_remainder );
2702 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2703 outline0("LDX #16" );
2704 outhead1("%sL1:", label );
2705 outline1("ASL %s", _other );
2706 outline1("ROL %s", address_displacement(_environment, _other, "1") );
2707 outline1("ROL %s", _other_remainder );
2708 outline1("ROL %s", address_displacement(_environment, _other_remainder, "1") );
2709 outline1("LDA %s", _other_remainder );
2710 outline0("SEC" );
2711 outline1("SBC %s", _destination );
2712 outline0("TAY" );
2713 outline1("LDA %s", address_displacement(_environment, _other_remainder, "1") );
2714 outline1("SBC %s", address_displacement(_environment, _destination, "1") );
2715 outline1("BCC %sL2", label );
2716 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2717 outline1("STY %s", _other_remainder );
2718 outline1("INC %s", _other );
2719 outhead1("%sL2:", label );
2720 outline0("DEX" );
2721 outhead1("BNE %sL1", label );
2722 }
2723
2725
2726 if ( _signed ) {
2727 outline1("LDA %s", _source );
2728 outline0("STA CPUMATHDIV16BITTO16BIT_SOURCE");
2729 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2730 outline0("STA CPUMATHDIV16BITTO16BIT_SOURCE+1");
2731 outline1("LDA %s", _destination );
2732 outline0("STA CPUMATHDIV16BITTO16BIT_DESTINATION");
2733 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2734 outline0("STA CPUMATHDIV16BITTO16BIT_DESTINATION+1");
2735 outline0("JSR CPUMATHDIV16BITTO16BIT_SIGNED");
2736 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER");
2737 outline1("STA %s", _other );
2738 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER+1");
2739 outline1("STA %s", address_displacement(_environment, _other, "1") );
2740 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER_REMAINDER");
2741 outline1("STA %s", _other_remainder );
2742 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER_REMAINDER+1");
2743 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2744 } else {
2745 outline1("LDA %s", _source );
2746 outline0("STA CPUMATHDIV16BITTO16BIT_SOURCE");
2747 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2748 outline0("STA CPUMATHDIV16BITTO16BIT_SOURCE+1");
2749 outline1("LDA %s", _destination );
2750 outline0("STA CPUMATHDIV16BITTO16BIT_DESTINATION");
2751 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2752 outline0("STA CPUMATHDIV16BITTO16BIT_DESTINATION+1");
2753 outline0("JSR CPUMATHDIV16BITTO16BIT");
2754 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER");
2755 outline1("STA %s", _other );
2756 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER+1");
2757 outline1("STA %s", address_displacement(_environment, _other, "1") );
2758 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER_REMAINDER");
2759 outline1("STA %s", _other_remainder );
2760 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER_REMAINDER+1");
2761 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2762 }
2763
2764 done()
2765
2766}
2767
2768void cpu_math_div_16bit_to_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _signed ) {
2769
2771
2773
2774 if ( _signed ) {
2775
2776 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2777 outline1("EOR #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2778 outline0("AND #$80" );
2779 outline0("PHA");
2780
2781 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2782 outline0("AND #$80" );
2783 outline1("BEQ %ssecond", label );
2784 outline0("CLC" );
2785 outline1("LDA %s", _source );
2786 outline0("EOR #$ff" );
2787 outline0("STA MATHPTR0" );
2788 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2789 outline0("EOR #$ff" );
2790 outline0("STA MATHPTR1" );
2791 outline0("CLC" );
2792 outline0("LDA MATHPTR0" );
2793 outline0("ADC #1" );
2794 outline0("STA MATHPTR0" );
2795 outline0("LDA MATHPTR1" );
2796 outline0("ADC #0" );
2797 outline0("STA MATHPTR1" );
2798 outline1("JMP %ssecond2", label );
2799 outhead1("%ssecond:", label );
2800 outline1("LDA %s", _source );
2801 outline0("STA MATHPTR0");
2802 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2803 outline0("STA MATHPTR1");
2804 outline1("JMP %ssecond2", label );
2805
2806 outhead1("%ssecond2:", label );
2807 outline1("LDA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2808 outline0("AND #$80" );
2809 outline1("BEQ %sthird", label );
2810 outline0("CLC" );
2811 outline1("LDA #$%2.2x", (unsigned char)((_destination)&0xff) );
2812 outline0("EOR #$ff" );
2813 outline0("STA MATHPTR2" );
2814 outline1("LDA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2815 outline0("EOR #$ff" );
2816 outline0("STA MATHPTR3" );
2817 outline0("CLC" );
2818 outline0("LDA MATHPTR2" );
2819 outline0("ADC #1" );
2820 outline0("STA MATHPTR2" );
2821 outline0("LDA MATHPTR3" );
2822 outline0("ADC #0" );
2823 outline0("STA MATHPTR3" );
2824 outline1("JMP %sthird2", label );
2825 outhead1("%sthird:", label );
2826 outline1("LDA #$%2.2x", (unsigned char)((_destination)&0xff) );
2827 outline0("STA MATHPTR2");
2828 outline1("LDA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2829 outline0("STA MATHPTR3");
2830 outline1("JMP %sthird2", label );
2831
2832 outhead1("%sthird2:", label );
2833
2834 outline0("LDA MATHPTR0" );
2835 outline1("STA %s", _other );
2836 outline0("LDA MATHPTR1" );
2837 outline1("STA %s", address_displacement(_environment, _other, "1") );
2838
2839 outline0("LDA #0" );
2840 outline1("STA %s", _other_remainder );
2841 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2842 outline0("LDX #16" );
2843 outhead1("%sL1:", label );
2844 outline1("ASL %s", _other );
2845 outline1("ROL %s", address_displacement(_environment, _other, "1") );
2846 outline1("ROL %s", _other_remainder );
2847 outline1("ROL %s", address_displacement(_environment, _other_remainder, "1") );
2848 outline1("LDA %s", _other_remainder );
2849 outline0("SEC" );
2850 outline0("SBC MATHPTR2" );
2851 outline0("TAY" );
2852 outline1("LDA %s", address_displacement(_environment, _other_remainder, "1") );
2853 outline0("SBC MATHPTR3" );
2854 outline1("BCC %sL2", label );
2855 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2856 outline1("STY %s", _other_remainder );
2857 outline1("INC %s", _other );
2858 outhead1("%sL2:", label );
2859 outline0("DEX" );
2860 outhead1("BNE %sL1", label );
2861
2862 outline0("PLA");
2863 outline0("AND #$80");
2864 outline1("BEQ %sdone", label);
2865 outline1("LDA %s", _other );
2866 outline0("EOR #$ff" );
2867 outline1("STA %s", _other );
2868 outline1("LDA %s", address_displacement(_environment, _other, "1") );
2869 outline0("EOR #$ff" );
2870 outline1("STA %s", address_displacement(_environment, _other, "1") );
2871 outline0("CLC" );
2872 outline1("LDA %s", _other );
2873 outline0("ADC #1" );
2874 outline1("STA %s", _other );
2875 outline1("LDA %s", address_displacement(_environment, _other, "1") );
2876 outline0("ADC #0" );
2877 outline1("STA %s", address_displacement(_environment, _other, "1") );
2878 outhead1("%sdone:", label );
2879
2880 } else {
2881 outline1("LDA %s", _source );
2882 outline1("STA %s", _other );
2883 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2884 outline1("STA %s", address_displacement(_environment, _other, "1") );
2885
2886 outline0("LDA #0" );
2887 outline1("STA %s", _other_remainder );
2888 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2889 outline0("LDX #16" );
2890 outhead1("%sL1:", label );
2891 outline1("ASL %s", _other );
2892 outline1("ROL %s", address_displacement(_environment, _other, "1") );
2893 outline1("ROL %s", _other_remainder );
2894 outline1("ROL %s", address_displacement(_environment, _other_remainder, "1") );
2895 outline1("LDA %s", _other_remainder );
2896 outline0("SEC" );
2897 outline1("SBC #$%2.2x", (unsigned char)((_destination)&0xff) );
2898 outline0("TAY" );
2899 outline1("LDA %s", address_displacement(_environment, _other_remainder, "1") );
2900 outline1("SBC #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2901 outline1("BCC %sL2", label );
2902 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2903 outline1("STY %s", _other_remainder );
2904 outline1("INC %s", _other );
2905 outhead1("%sL2:", label );
2906 outline0("DEX" );
2907 outhead1("BNE %sL1", label );
2908 }
2909
2911
2912 if ( _signed ) {
2913 outline1("LDA %s", _source );
2914 outline0("STA CPUMATHDIV16BITTO16BIT_SOURCE");
2915 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2916 outline0("STA CPUMATHDIV16BITTO16BIT_SOURCE+1");
2917 outline1("LDA #$%2.2x", (unsigned char)((_destination)&0xff) );
2918 outline0("STA CPUMATHDIV16BITTO16BIT_DESTINATION");
2919 outline1("LDA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2920 outline0("STA CPUMATHDIV16BITTO16BIT_DESTINATION+1");
2921 outline0("JSR CPUMATHDIV16BITTO16BIT_SIGNED");
2922 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER");
2923 outline1("STA %s", _other );
2924 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER+1");
2925 outline1("STA %s", address_displacement(_environment, _other, "1") );
2926 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER_REMAINDER");
2927 outline1("STA %s", _other_remainder );
2928 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER_REMAINDER+1");
2929 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2930 } else {
2931 outline1("LDA %s", _source );
2932 outline0("STA CPUMATHDIV16BITTO16BIT_SOURCE");
2933 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2934 outline0("STA CPUMATHDIV16BITTO16BIT_SOURCE+1");
2935 outline1("LDA #$%2.2x", (unsigned char)((_destination)&0xff) );
2936 outline0("STA CPUMATHDIV16BITTO16BIT_DESTINATION");
2937 outline1("LDA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2938 outline0("STA CPUMATHDIV16BITTO16BIT_DESTINATION+1");
2939 outline0("JSR CPUMATHDIV16BITTO16BIT");
2940 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER");
2941 outline1("STA %s", _other );
2942 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER+1");
2943 outline1("STA %s", address_displacement(_environment, _other, "1") );
2944 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER_REMAINDER");
2945 outline1("STA %s", _other_remainder );
2946 outline0("LDA CPUMATHDIV16BITTO16BIT_OTHER_REMAINDER+1");
2947 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
2948 }
2949
2950 done()
2951
2952}
2953
2962void cpu_math_sub_16bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
2963
2964 inline( cpu_math_sub_16bit )
2965
2966 outline0("SEC");
2967 outline1("LDA %s", _source);
2968 outline1("SBC %s", _destination);
2969 if ( _other ) {
2970 outline1("STA %s", _other);
2971 } else {
2972 outline1("STA %s", _destination);
2973 }
2974 outline1("LDA %s", address_displacement(_environment, _source, "1"));
2975 outline1("SBC %s", address_displacement(_environment, _destination, "1"));
2976 if ( _other ) {
2977 outline1("STA %s", address_displacement(_environment, _other, "1"));
2978 } else {
2979 outline1("STA %s", address_displacement(_environment, _destination, "1"));
2980 }
2981
2983
2984}
2985
2986void cpu_math_sub_16bit_with_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
2987
2989
2990 outline0("SEC");
2991 outline1("LDA %s", _source);
2992 outline1("SBC %s", _destination);
2993 if ( _other ) {
2994 outline1("STA %s", _other);
2995 } else {
2996 outline1("STA %s", _destination);
2997 }
2998 outline1("LDA %s", address_displacement(_environment, _source, "1"));
2999 outline0("SBC #$0");
3000 if ( _other ) {
3001 outline1("STA %s", address_displacement(_environment, _other, "1"));
3002 } else {
3003 outline1("STA %s", address_displacement(_environment, _destination, "1"));
3004 }
3005
3007
3008}
3009
3017void cpu_math_complement_const_16bit( Environment * _environment, char *_source, int _value ) {
3018
3020
3021 outline0("SEC");
3022 outline1("LDA #$%2.2x", ( _value & 0xff ) );
3023 outline1("SBC %s", _source);
3024 outline1("STA %s", _source );
3025 outline1("LDA #$%2.2x", ( ( _value >> 8 ) & 0xff ) );
3026 outline1("SBC %s", address_displacement(_environment, _source, "1"));
3027 outline1("STA %s", address_displacement(_environment, _source, "1") );
3028
3030
3031}
3032
3040void cpu_math_div2_const_16bit( Environment * _environment, char *_source, int _steps, int _signed, char * _remainder ) {
3041
3043
3045
3046 if ( _signed ) {
3047 if ( _remainder ) {
3048 outline1("LDA %s", _source);
3049 outline0("AND #$01" );
3050 outline1("STA %s", _remainder);
3051 }
3052 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3053 outline0("AND #$80" );
3054 outline0("TAX")
3055 outline1("BEQ %snocomplement", label );
3056 cpu_complement2_16bit( _environment, _source, _source );
3057 outhead1("%snocomplement:", label );
3058 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3059 outline0("AND #$7F");
3060 outline1("STA %s", address_displacement(_environment, _source, "1"));
3061 while( _steps ) {
3062 outline0("CLC");
3063 outline1("LSR %s", address_displacement(_environment, _source, "1"));
3064 outline1("ROR %s", _source);
3065 --_steps;
3066 }
3067 outline0("TXA")
3068 outline1("BEQ %snocomplement2", label );
3069 cpu_complement2_16bit( _environment, _source, _source );
3070 outhead1("%snocomplement2:", label );
3071 outline1("ORA %s", address_displacement(_environment, _source, "1"));
3072 outline1("STA %s", address_displacement(_environment, _source, "1"));
3073 } else {
3074 if ( _remainder ) {
3075 outline1("LDA %s", _source);
3076 outline0("AND #$01" );
3077 outline1("STA %s", _remainder);
3078 }
3079 while( _steps ) {
3080 outline0("CLC");
3081 outline1("LSR %s", address_displacement(_environment, _source, "1"));
3082 outline1("ROR %s", _source);
3083 --_steps;
3084 }
3085 }
3086
3088
3089
3090}
3091
3099void cpu_math_mul2_const_16bit( Environment * _environment, char *_source, int _steps, int _signed ) {
3100
3102
3103 if ( _signed ) {
3104 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3105 outline0("AND #$80" );
3106 outline0("TAX")
3107 while( _steps ) {
3108 outline0("CLC");
3109 outline1("ASL %s", _source);
3110 outline1("ROL %s", address_displacement(_environment, _source, "1"));
3111 --_steps;
3112 }
3113 outline0("TXA")
3114 outline1("ORA %s", address_displacement(_environment, _source, "1"));
3115 outline1("STA %s", address_displacement(_environment, _source, "1"));
3116 } else {
3117 while( _steps ) {
3118 outline0("CLC");
3119 outline1("ASL %s", _source);
3120 outline1("ROL %s", address_displacement(_environment, _source, "1"));
3121 --_steps;
3122 }
3123 }
3124
3126
3127}
3128
3136void cpu_math_and_const_16bit( Environment * _environment, char *_source, int _mask ) {
3137
3138 inline( cpu_math_and_const_16bit )
3139
3140 outline1("LDA %s", _source);
3141 outline1("AND #$%2.2x", (_mask & 0xff ) );
3142 outline1("STA %s", _source);
3143 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3144 outline1("AND #$%2.2x", ((_mask>>8) & 0xff ));
3145 outline1("STA %s", address_displacement(_environment, _source, "1"));
3146
3148
3149}
3150
3151/*****************************************************************************
3152 * 32 BIT MANIPULATION
3153 ****************************************************************************/
3154
3162void cpu_move_32bit( Environment * _environment, char *_source, char *_destination ) {
3163
3164 inline( cpu_move_32bit )
3165
3166 outline1("LDA %s", _source);
3167 outline1("STA %s", _destination);
3168 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3169 outline1("STA %s", address_displacement(_environment, _destination, "1"));
3170 outline1("LDA %s", address_displacement(_environment, _source, "2"));
3171 outline1("STA %s", address_displacement(_environment, _destination, "2"));
3172 outline1("LDA %s", address_displacement(_environment, _source, "3"));
3173 outline1("STA %s", address_displacement(_environment, _destination, "3"));
3174
3176
3177}
3178
3186void cpu_store_32bit( Environment * _environment, char *_destination, int _value ) {
3187
3188 inline( cpu_store_32bit )
3189
3190 outline1("LDA #$%2.2x", ( _value & 0xff ) );
3191 outline1("STA %s", _destination);
3192 outline1("LDA #$%2.2x", ( ( _value >> 8 ) & 0xff ) );
3193 outline1("STA %s", address_displacement(_environment, _destination, "1"));
3194 outline1("LDA #$%2.2x", ( ( _value >> 16 ) & 0xff ) );
3195 outline1("STA %s", address_displacement(_environment, _destination, "2"));
3196 outline1("LDA #$%2.2x", ( ( _value >> 24 ) & 0xff ) );
3197 outline1("STA %s", address_displacement(_environment, _destination, "3"));
3198
3200
3201}
3202
3203void cpu_math_div_32bit_to_16bit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _signed ) {
3204
3206
3208
3209 outline1("LDA %s", _source );
3210 outline0("STA MATHPTR4");
3211 outline1("LDA %s", address_displacement(_environment, _source, "1") );
3212 outline0("STA MATHPTR5");
3213 outline1("LDA %s", address_displacement(_environment, _source, "2") );
3214 outline0("STA MATHPTR2");
3215 outline1("LDA %s", address_displacement(_environment, _source, "3") );
3216 outline0("STA MATHPTR3" );
3217
3218 outline1("LDA %s", _destination );
3219 outline0("STA MATHPTR0");
3220 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
3221 outline0("STA MATHPTR1" );
3222
3223 outhead1("%sSTART:", label );
3224 outline0("SEC" );
3225 outline0("LDA MATHPTR2" );
3226 outline0("SBC MATHPTR0" );
3227 outline0("LDA MATHPTR3" );
3228 outline0("SBC MATHPTR1 " );
3229 outline1("BCS %soflo", label );
3230 outline0("LDX #$11" );
3231 outhead1("%sloop:", label)
3232
3233 outline0("ROL MATHPTR4");
3234 outline0("ROL MATHPTR5");
3235 outline0("DEX" );
3236 outline1("BEQ %send", label );
3237
3238 outline0("ROL MATHPTR2" );
3239 outline0("ROL MATHPTR3" );
3240 outline0("STA MATHPTR7" );
3241 outline0("ROL MATHPTR8" ); // <<--- forse MATHPTR7
3242 outline0("SEC" );
3243 outline0("LDA MATHPTR2" );
3244 outline0("SBC MATHPTR0" );
3245 outline0("STA MATHPTR6" );
3246 outline0("LDA MATHPTR3" );
3247 outline0("SBC MATHPTR1" );
3248 outline0("TAY" );
3249 outline0("LDA MATHPTR8" ); // <<--- forse MATHPTR8
3250 outline0("SBC #0" );
3251 outline1("BCC %sloop", label )
3252 outline0("LDA MATHPTR6");
3253 outline0("STA MATHPTR2");
3254 outline0("STY MATHPTR3" );
3255 outline1("JMP %sloop", label );
3256
3257 outhead1("%soflo:", label );
3258 outline0("LDA #$ff" );
3259 outline0("STA MATHPTR2" );
3260 outline0("STA MATHPTR3" );
3261 outline0("STA MATHPTR4" );
3262 outline0("STA MATHPTR5" );
3263 outhead1("%send:", label );
3264
3265 outline0("LDA MATHPTR4");
3266 outline1("STA %s", _other );
3267 outline0("LDA MATHPTR5");
3268 outline1("STA %s", address_displacement(_environment, _other, "1") );
3269 outline0("LDA MATHPTR2");
3270 outline1("STA %s", _other_remainder );
3271 outline0("LDA MATHPTR3");
3272 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
3273
3275
3276 outline1("LDA %s", address_displacement(_environment, _source, "3"));
3277 outline0("AND #$80");
3278 outline0("PHA");
3279 outline1("BEQ %snocomplement", label );
3280 cpu_complement2_32bit( _environment, _source, _source );
3281 outhead1("%snocomplement:", label );
3282 outline1("LDA %s", _source );
3283 outline0("STA MATHPTR4");
3284 outline1("LDA %s", address_displacement(_environment, _source, "1") );
3285 outline0("STA MATHPTR5");
3286 outline1("LDA %s", address_displacement(_environment, _source, "2") );
3287 outline0("STA MATHPTR2");
3288 outline1("LDA %s", address_displacement(_environment, _source, "3") );
3289 outline0("STA MATHPTR3" );
3290 outline1("LDA %s", _destination );
3291 outline0("STA MATHPTR0");
3292 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
3293 outline0("STA MATHPTR1" );
3294 outline0("JSR CPUMATHDIV32BITTO16BIT" );
3295 outline0("LDA MATHPTR4");
3296 outline1("STA %s", _other );
3297 outline0("LDA MATHPTR5");
3298 outline1("STA %s", address_displacement(_environment, _other, "1") );
3299 outline0("LDA MATHPTR2");
3300 outline1("STA %s", _other_remainder );
3301 outline0("LDA MATHPTR3");
3302 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
3303
3304 outline0("PLA");
3305 outline1("BEQ %snocomplement2", label );
3306 cpu_complement2_32bit( _environment, _source, _source );
3307 cpu_complement2_32bit( _environment, _other, _other );
3308 outhead1("%snocomplement2:", label );
3309
3310 done()
3311
3312}
3313
3314void cpu_math_div_32bit_to_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _signed ) {
3315
3317
3319
3320 outline1("LDA %s", _source );
3321 outline0("STA MATHPTR4");
3322 outline1("LDA %s", address_displacement(_environment, _source, "1") );
3323 outline0("STA MATHPTR5");
3324 outline1("LDA %s", address_displacement(_environment, _source, "2") );
3325 outline0("STA MATHPTR2");
3326 outline1("LDA %s", address_displacement(_environment, _source, "3") );
3327 outline0("STA MATHPTR3" );
3328
3329 outline1("LDA #$%2.2x", (unsigned char)((_destination)&0xff) );
3330 outline0("STA MATHPTR0");
3331 outline1("LDA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
3332 outline0("STA MATHPTR1" );
3333
3334 outhead1("%sSTART:", label );
3335 outline0("SEC" );
3336 outline0("LDA MATHPTR2" );
3337 outline0("SBC MATHPTR0" );
3338 outline0("LDA MATHPTR3" );
3339 outline0("SBC MATHPTR1 " );
3340 outline1("BCS %soflo", label );
3341 outline0("LDX #$11" );
3342 outhead1("%sloop:", label)
3343
3344 outline0("ROL MATHPTR4");
3345 outline0("ROL MATHPTR5");
3346 outline0("DEX" );
3347 outline1("BEQ %send", label );
3348
3349 outline0("ROL MATHPTR2" );
3350 outline0("ROL MATHPTR3" );
3351 outline0("STA MATHPTR7" );
3352 outline0("ROL MATHPTR8" ); // <<--- forse MATHPTR7
3353 outline0("SEC" );
3354 outline0("LDA MATHPTR2" );
3355 outline0("SBC MATHPTR0" );
3356 outline0("STA MATHPTR6" );
3357 outline0("LDA MATHPTR3" );
3358 outline0("SBC MATHPTR1" );
3359 outline0("TAY" );
3360 outline0("LDA MATHPTR8" ); // <<--- forse MATHPTR8
3361 outline0("SBC #0" );
3362 outline1("BCC %sloop", label )
3363 outline0("LDA MATHPTR6");
3364 outline0("STA MATHPTR2");
3365 outline0("STY MATHPTR3" );
3366 outline1("JMP %sloop", label );
3367
3368 outhead1("%soflo:", label );
3369 outline0("LDA #$ff" );
3370 outline0("STA MATHPTR2" );
3371 outline0("STA MATHPTR3" );
3372 outline0("STA MATHPTR4" );
3373 outline0("STA MATHPTR5" );
3374 outhead1("%send:", label );
3375
3376 outline0("LDA MATHPTR4");
3377 outline1("STA %s", _other );
3378 outline0("LDA MATHPTR5");
3379 outline1("STA %s", address_displacement(_environment, _other, "1") );
3380 outline0("LDA MATHPTR2");
3381 outline1("STA %s", _other_remainder );
3382 outline0("LDA MATHPTR3");
3383 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
3384
3386
3387 outline1("LDA %s", address_displacement(_environment, _source, "3"));
3388 outline0("AND #$80");
3389 outline0("PHA");
3390 outline1("BEQ %snocomplement", label );
3391 cpu_complement2_32bit( _environment, _source, _source );
3392 outhead1("%snocomplement:", label );
3393 outline1("LDA %s", _source );
3394 outline0("STA MATHPTR4");
3395 outline1("LDA %s", address_displacement(_environment, _source, "1") );
3396 outline0("STA MATHPTR5");
3397 outline1("LDA %s", address_displacement(_environment, _source, "2") );
3398 outline0("STA MATHPTR2");
3399 outline1("LDA %s", address_displacement(_environment, _source, "3") );
3400 outline0("STA MATHPTR3" );
3401 outline1("LDA #$%2.2x", (unsigned char)((_destination)&0xff) );
3402 outline0("STA MATHPTR0");
3403 outline1("LDA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
3404 outline0("STA MATHPTR1" );
3405 outline0("JSR CPUMATHDIV32BITTO16BIT" );
3406 outline0("LDA MATHPTR4");
3407 outline1("STA %s", _other );
3408 outline0("LDA MATHPTR5");
3409 outline1("STA %s", address_displacement(_environment, _other, "1") );
3410 outline0("LDA MATHPTR2");
3411 outline1("STA %s", _other_remainder );
3412 outline0("LDA MATHPTR3");
3413 outline1("STA %s", address_displacement(_environment, _other_remainder, "1") );
3414 outline0("PLA");
3415 outline1("BEQ %snocomplement2", label );
3416 cpu_complement2_32bit( _environment, _source, _source );
3417 cpu_complement2_32bit( _environment, _other, _other );
3418 outhead1("%snocomplement2:", label );
3419
3420 done()
3421
3422}
3423
3424void cpu_math_div_nbit_to_nbit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _bits ) {
3425
3427
3428 int i;
3429
3431
3432 char afterLabel[MAX_TEMPORARY_STORAGE]; sprintf( afterLabel, "%safter", label );
3433 char skipLabel[MAX_TEMPORARY_STORAGE]; sprintf( skipLabel, "%sskip", label );
3434 char skip2Label[MAX_TEMPORARY_STORAGE]; sprintf( skip2Label, "%sskipb", label );
3435 char skip3Label[MAX_TEMPORARY_STORAGE]; sprintf( skip3Label, "%sskipc", label );
3436 char skip4Label[MAX_TEMPORARY_STORAGE]; sprintf( skip4Label, "%sskipd", label );
3437 char quotient[MAX_TEMPORARY_STORAGE]; sprintf( quotient, "CPUMATHDIVNBITTONBIT%d_QUOTIENT", _bits >> 3 );
3438 char divisor[MAX_TEMPORARY_STORAGE]; sprintf( divisor, "CPUMATHDIVNBITTONBIT%d_DIVISOR", _bits >> 3 );
3439 char dividend[MAX_TEMPORARY_STORAGE]; sprintf( dividend, "CPUMATHDIVNBITTONBIT%d_DIVIDEND", _bits >> 3 );
3440 char result1[MAX_TEMPORARY_STORAGE]; sprintf( result1, "CPUMATHDIVNBITTONBIT%d_RESULT1", _bits >> 3 );
3441 char result2[MAX_TEMPORARY_STORAGE]; sprintf( result2, "CPUMATHDIVNBITTONBIT%d_RESULT2", _bits >> 3 );
3442 char k[MAX_TEMPORARY_STORAGE]; sprintf( k, "CPUMATHDIVNBITTONBIT%d_K", _bits >> 3 );
3443
3444 if ( ! _environment->cpuOptimization.cpu_math_div_nbit_to_nbit[_bits>>3] ) {
3445
3446 cpu_jump( _environment, afterLabel );
3447
3448 outhead2("%s: .RES %d", quotient, _bits>>3 );
3449 outhead2("%s: .RES %d", divisor, _bits>>3 );
3450 outhead2("%s: .RES %d", dividend, _bits>>3 );
3451 outhead1("%s: .BYTE 0", k );
3452 outhead1("%s: .BYTE 0", result1 );
3453 outhead1("%s: .BYTE 0", result2 );
3454
3455 // public static long div(long dividend, long divisor) {
3456 // long quotient = 0;
3457
3458 outhead1("CPUMATHDIVNBITTONBIT%d:", _bits>>3);
3459 outhead0("LDA #$00");
3460 for( i=0; i<(_bits>>3); ++i ) {
3461 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
3462 outline1("STA %s", address_displacement( _environment, quotient, offset ) );
3463 }
3464
3465 // int k = 0;
3466 cpu_store_8bit( _environment, k, 0 );
3467
3468 // while (divisor <= dividend && divisor > 0) {
3469
3470 cpu_label( _environment, label );
3471 cpu_less_than_nbit( _environment, divisor, dividend, result1, 1, _bits );
3472 cpu_greater_than_nbit_const( _environment, divisor, 0, result2, 0, _bits );
3473 cpu_and_8bit( _environment, result1, result2, result1 );
3474 cpu_compare_and_branch_8bit_const( _environment, result1, 0, skipLabel, 1 );
3475
3476 // divisor <<= 1;
3477
3478 cpu_math_mul2_const_nbit( _environment, divisor, 1, _bits );
3479
3480 // k++;
3481
3482 cpu_inc( _environment, k );
3483
3484 // }
3485
3486 cpu_jump( _environment, label );
3487
3488 cpu_label( _environment, skipLabel );
3489
3490 // while (k-- > 0) {
3491
3492 cpu_greater_than_8bit_const( _environment, k, 0, result1, 0, 1 );
3493 cpu_dec( _environment, k );
3494 cpu_compare_and_branch_8bit_const( _environment, result1, 0, skip2Label, 1 );
3495
3496 // divisor >>= 1;
3497
3498 cpu_math_div2_const_nbit( _environment, divisor, 1, _bits, NULL );
3499
3500 // if (divisor <= dividend) {
3501 cpu_less_than_nbit( _environment, divisor, dividend, result1, 1, _bits );
3502 cpu_compare_and_branch_8bit_const( _environment, result1, 0, skip3Label, 1 );
3503
3504 // dividend -= divisor;
3505
3506 cpu_math_sub_nbit( _environment, dividend, divisor, dividend, _bits );
3507
3508 // quotient = (quotient << 1) + 1;
3509 cpu_math_mul2_const_nbit( _environment, quotient, 1, _bits );
3510 cpu_inc_nbit( _environment, quotient, _bits );
3511
3512 // }
3513 cpu_jump( _environment, skip4Label );
3514 cpu_label( _environment, skip3Label );
3515 // else quotient <<= 1;
3516 cpu_math_mul2_const_nbit( _environment, quotient, 1, _bits );
3517 cpu_label( _environment, skip4Label );
3518 cpu_jump( _environment, skipLabel );
3519
3520 // }
3521 cpu_label( _environment, skip2Label );
3522 // return quotient;
3523 cpu_return( _environment );
3524
3525 cpu_label( _environment, afterLabel );
3526
3527 }
3528
3529 for( i=0; i<(_bits>>3); ++i ) {
3530 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
3531 outline1("LDA %s", address_displacement( _environment, _source, offset ) );
3532 outline1("STA %s", address_displacement( _environment, dividend, offset ) );
3533 outline1("LDA %s", address_displacement( _environment, _destination, offset ) );
3534 outline1("STA %s", address_displacement( _environment, divisor, offset ) );
3535 }
3536 outline1("JSR CPUMATHDIVNBITTONBIT%d", _bits>>3);
3537
3538 for( i=0; i<(_bits>>3); ++i ) {
3539 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
3540 if ( _other ) {
3541 outline1("LDA %s", address_displacement( _environment, quotient, offset ) );
3542 outline1("STA %s", address_displacement( _environment, _other, offset ) );
3543 } else {
3544 outline1("LDA %s", address_displacement( _environment, quotient, offset ) );
3545 outline1("STA %s", address_displacement( _environment, _destination, offset ) );
3546 }
3547 }
3548
3549 // }
3551
3552}
3553
3554void cpu_math_div_nbit_to_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _bits ) {
3555
3557
3558 int i;
3559
3561
3562 char afterLabel[MAX_TEMPORARY_STORAGE]; sprintf( afterLabel, "%safter", label );
3563 char data[MAX_TEMPORARY_STORAGE]; sprintf( data, "CPUMATHDIVNBITTONBITCONST%d_DATA", _bits >> 3 );
3564
3565 if ( ! _environment->cpuOptimization.cpu_math_div_nbit_to_nbit_const[_bits>>3] ) {
3566
3567 cpu_jump( _environment, afterLabel );
3568
3569 outhead2("%s: .RES %d", data, _bits>>3 );
3570
3571 cpu_label( _environment, afterLabel );
3572
3573 }
3574
3575 for( i=0; i<(_bits>>3); ++i ) {
3576 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
3577 outline1("LDA #$%2.2x", (unsigned char)( (_destination >> (i*8)) & 0xff ) );
3578 outline1("STA %s", address_displacement( _environment, data, offset ) );
3579 }
3580 cpu_math_div_nbit_to_nbit( _environment, _source, data, _other, _other_remainder, _bits );
3581
3582 // }
3584
3585}
3586
3596void cpu_compare_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive ) {
3597
3599
3600 inline( cpu_compare_32bit )
3601
3602 outline1("LDA %s", _source);
3603 outline1("CMP %s", _destination);
3604 outline1("BNE %s", label);
3605 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3606 outline1("CMP %s", address_displacement(_environment, _destination, "1"));
3607 outline1("BNE %s", label);
3608 outline1("LDA %s", address_displacement(_environment, _source, "2"));
3609 outline1("CMP %s", address_displacement(_environment, _destination, "2"));
3610 outline1("BNE %s", label);
3611 outline1("LDA %s", address_displacement(_environment, _source, "3"));
3612 outline1("CMP %s", address_displacement(_environment, _destination, "3"));
3613 outline1("BNE %s", label);
3614 outline1("LDA #$%2.2x", 0xff*_positive);
3615 if ( _other ) {
3616 outline1("STA %s", _other);
3617 } else {
3618 outline1("STA %s", _destination);
3619 }
3620 outline1("JMP %s_2", label);
3621 outhead1("%s:", label);
3622 outline1("LDA #$%2.2x", 0xff*(1-_positive));
3623 if ( _other ) {
3624 outline1("STA %s", _other);
3625 } else {
3626 outline1("STA %s", _destination);
3627 }
3628 outhead1("%s_2:", label);
3629
3631
3632}
3633
3634void cpu_compare_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive, int _bits ) {
3635
3637
3638 inline( cpu_compare_nbit )
3639
3640 for( int i=0; i<(_bits>>3); ++i ) {
3641 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
3642 outline1("LDA %s", address_displacement(_environment, _source, offset));
3643 outline1("CMP %s", address_displacement(_environment, _destination, offset));
3644 outline2("BEQ %sx%dx", label, i);
3645 outline1("JMP %s", label);
3646 outhead2("%sx%dx:", label, i);
3647 }
3648 outline1("LDA #$%2.2x", 0xff*_positive);
3649 if ( _other ) {
3650 outline1("STA %s", _other);
3651 } else {
3652 outline1("STA %s", _destination);
3653 }
3654 outline1("JMP %s_2", label);
3655 outhead1("%s:", label);
3656 outline1("LDA #$%2.2x", 0xff*(1-_positive));
3657 if ( _other ) {
3658 outline1("STA %s", _other);
3659 } else {
3660 outline1("STA %s", _destination);
3661 }
3662 outhead1("%s_2:", label);
3663
3665
3666}
3667
3677void cpu_compare_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive, int _bits ) {
3678
3680
3681 int i;
3682
3683 inline( cpu_compare_nbit )
3684
3685 for( i=0; i<(_bits>>3); ++i ) {
3686 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
3687 outline1("LDA %s", address_displacement(_environment, _source, offset));
3688 outline1("CMP #$%2.2x", (unsigned char) ( ( _destination >> (i*8) ) & 0xff ) );
3689 outline1("BNE %s", label);
3690 }
3691 outline1("LDA #$%2.2x", 0xff*_positive);
3692 outline1("STA %s", _other);
3693 outline1("JMP %s_2", label);
3694 outhead1("%s:", label);
3695 outline1("LDA #$%2.2x", 0xff*(1-_positive));
3696 outline1("STA %s", _other);
3697 outhead1("%s_2:", label);
3698
3700
3701}
3702
3703void cpu_compare_32bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive ) {
3704
3706
3707 inline( cpu_compare_32bit )
3708
3709 outline1("LDA %s", _source);
3710 outline1("CMP #$%2.2x", (unsigned char) ( _destination & 0xff ) );
3711 outline1("BNE %s", label);
3712 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3713 outline1("CMP #$%2.2x", (unsigned char) ( ( _destination >> 8 ) & 0xff ) );
3714 outline1("BNE %s", label);
3715 outline1("LDA %s", address_displacement(_environment, _source, "2"));
3716 outline1("CMP #$%2.2x", (unsigned char) ( ( _destination >> 16 ) & 0xff ) );
3717 outline1("BNE %s", label);
3718 outline1("LDA %s", address_displacement(_environment, _source, "3"));
3719 outline1("CMP #$%2.2x", (unsigned char) ( ( _destination >> 24 ) & 0xff ) );
3720 outline1("BNE %s", label);
3721 outline1("LDA #$%2.2x", 0xff*_positive);
3722 outline1("STA %s", _other);
3723 outline1("JMP %s_2", label);
3724 outhead1("%s:", label);
3725 outline1("LDA #$%2.2x", 0xff*(1-_positive));
3726 outline1("STA %s", _other);
3727 outhead1("%s_2:", label);
3728
3730
3731}
3732
3742void cpu_compare_and_branch_32bit_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
3743
3745
3747
3748 outline1("LDA %s", address_displacement(_environment, _source, "3"));
3749 outline1("CMP #$%2.2x", (unsigned char)( _destination >> 24 ) & 0xff );
3750 outline1("BNE %s", label);
3751 outline1("LDA %s", address_displacement(_environment, _source, "2"));
3752 outline1("CMP #$%2.2x", (unsigned char)( _destination >> 16 ) & 0xff );
3753 outline1("BNE %s", label);
3754 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3755 outline1("CMP #$%2.2x", (unsigned char)( _destination >> 8 ) & 0xff );
3756 outline1("BNE %s", label);
3757 outline1("LDA %s", _source);
3758 outline1("CMP #$%2.2x", (unsigned char)( _destination & 0xff ) );
3759 outline1("BNE %s", label);
3760 if ( _positive ) {
3761 outline1("JMP %s", _label);
3762 outhead1("%s:", label);
3763 } else {
3764 outline1("JMP %snot", label);
3765 outhead1("%s:", label);
3766 outline1("JMP %s", _label);
3767 outhead1("%snot:", label);
3768 }
3769
3771
3772}
3773
3783void cpu_less_than_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
3784
3786
3787 inline( cpu_less_than_32bit )
3788
3789 if ( _equal ) {
3790
3791 cpu_compare_32bit( _environment, _source, _destination, _other, 1 );
3792
3793 if ( _other ) {
3794 outline1("LDA %s", _other);
3795 } else {
3796 outline1("LDA %s", _destination);
3797 }
3798
3799 outline1("BEQ %sless", label );
3800 outline1("JMP %sdone", label );
3801 outhead1("%sless:", label );
3802
3803 }
3804
3805 if ( _signed ) {
3806 outline1("LDA %s", _source);
3807 outline1("CMP %s", _destination);
3808 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3809 outline1("SBC %s", address_displacement(_environment, _destination, "1"));
3810 outline1("LDA %s", address_displacement(_environment, _source, "2"));
3811 outline1("SBC %s", address_displacement(_environment, _destination, "2"));
3812 outline1("LDA %s", address_displacement(_environment, _source, "3"));
3813 outline1("SBC %s", address_displacement(_environment, _destination, "3"));
3814 outline1("BVC %sv0", label );
3815 outline0("EOR #$80" );
3816 outhead1("%sv0:", label );
3817 outline1("BMI %smi", label );
3818 outhead1("%spl:", label );
3819 outline0("LDA #$00" );
3820 if ( _other ) {
3821 outline1("STA %s", _other);
3822 } else {
3823 outline1("STA %s", _destination);
3824 }
3825 outline1("JMP %sen", label );
3826 outhead1("%smi:", label );
3827 outline0("LDA #$FF" );
3828 if ( _other ) {
3829 outline1("STA %s", _other);
3830 } else {
3831 outline1("STA %s", _destination);
3832 }
3833 outhead1("%sen:", label);
3834
3835 } else {
3836 outline1("LDA %s", address_displacement(_environment, _source, "3"));
3837 outline1("CMP %s", address_displacement(_environment, _destination, "3") );
3838 outline1("BEQ %s_1a", label);
3839 outline1("BCC %s", label);
3840 outline1("BCS %s_0", label);
3841 outhead1("%s_1a:", label);
3842 outline1("LDA %s", address_displacement(_environment, _source, "2"));
3843 outline1("CMP %s", address_displacement(_environment, _destination, "2") );
3844 outline1("BEQ %s_1", label);
3845 outline1("BCC %s", label);
3846 outline1("BCS %s_0", label);
3847 outhead1("%s_1:", label);
3848 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3849 outline1("CMP %s", address_displacement(_environment, _destination, "1") );
3850 outline1("BEQ %s_1b", label);
3851 outline1("BCC %s", label);
3852 outline1("BCS %s_0", label);
3853 outhead1("%s_1b:", label);
3854 outline1("LDA %s", _source);
3855 outline1("CMP %s", _destination );
3856 outline1("BCC %s", label);
3857 outline1("BCS %s_0", label);
3858 outhead1("%s_0:", label);
3859 outline0("LDA #0" );
3860 if ( _other ) {
3861 outline1("STA %s", _other);
3862 } else {
3863 outline1("STA %s", _destination);
3864 }
3865 outline1("JMP %s_2", label);
3866 outhead1("%s:", label);
3867 outline0("LDA #$FF" );
3868 if ( _other ) {
3869 outline1("STA %s", _other);
3870 } else {
3871 outline1("STA %s", _destination);
3872 }
3873 outhead1("%s_2:", label);
3874 }
3875
3876 if ( _equal ) {
3877
3878 outhead1("%sdone:", label );
3879 if ( _other ) {
3880 outline1("STA %s", _other);
3881 } else {
3882 outline1("STA %s", _destination);
3883 }
3884
3885 }
3886
3888
3889}
3890
3891void cpu_less_than_32bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
3892
3894
3896
3897 if ( _signed ) {
3898
3899 if ( _equal ) {
3900
3901 cpu_compare_32bit_const( _environment, _source, _destination, _other, 1 );
3902
3903 if ( _other ) {
3904 outline1("LDA %s", _other);
3905 } else {
3906 outline1("LDA %s", _destination);
3907 }
3908
3909 outline1("BEQ %sless", label );
3910 outline1("JMP %sdone", label );
3911 outhead1("%sless:", label );
3912
3913 }
3914
3915 outline1("LDA %s", _source);
3916 outline1("CMP #$%2.2x", (unsigned char)( _destination & 0xff ) );
3917 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3918 outline1("SBC #$%2.2x", (unsigned char)( ( _destination >> 8 ) & 0xff ) );
3919 outline1("LDA %s", address_displacement(_environment, _source, "2"));
3920 outline1("SBC #$%2.2x", (unsigned char)( ( _destination >> 16 ) & 0xff ) );
3921 outline1("LDA %s", address_displacement(_environment, _source, "3"));
3922 outline1("SBC #$%2.2x", (unsigned char)( ( _destination >> 24 ) & 0xff ) );
3923 outline1("BVC %sv0", label );
3924 outline0("EOR #$80" );
3925 outhead1("%sv0:", label );
3926 outline1("BMI %smi", label );
3927 outhead1("%spl:", label );
3928 outline0("LDA #$00" );
3929 outline1("STA %s", _other);
3930 outline1("JMP %sen", label );
3931 outhead1("%smi:", label );
3932 outline0("LDA #$ff" );
3933 outline1("STA %s", _other);
3934 outhead1("%sen:", label);
3935
3936 if ( _equal ) {
3937
3938 outhead1("%sdone:", label );
3939
3940 }
3941
3942 } else {
3943 outline1("LDA %s", address_displacement(_environment, _source, "3"));
3944 outline1("CMP #$%2.2x", (unsigned char)( ( _destination >> 24 ) & 0xff ) );
3945 outline1("BEQ %s_1a", label);
3946 outline1("BCC %s", label);
3947 outline1("BCS %s_0", label);
3948 outhead1("%s_1a:", label);
3949 outline1("LDA %s", address_displacement(_environment, _source, "2"));
3950 outline1("CMP #$%2.2x", (unsigned char)( ( _destination >> 16 ) & 0xff ) );
3951 outline1("BEQ %s_1", label);
3952 outline1("BCC %s", label);
3953 outline1("BCS %s_0", label);
3954 outhead1("%s_1:", label);
3955 outline1("LDA %s", address_displacement(_environment, _source, "1"));
3956 outline1("CMP #$%2.2x", (unsigned char)( ( _destination >> 8 ) & 0xff ) );
3957 outline1("BEQ %s_1b", label);
3958 outline1("BCC %s", label);
3959 outline1("BCS %s_0", label);
3960 outhead1("%s_1b:", label);
3961 outline1("LDA %s", _source);
3962 outline1("CMP #$%2.2x", (unsigned char)( _destination & 0xff ) );
3963 if ( _equal ) {
3964 outline1("BEQ %s", label);
3965 }
3966 outline1("BCC %s", label);
3967 outline1("BCS %s_0", label);
3968 outhead1("%s_0:", label);
3969 outline0("LDA #0" );
3970 outline1("STA %s", _other);
3971 outline1("JMP %s_2", label);
3972 outhead1("%s:", label);
3973 outline0("LDA #$FF" );
3974 outline1("STA %s", _other);
3975 outhead1("%s_2:", label);
3976 }
3977
3979
3980}
3981
3982void cpu_less_than_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _bits ) {
3983
3985
3986 inline( cpu_less_than_nbit )
3987
3988 if ( _equal ) {
3989
3990 cpu_compare_nbit( _environment, _source, _destination, _other, 1, _bits );
3991
3992 if ( _other ) {
3993 outline1("LDA %s", _other);
3994 } else {
3995 outline1("LDA %s", _destination);
3996 }
3997
3998 outline1("BEQ %sless", label );
3999 outline1("JMP %sdone", label );
4000 outhead1("%sless:", label );
4001
4002 }
4003
4004 outline1("LDA %s", _source);
4005 outline1("CMP %s", _destination);
4006 for(int i=1; i<(_bits>>3); ++i ) {
4007 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
4008 outline1("LDA %s", address_displacement(_environment, _source, offset ) );
4009 outline1("SBC %s", address_displacement(_environment, _destination, offset ) );
4010 }
4011 outline1("BVC %sv0", label );
4012 outline0("EOR #$80" );
4013 outhead1("%sv0:", label );
4014 outline1("BMI %smi", label );
4015 outhead1("%spl:", label );
4016 outline0("LDA #$00" );
4017 if ( _other ) {
4018 outline1("STA %s", _other);
4019 } else {
4020 outline1("STA %s", _destination);
4021 }
4022 outline1("JMP %sen", label );
4023 outhead1("%smi:", label );
4024 outline0("LDA #$FF" );
4025 if ( _other ) {
4026 outline1("STA %s", _other);
4027 } else {
4028 outline1("STA %s", _destination);
4029 }
4030 outhead1("%sen:", label);
4031
4032 if ( _equal ) {
4033
4034 outhead1("%sdone:", label );
4035
4036 }
4037
4039
4040}
4041
4042void cpu_less_than_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _bits ) {
4043
4045
4046 int i;
4047
4048 inline( cpu_less_than_nbit_const )
4049
4050 if ( _equal ) {
4051
4052 cpu_compare_nbit_const( _environment, _source, _destination, _other, 1, _bits );
4053
4054 if ( _other ) {
4055 outline1("LDA %s", _other);
4056 } else {
4057 outline1("LDA %s", _destination);
4058 }
4059
4060 outline1("BEQ %sless", label );
4061 outline1("JMP %sdone", label );
4062 outhead1("%sless:", label );
4063
4064 }
4065
4066 for( i=0; i<(_bits>>3); ++i ) {
4067 char offset[MAX_TEMPORARY_STORAGE]; sprintf(offset, "%d", i );
4068 outline1("LDA %s", address_displacement(_environment, _source, offset ) );
4069 outline1("CMP #$%2.2x", (unsigned char)( ( _destination >> (i*8) ) & 0xff ) );
4070 }
4071 outline1("BVC %sv0", label );
4072 outline0("EOR #$80" );
4073 outhead1("%sv0:", label );
4074 outline1("BMI %smi", label );
4075 outhead1("%spl:", label );
4076 outline0("LDA #$00" );
4077 outline1("STA %s", _other);
4078 outline1("JMP %sen", label );
4079 outhead1("%smi:", label );
4080 outline0("LDA #$ff" );
4081 outline1("STA %s", _other);
4082 outhead1("%sen:", label);
4083
4084 if ( _equal ) {
4085
4086 outhead1("%sdone:", label );
4087
4088 }
4089
4091
4092}
4093
4103void cpu_greater_than_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
4104
4105 inline( cpu_greater_than_32bit )
4106
4107 cpu_less_than_32bit( _environment, _source, _destination, _other, !_equal, _signed );
4108 if ( _other ) {
4109 cpu_not_8bit( _environment, _other, _other );
4110 } else {
4111 cpu_not_8bit( _environment, _destination, _destination );
4112 }
4113
4115
4116}
4117
4118void cpu_greater_than_32bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
4119
4120 inline( cpu_greater_than_32bit )
4121
4122 cpu_less_than_32bit_const( _environment, _source, _destination, _other, !_equal, _signed );
4123 cpu_not_8bit( _environment, _other, _other );
4124
4126
4127}
4128
4129void cpu_greater_than_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _bits ) {
4130
4131 inline( cpu_greater_than_nbit )
4132
4133 cpu_less_than_nbit( _environment, _source, _destination, _other, !_equal, _bits );
4134 if ( _other ) {
4135 cpu_not_8bit( _environment, _other, _other );
4136 } else {
4137 cpu_not_8bit( _environment, _destination, _destination );
4138 }
4139
4141
4142}
4143
4144void cpu_greater_than_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _bits ) {
4145
4146 inline( cpu_greater_than_nbit )
4147
4148 cpu_less_than_nbit_const( _environment, _source, _destination, _other, !_equal, _bits );
4149 cpu_not_8bit( _environment, _other, _other );
4150
4152
4153}
4154
4163void cpu_math_add_32bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
4164
4165 inline( cpu_math_add_32bit )
4166
4167 outline0("CLC");
4168 outline1("LDA %s", _source);
4169 outline1("ADC %s", _destination);
4170 if ( _other ) {
4171 outline1("STA %s", _other);
4172 } else {
4173 outline1("STA %s", _destination);
4174 }
4175 outline1("LDA %s", address_displacement(_environment, _source, "1"));
4176 outline1("ADC %s", address_displacement(_environment, _destination, "1"));
4177 if ( _other ) {
4178 outline1("STA %s", address_displacement(_environment, _other, "1"));
4179 } else {
4180 outline1("STA %s", address_displacement(_environment, _destination, "1"));
4181 }
4182 outline1("LDA %s", address_displacement(_environment, _source, "2"));
4183 outline1("ADC %s", address_displacement(_environment, _destination, "2"));
4184 if ( _other ) {
4185 outline1("STA %s", address_displacement(_environment, _other, "2"));
4186 } else {
4187 outline1("STA %s", address_displacement(_environment, _destination, "2"));
4188 }
4189 outline1("LDA %s", address_displacement(_environment, _source, "3"));
4190 outline1("ADC %s", address_displacement(_environment, _destination, "3"));
4191 if ( _other ) {
4192 outline1("STA %s", address_displacement(_environment, _other, "3"));
4193 } else {
4194 outline1("STA %s", address_displacement(_environment, _destination, "3"));
4195 }
4196
4198
4199}
4200
4201void cpu_math_add_32bit_const( Environment * _environment, char *_source, int _destination, char *_other ) {
4202
4203 inline( cpu_math_add_32bit_const )
4204
4205 outline0("CLC");
4206 outline1("LDA %s", _source);
4207 outline1("ADC #$%2.2x", ( _destination & 0xff ) );
4208 outline1("STA %s", _other);
4209 outline1("LDA %s", address_displacement(_environment, _source, "1"));
4210 outline1("ADC #$%2.2x", ( ( _destination >> 8 ) & 0xff ) );
4211 outline1("STA %s", address_displacement(_environment, _other, "1"));
4212 outline1("LDA %s", address_displacement(_environment, _source, "2"));
4213 outline1("ADC #$%2.2x", ( ( _destination >> 16 ) & 0xff ) );
4214 outline1("STA %s", address_displacement(_environment, _other, "2"));
4215 outline1("LDA %s", address_displacement(_environment, _source, "3"));
4216 outline1("ADC #$%2.2x", ( ( _destination >> 24 ) & 0xff ) );
4217 outline1("STA %s", address_displacement(_environment, _other, "3"));
4218
4220
4221}
4222
4223void cpu_math_add_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _bits ) {
4224
4225 inline( cpu_math_add_nbit )
4226
4227 outline0("CLC");
4228 for( int i=0; i<(_bits>>3); ++i ) {
4229 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
4230 outline1("LDA %s", address_displacement(_environment, _source, offset));
4231 outline1("ADC %s", address_displacement(_environment, _destination, offset));
4232 if ( _other ) {
4233 outline1("STA %s", address_displacement(_environment, _other, offset));
4234 } else {
4235 outline1("STA %s", address_displacement(_environment, _destination, offset));
4236 }
4237 }
4239
4240}
4241
4242void cpu_math_add_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, int _bits ) {
4243
4244 int i;
4245
4246 inline( cpu_math_add_32bit_const )
4247
4248 outline0("CLC");
4249 for( i=0; i<(_bits>>3); ++i ) {
4250 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
4251 outline1("LDA %s", address_displacement(_environment, _source, offset));
4252 outline1("ADC #$%2.2x", (unsigned char)( ( _destination >> (i*8) ) & 0xff ) );
4253 outline1("STA %s", address_displacement(_environment, _other, offset));
4254 }
4255
4257
4258}
4259
4267void cpu_math_double_32bit( Environment * _environment, char *_source, char *_other, int _signed ) {
4268
4269 inline( cpu_math_double_32bit )
4270
4271 outline1("LDA %s", _source);
4272 outline0("ASL A");
4273 if ( _other ) {
4274 outline1("STA %s", _source);
4275 } else {
4276 outline1("STA %s", _source);
4277 }
4278 outline1("LDA %s", address_displacement(_environment, _source, "1"));
4279 outline0("ROL A");
4280 if ( _other ) {
4281 outline1("STA %s", address_displacement(_environment, _source, "1"));
4282 } else {
4283 outline1("STA %s", address_displacement(_environment, _source, "1"));
4284 }
4285 outline1("LDA %s", address_displacement(_environment, _source, "2"));
4286 outline0("ROL A");
4287 if ( _other ) {
4288 outline1("STA %s", address_displacement(_environment, _source, "2"));
4289 } else {
4290 outline1("STA %s", address_displacement(_environment, _source, "2"));
4291 }
4292 outline1("LDA %s", address_displacement(_environment, _source, "3"));
4293 outline0("ROL A");
4294 if ( _other ) {
4295 outline1("STA %s", address_displacement(_environment, _source, "3"));
4296 } else {
4297 outline1("STA %s", address_displacement(_environment, _source, "3"));
4298 }
4299
4301
4302}
4303
4312void cpu_math_sub_32bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
4313
4314 inline( cpu_math_sub_32bit )
4315
4316 outline0("SEC");
4317 outline1("LDA %s", _source);
4318 outline1("SBC %s", _destination);
4319 if ( _other ) {
4320 outline1("STA %s", _other);
4321 } else {
4322 outline1("STA %s", _destination);
4323 }
4324 outline1("LDA %s", address_displacement(_environment, _source, "1"));
4325 outline1("SBC %s", address_displacement(_environment, _destination, "1"));
4326 if ( _other ) {
4327 outline1("STA %s", address_displacement(_environment, _other, "1"));
4328 } else {
4329 outline1("STA %s", address_displacement(_environment, _destination, "1"));
4330 }
4331 outline1("LDA %s", address_displacement(_environment, _source, "2"));
4332 outline1("SBC %s", address_displacement(_environment, _destination, "2"));
4333 if ( _other ) {
4334 outline1("STA %s", address_displacement(_environment, _other, "2"));
4335 } else {
4336 outline1("STA %s", address_displacement(_environment, _destination, "2"));
4337 }
4338 outline1("LDA %s", address_displacement(_environment, _source, "3"));
4339 outline1("SBC %s", address_displacement(_environment, _destination, "3"));
4340 if ( _other ) {
4341 outline1("STA %s", address_displacement(_environment, _other, "3"));
4342 } else {
4343 outline1("STA %s", address_displacement(_environment, _destination, "3"));
4344 }
4345
4347
4348}
4349
4350void cpu_math_sub_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _bits ) {
4351
4352 inline( cpu_math_sub_nbit )
4353
4354 outline0("SEC");
4355 for( int i=0; i<(_bits)>>3; ++i ) {
4356 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
4357 outline1("LDA %s", address_displacement(_environment, _source, offset));
4358 outline1("SBC %s", address_displacement(_environment, _destination, offset));
4359 if ( _other ) {
4360 outline1("STA %s", address_displacement(_environment, _other, offset));
4361 } else {
4362 outline1("STA %s", address_displacement(_environment, _destination, offset));
4363 }
4364 }
4365
4367
4368}
4369
4377void cpu_math_complement_const_32bit( Environment * _environment, char *_source, int _value ) {
4378
4380
4381 outline0("SEC");
4382 outline1("LDA #$%2.2x", ( _value & 0xff ) );
4383 outline1("SBC %s", _source);
4384 outline1("STA %s", _source );
4385 outline1("LDA #$%2.2x", ( ( _value >> 8 ) & 0xff ) );
4386 outline1("SBC %s", address_displacement(_environment, _source, "1"));
4387 outline1("STA %s", address_displacement(_environment, _source, "1") );
4388 outline1("LDA #$%2.2x", ( ( _value >> 16 ) & 0xff ) );
4389 outline1("SBC %s", address_displacement(_environment, _source, "2"));
4390 outline1("STA %s", address_displacement(_environment, _source, "2") );
4391 outline1("LDA #$%2.2x", ( ( _value >> 24 ) & 0xff ) );
4392 outline1("SBC %s", address_displacement(_environment, _source, "3"));
4393 outline1("STA %s", address_displacement(_environment, _source, "3") );
4394
4396
4397}
4398
4406void cpu_math_div2_const_32bit( Environment * _environment, char *_source, int _steps, int _signed, char * _remainder ) {
4407
4409
4411
4412 if ( _signed ) {
4413 if ( _remainder ) {
4414 outline1("LDA %s", _source);
4415 outline0("AND #$01" );
4416 outline1("STA %s", _remainder);
4417 }
4418 outline1("LDA %s", address_displacement(_environment, _source, "3"));
4419 outline0("AND #$80");
4420 outline0("TAX");
4421 outline1("BEQ %snocomplement", label );
4422 cpu_complement2_32bit( _environment, _source, _source );
4423 outhead1("%snocomplement:", label );
4424 while( _steps ) {
4425 outline0("CLC");
4426 outline1("LSR %s", address_displacement(_environment, _source, "3"));
4427 outline1("ROR %s", address_displacement(_environment, _source, "2"));
4428 outline1("ROR %s", address_displacement(_environment, _source, "1"));
4429 outline1("ROR %s", _source);
4430 --_steps;
4431 }
4432 outline0("TXA");
4433 outline1("BEQ %snocomplement2", label );
4434 cpu_complement2_32bit( _environment, _source, _source );
4435 outhead1("%snocomplement2:", label );
4436 } else {
4437 if ( _remainder ) {
4438 outline1("LDA %s", _source);
4439 outline0("AND #$01" );
4440 outline1("STA %s", _remainder);
4441 }
4442 while( _steps ) {
4443 outline0("CLC");
4444 outline1("LSR %s", address_displacement(_environment, _source, "3"));
4445 outline1("ROR %s", address_displacement(_environment, _source, "2"));
4446 outline1("ROR %s", address_displacement(_environment, _source, "1"));
4447 outline1("ROR %s", _source);
4448 --_steps;
4449 }
4450 }
4451
4453
4454}
4455
4456void cpu_math_div2_const_nbit( Environment * _environment, char *_source, int _steps, int _bits, char * _remainder ) {
4457
4458 inline( cpu_math_div2_const_nbit )
4459
4461
4462 if ( _remainder ) {
4463 outline1("LDA %s", _source);
4464 outline0("AND #$01" );
4465 outline1("STA %s", _remainder);
4466 }
4467 char offsetMsb[MAX_TEMPORARY_STORAGE]; sprintf( offsetMsb, "%d", (_bits>>3)-1 );
4468
4469 outline1("LDA %s", address_displacement(_environment, _source, offsetMsb));
4470 outline0("AND #$80");
4471 outline0("TAX");
4472 outline1("BNE %snocomplementx", label );
4473 outline1("JMP %snocomplement", label );
4474 outhead1("%snocomplementx:", label );
4475 cpu_complement2_nbit( _environment, _source, _source, _bits );
4476 outhead1("%snocomplement:", label );
4477 while( _steps ) {
4478 outline0("CLC");
4479 outline1("LSR %s", address_displacement(_environment, _source, offsetMsb));
4480 for( int i=(_bits>>3)-2; i>-1; --i ) {
4481 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
4482 outline1("ROR %s", address_displacement(_environment, _source, offset));
4483 }
4484 --_steps;
4485 }
4486 outline0("TXA");
4487 outline1("BNE %snocomplement2x", label );
4488 outline1("JMP %snocomplement2", label );
4489 outhead1("%snocomplement2x:", label );
4490 cpu_complement2_nbit( _environment, _source, _source, _bits );
4491 outhead1("%snocomplement2:", label );
4492
4494
4495}
4496
4504void cpu_math_mul2_const_32bit( Environment * _environment, char *_source, int _steps, int _signed ) {
4505
4507
4508 if ( _signed ) {
4509 outline1("LDA %s", address_displacement(_environment, _source, "3"));
4510 outline0("AND #$80");
4511 outline0("TAX");
4512 while( _steps ) {
4513 outline0("CLC");
4514 outline1("ASL %s", _source);
4515 outline1("ROL %s", address_displacement(_environment, _source, "1"));
4516 outline1("ROL %s", address_displacement(_environment, _source, "2"));
4517 outline1("ROL %s", address_displacement(_environment, _source, "3"));
4518 --_steps;
4519 }
4520 outline0("TXA");
4521 outline1("ORA %s", address_displacement(_environment, _source, "3"));
4522 outline1("STA %s", address_displacement(_environment, _source, "3"));
4523 } else {
4524 while( _steps ) {
4525 outline0("CLC");
4526 outline1("ASL %s", _source);
4527 outline1("ROL %s", address_displacement(_environment, _source, "1"));
4528 outline1("ROL %s", address_displacement(_environment, _source, "2"));
4529 outline1("ROL %s", address_displacement(_environment, _source, "3"));
4530 --_steps;
4531 }
4532 }
4533
4535
4536}
4537
4538void cpu_math_mul2_const_nbit( Environment * _environment, char *_source, int _steps, int _bits ) {
4539
4540 int i;
4541
4542 inline( cpu_math_mul2_const_nbit )
4543
4544 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", (_bits>>3)-1 );
4545 outline1("LDA %s", address_displacement(_environment, _source, offset));
4546 outline0("AND #$80");
4547 outline0("TAX");
4548 while( _steps ) {
4549 outline0("CLC");
4550 outline1("ASL %s", _source);
4551 for( i=1; i<(_bits>>3); ++i ) {
4552 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i);
4553 outline1("ROL %s", address_displacement(_environment, _source, offset));
4554 }
4555 --_steps;
4556 }
4557 outline0("TXA");
4558 outline1("ORA %s", address_displacement(_environment, _source, offset));
4559 outline1("STA %s", address_displacement(_environment, _source, offset));
4560
4562
4563}
4564
4572void cpu_math_and_const_32bit( Environment * _environment, char *_source, int _mask ) {
4573
4574 inline( cpu_math_and_const_32bit )
4575
4576 outline1("LDA %s", _source);
4577 outline1("AND #$%2.2x", (_mask & 0xff ) );
4578 outline1("STA %s", _source);
4579 outline1("LDA %s", address_displacement(_environment, _source, "1"));
4580 outline1("AND #$%2.2x", ((_mask>>8) & 0xff ));
4581 outline1("STA %s", address_displacement(_environment, _source, "1"));
4582 outline1("LDA %s", address_displacement(_environment, _source, "2"));
4583 outline1("AND #$%2.2x", ((_mask>>16) & 0xff ) );
4584 outline1("STA %s", address_displacement(_environment, _source, "2"));
4585 outline1("LDA %s", address_displacement(_environment, _source, "3"));
4586 outline1("AND #$%2.2x", ((_mask>>24) & 0xff ));
4587 outline1("STA %s", address_displacement(_environment, _source, "3"));
4588
4590
4591}
4592
4593void cpu_combine_nibbles( Environment * _environment, char * _low_nibble, char * _hi_nibble, char * _byte ) {
4594
4595 inline( cpu_combine_nibbles )
4596
4597 outline1("LDA %s", _hi_nibble);
4598 outline0("ASL");
4599 outline0("ASL");
4600 outline0("ASL");
4601 outline0("ASL");
4602 outline1("ORA %s", _low_nibble);
4603 outline1("STA %s", _byte);
4604
4606
4607}
4608
4617void cpu_move_nbit( Environment * _environment, int _n, char * _source, char *_destination ) {
4618
4619 int i = 0;
4620 while( _n ) {
4621 char sourceAddress[MAX_TEMPORARY_STORAGE]; sprintf( sourceAddress, "%s+%d", _source, i*4 );
4622 char destinationAddress[MAX_TEMPORARY_STORAGE]; sprintf( destinationAddress, "%s+%d", _destination, i*4 );
4623 if ( _n <= 32 ) {
4624 switch( _n ) {
4625 case 1: case 2: case 3: case 4:
4626 case 5: case 6: case 7: case 8:
4627 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4628 break;
4629 case 9: case 10: case 11: case 12:
4630 case 13: case 14: case 15: case 16:
4631 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4632 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
4633 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
4634 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4635 break;
4636 case 17: case 18: case 19: case 20:
4637 case 21: case 22: case 23: case 24:
4638 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4639 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
4640 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
4641 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4642 sprintf( sourceAddress, "%s+%d", _source, i*4+2 );
4643 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
4644 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4645 break;
4646 case 25: case 26: case 27: case 28:
4647 case 29: case 30: case 31: case 32:
4648 default:
4649 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4650 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
4651 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
4652 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4653 sprintf( sourceAddress, "%s+%d", _source, i*4+2 );
4654 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
4655 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4656 sprintf( sourceAddress, "%s+%d", _source, i*4+3 );
4657 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
4658 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4659 break;
4660 }
4661 _n = 0;
4662 } else {
4663 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4664 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
4665 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
4666 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4667 sprintf( sourceAddress, "%s+%d", _source, i*4+2 );
4668 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
4669 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4670 sprintf( sourceAddress, "%s+%d", _source, i*4+3 );
4671 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
4672 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
4673 _n -= 32;
4674 }
4675 ++i;
4676 }
4677
4678}
4679
4680
4681void cpu_jump( Environment * _environment, char * _label ) {
4682
4683 inline( cpu_jump )
4684
4685 outline1("JMP %s", _label );
4686
4688
4689}
4690
4691void cpu_call_addr( Environment * _environment, int _address ) {
4692
4693 outline1("JSR $%4.4x", _address );
4694
4695}
4696
4697void cpu_call( Environment * _environment, char * _label ) {
4698
4699 inline( cpu_call )
4700
4701 outline1("JSR %s", _label );
4702
4704
4705}
4706
4707void cpu_call_indirect( Environment * _environment, char * _value ) {
4708
4709
4710 inline( cpu_call_indirect )
4711
4713
4714 char indirectLabel[MAX_TEMPORARY_STORAGE]; sprintf( indirectLabel, "%sindirect", label );
4715
4716 cpu_jump( _environment, label );
4717 cpu_label( _environment, indirectLabel );
4718 // We must use self-modifying code in order to avoid
4719 // a 6502/6510 bug when using indirect addressing.
4720 outline0( "JMP $0000" );
4721 cpu_label( _environment, label );
4722 outline0( "PHA" );
4723 outline1( "LDA %s", _value );
4724 outline1( "STA %s", address_displacement( _environment, indirectLabel, "1" ) );
4725 outline1( "LDA %s", address_displacement( _environment, _value, "1" ) );
4726 outline1( "STA %s", address_displacement( _environment, indirectLabel, "2" ) );
4727 outline0( "PLA" );
4728 cpu_call( _environment, indirectLabel );
4729
4731
4732}
4733
4734void cpu_jump_indirect( Environment * _environment, char * _value ) {
4735
4736
4737 inline( cpu_jump_indirect )
4738
4740
4741 char indirectLabel[MAX_TEMPORARY_STORAGE]; sprintf( indirectLabel, "%sindirect", label );
4742
4743 cpu_jump( _environment, label );
4744 cpu_label( _environment, indirectLabel );
4745 // We must use self-modifying code in order to avoid
4746 // a 6502/6510 bug when using indirect addressing.
4747 outline0( "JMP $0000" );
4748 cpu_label( _environment, label );
4749 outline0( "PHA" );
4750 outline1( "LDA %s", _value );
4751 outline1( "STA %s", address_displacement( _environment, indirectLabel, "1" ) );
4752 outline1( "LDA %s", address_displacement( _environment, _value, "1" ) );
4753 outline1( "STA %s", address_displacement( _environment, indirectLabel, "2" ) );
4754 outline0( "PLA" );
4755 cpu_jump( _environment, indirectLabel );
4756
4758
4759}
4760
4761int cpu_register_decode( Environment * _environment, char * _register ) {
4762
4764
4765 if ( !_environment->emptyProcedure ) {
4766
4767 if ( strcmp( _register, "PC" ) == 0 ) {
4768 if ( !_environment->emptyProcedure ) {
4770 }
4771 result = REGISTER_PC;
4772 } else if ( strcmp( _register, "S" ) == 0 ) {
4773 if ( !_environment->emptyProcedure ) {
4775 }
4776 result = REGISTER_S;
4777 } else if ( strcmp( _register, "A" ) == 0 ) {
4778 result = REGISTER_A;
4779 } else if ( strcmp( _register, "X" ) == 0 ) {
4780 result = REGISTER_X;
4781 } else if ( strcmp( _register, "Y" ) == 0 ) {
4782 result = REGISTER_Y;
4783 } else if ( strcmp( _register, "XY" ) == 0 ) {
4784 result = REGISTER_XY;
4785 } else if ( strcmp( _register, "YX" ) == 0 ) {
4786 result = REGISTER_XY;
4787 } else if ( strcmp( _register, "CARRY" ) == 0 ) {
4788 result = REGISTER_CARRY;
4789 } else {
4790 int i, c;
4791 char * comma = strchr( _register, ',' );
4792 if ( !comma ) {
4793 for( i=0, c=strlen(_register); i<c; ++i ) {
4794 if ( !isdigit( _register[i] ) )
4795 break;
4796 }
4797 if ( i >= c ) {
4798 return (int)REGISTER_PAGE_ZERO | ( atoi( _register ) & 0xff );
4799 }
4800 } else {
4801 *comma = 0;
4802 for( i=0, c=strlen(_register); i<c; ++i ) {
4803 if ( !isdigit( _register[i] ) )
4804 break;
4805 }
4806 if ( i >= c ) {
4807 return (int)REGISTER_PAGE_ZERO2 | ( atoi( _register ) & 0xff );
4808 }
4809 }
4810 }
4811
4812 }
4813
4814 return (int)result;
4815
4816}
4817
4818void cpu_set_asmio( Environment * _environment, int _asmio, int _value ) {
4819
4820 if ( IS_REGISTER( _asmio ) ) {
4821
4822 CPU6502Register reg = (CPU6502Register) _asmio;
4823
4824 switch ( reg ) {
4825 case REGISTER_NONE:
4827 break;
4828 case REGISTER_PC:
4829 case REGISTER_S:
4830 break;
4831 case REGISTER_A:
4832 outline1( "LDA #$%2.2x", (unsigned char)(_value & 0xff ) );
4833 break;
4834 case REGISTER_X:
4835 outline1( "LDX #$%2.2x", (unsigned char)(_value & 0xff ) );
4836 break;
4837 case REGISTER_Y:
4838 outline1( "LDY #$%2.2x", (unsigned char)(_value & 0xff ) );
4839 break;
4840 case REGISTER_XY:
4841 outline1( "LDY #$%2.2x", (unsigned char)(_value & 0xff ) );
4842 outline1( "LDX #$%2.2x", (unsigned char)((_value>>8) & 0xff ) );
4843 break;
4844 case REGISTER_YX:
4845 outline1( "LDX #$%2.2x", (unsigned char)(_value & 0xff ) );
4846 outline1( "LDY #$%2.2x", (unsigned char)((_value>>8) & 0xff ) );
4847 break;
4848 case REGISTER_AXY:
4849 outline1( "LDY #$%2.2x", (unsigned char)(_value & 0xff ) );
4850 outline1( "LDX #$%2.2x", (unsigned char)((_value>>8) & 0xff ) );
4851 outline1( "LDA #$%2.2x", (unsigned char)((_value>>16) & 0xff ) );
4852 break;
4853 case REGISTER_CARRY:
4854 if ( _value ) {
4855 outline0( "SEC" );
4856 } else {
4857 outline0( "CLC" );
4858 }
4859 break;
4860 case REGISTER_ZERO:
4861 if ( _value ) {
4862 outline0( "LDA #1" );
4863 } else {
4864 outline0( "LDA #0" );
4865 }
4866 break;
4867 }
4868
4869 } else if ( IS_PAGE_ZERO( _asmio ) ) {
4870
4871 outline1( "LDA #$%2.2x", (unsigned char)(_value & 0xff ) );
4872 outline1( "STA #$%2.2x", (unsigned char)(_asmio & 0xff ) );
4873
4874 } else if ( IS_PAGE_ZERO2( _asmio ) ) {
4875
4876 outline1( "LDA #$%2.2x", (unsigned char)(_value & 0xff ) );
4877 outline1( "STA #$%2.2x", (unsigned char)(_asmio & 0xff ) );
4878 outline1( "LDA #$%2.2x", (unsigned char)((_value>>8) & 0xff ) );
4879 outline1( "STA #$%2.2x", (unsigned char)((_asmio+1) & 0xff ) );
4880
4881 } else {
4882
4883 CPU6502Stack stk = (CPU6502Stack) _asmio;
4884
4885 switch ( stk ) {
4886 case STACK_NONE:
4887 break;
4888 case STACK_BYTE:
4889 outline1( "LDA #$%2.2x", (unsigned char)(_value & 0xff ) );
4890 outline0( "PHA" );
4891 break;
4892 case STACK_WORD:
4893 outline1( "LDA #$%2.2x", (unsigned char)(_value & 0xff ) );
4894 outline0( "PHA" );
4895 outline1( "LDA #$%2.2x", (unsigned char)(( _value >> 8 ) & 0xff ) );
4896 outline0( "PHA" );
4897 break;
4898 case STACK_DWORD:
4899 outline1( "LDA #$%2.2x", (unsigned char)(_value & 0xff ) );
4900 outline0( "PHA" );
4901 outline1( "LDA #$%2.2x", (unsigned char)(( _value >> 8 ) & 0xff ) );
4902 outline0( "PHA" );
4903 outline1( "LDA #$%2.2x", (unsigned char)(( _value >> 16 ) & 0xff ) );
4904 outline0( "PHA" );
4905 outline1( "LDA #$%2.2x", (unsigned char)(( _value >> 24 ) & 0xff ) );
4906 outline0( "PHA" );
4907 break;
4908 }
4909
4910 }
4911
4912}
4913
4914void cpu_set_asmio_indirect( Environment * _environment, int _asmio, char * _value ) {
4915
4916 if ( IS_REGISTER( _asmio ) ) {
4917
4919
4920 CPU6502Register reg = (CPU6502Register) _asmio;
4921
4922 switch ( reg ) {
4923 case REGISTER_NONE:
4925 break;
4926 case REGISTER_PC:
4927 case REGISTER_S:
4928 break;
4929 case REGISTER_A:
4930 outline1( "LDA %s", _value );
4931 break;
4932 case REGISTER_X:
4933 outline1( "LDX %s", _value );
4934 break;
4935 case REGISTER_Y:
4936 outline1( "LDY %s", _value );
4937 break;
4938 case REGISTER_XY:
4939 outline1( "LDY %s", _value );
4940 outline1( "LDX %s", address_displacement( _environment, _value, "1" ) );
4941 break;
4942 case REGISTER_YX:
4943 outline1( "LDX %s", _value );
4944 outline1( "LDY %s", address_displacement( _environment, _value, "1" ) );
4945 break;
4946 case REGISTER_AXY:
4947 outline1( "LDY %s", _value );
4948 outline1( "LDX %s", address_displacement( _environment, _value, "1" ) );
4949 outline1( "LDA %s", address_displacement( _environment, _value, "2" ) );
4950 break;
4951 case REGISTER_CARRY:
4952 outline0( "PHA");
4953 outline1( "LDA %s", _value );
4954 outline1( "BEQ %szero", label );
4955 outline0( "SEC" );
4956 outline1( "JMP %sdone", label );
4957 outhead1( "%szero:", label );
4958 outline0( "CLC" );
4959 outhead1( "%sdone:", label );
4960 outline0( "PLA");
4961 break;
4962 case REGISTER_ZERO:
4963 outline1( "LDA %s", _value );
4964 break;
4965 }
4966
4967 } else if ( IS_PAGE_ZERO( _asmio ) ) {
4968
4969 outline1( "LDA %s", _value );
4970 outline1( "STA #$%2.2x", (unsigned char)(_asmio & 0xff ) );
4971
4972 } else if ( IS_PAGE_ZERO2( _asmio ) ) {
4973
4974 outline1( "LDA %s", _value );
4975 outline1( "STA #$%2.2x", (unsigned char)(_asmio & 0xff ) );
4976 outline1( "LDA %s", address_displacement( _environment, _value, "1" ) );
4977 outline1( "STA #$%2.2x", (unsigned char)((_asmio+1) & 0xff ) );
4978
4979 } else {
4980
4981 CPU6502Stack stk = (CPU6502Stack) _asmio;
4982
4983 switch ( stk ) {
4984 case STACK_NONE:
4985 break;
4986 case STACK_BYTE:
4987 outline1( "LDA %s", address_displacement(_environment, _value, "0") );
4988 outline0( "PHA" );
4989 break;
4990 case STACK_WORD:
4991 outline1( "LDA %s", address_displacement(_environment, _value, "0") );
4992 outline0( "PHA" );
4993 outline1( "LDA %s", address_displacement(_environment, _value, "1") );
4994 outline0( "PHA" );
4995 break;
4996 case STACK_DWORD:
4997 outline1( "LDA %s", address_displacement(_environment, _value, "0") );
4998 outline0( "PHA" );
4999 outline1( "LDA %s", address_displacement(_environment, _value, "1") );
5000 outline0( "PHA" );
5001 outline1( "LDA %s", address_displacement(_environment, _value, "2") );
5002 outline0( "PHA" );
5003 outline1( "LDA %s", address_displacement(_environment, _value, "3") );
5004 outline0( "PHA" );
5005 break;
5006 }
5007
5008 }
5009
5010}
5011
5012void cpu_get_asmio_indirect( Environment * _environment, int _asmio, char * _value ) {
5013
5014 if ( IS_REGISTER( _asmio ) ) {
5015
5017
5018 CPU6502Register reg = (CPU6502Register) _asmio;
5019
5020 switch ( reg ) {
5021 case REGISTER_NONE:
5023 break;
5024 case REGISTER_PC:
5025 case REGISTER_S:
5026 break;
5027 case REGISTER_A:
5028 outline1( "STA %s", _value );
5029 break;
5030 case REGISTER_X:
5031 outline1( "STX %s", _value );
5032 break;
5033 case REGISTER_Y:
5034 outline1( "STY %s", _value );
5035 break;
5036 case REGISTER_XY:
5037 outline1( "STY %s", _value );
5038 outline1( "STX %s", address_displacement( _environment, _value, "1" ) );
5039 break;
5040 case REGISTER_YX:
5041 outline1( "STX %s", _value );
5042 outline1( "STY %s", address_displacement( _environment, _value, "1" ) );
5043 break;
5044 case REGISTER_AXY:
5045 outline1( "STY %s", _value );
5046 outline1( "STX %s", address_displacement( _environment, _value, "1" ) );
5047 outline1( "STA %s", address_displacement( _environment, _value, "2" ) );
5048 break;
5049 case REGISTER_CARRY:
5050 outline0( "PHA" );
5051 outline1( "BCS %sset", label );
5052 outline0( "LDA #$0" );
5053 outline1( "STA %s", _value );
5054 outline1( "JMP %sdone", label );
5055 outhead1( "%sset:", label );
5056 outhead1( "%sdone:", label );
5057 outline0( "LDA #$1" );
5058 outline1( "STA %s", _value );
5059 outline0( "PLA" );
5060 break;
5061 case REGISTER_ZERO:
5062 outline0( "PHA" );
5063 outline1( "BEQ %sset", label );
5064 outline0( "LDA #$0" );
5065 outline1( "STA %s", _value );
5066 outline1( "JMP %sdone", label );
5067 outhead1( "%sset:", label );
5068 outhead1( "%sdone:", label );
5069 outline0( "LDA #$1" );
5070 outline1( "STA %s", _value );
5071 outline0( "PLA" );
5072 break;
5073 }
5074
5075 } else if ( IS_PAGE_ZERO( _asmio ) ) {
5076
5077 outline1( "LDA #$%2.2x", (unsigned char)(_asmio & 0xff ) );
5078 outline1( "STA %s", _value );
5079
5080 } else if ( IS_PAGE_ZERO2( _asmio ) ) {
5081
5082 outline1( "LDA #$%2.2x", (unsigned char)(_asmio & 0xff ) );
5083 outline1( "STA %s", _value );
5084 outline1( "LDA #$%2.2x", (unsigned char)((_asmio+1) & 0xff ) );
5085 outline1( "STA %s", address_displacement( _environment, _value, "1" ) );
5086
5087 } else {
5088
5089 CPU6502Stack stk = (CPU6502Stack) _asmio;
5090
5091 switch ( stk ) {
5092 case STACK_NONE:
5093 break;
5094 case STACK_BYTE:
5095 outline0( "PLA" );
5096 outline1( "STA %s", address_displacement(_environment, _value, "0") );
5097 break;
5098 case STACK_WORD:
5099 outline0( "PLA" );
5100 outline1( "STA %s", address_displacement(_environment, _value, "1") );
5101 outline0( "PLA" );
5102 outline1( "STA %s", address_displacement(_environment, _value, "0") );
5103 break;
5104 case STACK_DWORD:
5105 outline0( "PLA" );
5106 outline1( "STA %s", address_displacement(_environment, _value, "3") );
5107 outline0( "PLA" );
5108 outline1( "STA %s", address_displacement(_environment, _value, "2") );
5109 outline0( "PLA" );
5110 outline1( "STA %s", address_displacement(_environment, _value, "1") );
5111 outline0( "PLA" );
5112 outline1( "STA %s", address_displacement(_environment, _value, "0") );
5113 break;
5114 }
5115
5116 }
5117
5118}
5119
5120
5121void cpu_return( Environment * _environment ) {
5122
5123 inline( cpu_return )
5124
5125 outline0("RTS" );
5126
5128
5129}
5130
5131void cpu_pop( Environment * _environment ) {
5132
5133 inline( cpu_pop )
5134
5135 outline0("PLA" );
5136 outline0("PLA" );
5137
5139
5140}
5141
5142void cpu_halt( Environment * _environment ) {
5143
5145
5146 inline( cpu_halt )
5147
5148 outhead1("%s:", label );
5149 outline1("JMP %s", label);
5150
5152
5153}
5154
5155void cpu_end( Environment * _environment ) {
5156
5157 inline( cpu_end )
5158
5159 outline0("SEI");
5160 cpu_halt( _environment );
5161
5163
5164}
5165
5166void cpu_random( Environment * _environment, char * _entropy ) {
5167
5169
5170 inline( cpu_random )
5171
5172 if ( _entropy ) {
5173 outhead1("%s:", label);
5174 outline0("ASL CPURANDOM_SEED");
5175 outline0("ROL CPURANDOM_SEED+1");
5176 outline0("ROL CPURANDOM_SEED+2");
5177 outline0("ROL CPURANDOM_SEED+3");
5178 outline1("BCC %sxx2", label);
5179 outline0("LDA CPURANDOM_SEED");
5180 outline1("EOR %s", _entropy)
5181 outline0("STA CPURANDOM_SEED");
5182 outline0("LDA CPURANDOM_SEED+1");
5183 outline0("EOR #$1D");
5184 outline0("STA CPURANDOM_SEED+1" );
5185 outline0("LDA CPURANDOM_SEED+2" );
5186 outline0("EOR #$C1" );
5187 outline0("STA CPURANDOM_SEED+2" );
5188 outline0("LDA CPURANDOM_SEED+3" );
5189 outline0("EOR #$04" );
5190 outline0("STA CPURANDOM_SEED+3" );
5191 outhead1("%sxx2:", label);
5192 }
5193
5195
5196
5197 done()
5198
5199}
5200
5201void cpu_random_8bit( Environment * _environment, char * _entropy, char * _result ) {
5202
5203 inline( cpu_random_8bit )
5204
5205 cpu_random( _environment, _entropy );
5206
5207 if ( _result ) {
5208 outline1("LDA %s", _entropy );
5209 outline0("ADC CPURANDOM_SEED" );
5210 outline0("STA CPURANDOM_SEED" );
5211 outline0("JSR CPURANDOM8" );
5212 outline0("LDA CPURANDOM_SEED" );
5213 outline1("STA %s", _result );
5214 }
5215
5217
5218}
5219
5220void cpu_random_16bit( Environment * _environment, char * _entropy, char * _result ) {
5221
5222 inline( cpu_random_16bit )
5223
5224 cpu_random( _environment, _entropy );
5225
5226 if ( _result ) {
5227 outline1("LDA %s", _entropy );
5228 outline0("ADC CPURANDOM_ENTROPY" );
5229 outline0("STA CPURANDOM_ENTROPY" );
5230 outline0("JSR CPURANDOM16" );
5231 outline0("LDA CPURANDOM_SEED" );
5232 outline1("STA %s", _result );
5233 outline0("LDA CPURANDOM_SEED+1" );
5234 outline1("STA %s", address_displacement(_environment, _result, "1") );
5235 }
5236
5238
5239}
5240
5241void cpu_random_32bit( Environment * _environment, char * _entropy, char * _result ) {
5242
5243 inline( cpu_random_32bit )
5244
5245 cpu_random( _environment, _entropy );
5246
5247 if ( _result ) {
5248 outline1("LDA %s", _entropy );
5249 outline0("ADC CPURANDOM_ENTROPY" );
5250 outline0("STA CPURANDOM_ENTROPY" );
5251 outline0("JSR CPURANDOM32" );
5252 outline0("LDA CPURANDOM_SEED" );
5253 outline1("STA %s", _result );
5254 outline0("LDA CPURANDOM_SEED+1" );
5255 outline1("STA %s", address_displacement(_environment, _result, "1") );
5256 outline0("LDA CPURANDOM_SEED+2" );
5257 outline1("STA %s", address_displacement(_environment, _result, "2") );
5258 outline0("LDA CPURANDOM_SEED+3" );
5259 outline1("STA %s", address_displacement(_environment, _result, "3") );
5260 }
5261
5263
5264}
5265
5266void cpu_limit_16bit( Environment * _environment, char * _variable, int _value ) {
5267
5269
5270 inline( cpu_limit_16bit )
5271
5272 outline0( "LDA #$0" );
5273 outline1( "STA %s", address_displacement(_environment, _variable, "1") );
5274 outline1( "LDA %s", _variable );
5275 outline1( "CMP #$%2.2x", (unsigned char)(_value & 0xff ) );
5276 outline1( "BCC %s", label );
5277 outline1( "SBC #$%2.2x", (unsigned char)(_value & 0xff ) );
5278 outline1( "STA %s", _variable );
5279 outhead1( "%s:", label );
5280
5282
5283}
5284
5285void cpu_busy_wait( Environment * _environment, char * _timing ) {
5286
5288
5289 inline( cpu_busy_wait )
5290
5291 outline1("LDX %s", _timing );
5292 outhead1("%s:", label );
5293 outline0("DEX");
5294 outline1("BNE %s", label);
5295
5297
5298}
5299
5300void cpu_logical_and_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5301
5303
5304 inline( cpu_logical_and_8bit )
5305
5306 outline1("LDA %s", _left );
5307 outhead1("BEQ %s", label );
5308 outline1("LDA %s", _right );
5309 outline1("BEQ %s", label);
5310 outline0("LDA #$FF");
5311 outline1("STA %s", _result);
5312 outline1("JMP %s_2", label);
5313 outhead1("%s:", label);
5314 outline0("LDA #0");
5315 outline1("STA %s", _result);
5316 outhead1("%s_2:", label);
5317
5319
5320}
5321
5322void cpu_and_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5323
5325
5326 inline( cpu_and_8bit )
5327
5328 outline1("LDA %s", _left );
5329 outline1("AND %s", _right );
5330 outline1("STA %s", _result);
5331
5333
5334}
5335
5336void cpu_and_8bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
5337
5339
5340 inline( cpu_and_8bit_const )
5341
5342 outline1("LDA %s", _left );
5343 outline1("AND #$%2.2x", _right );
5344 outline1("STA %s", _result);
5345
5347
5348}
5349
5350
5351void cpu_and_16bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5352
5354
5355 inline( cpu_and_16bit )
5356
5357 outline1("LDA %s", _left );
5358 outline1("AND %s", _right );
5359 outline1("STA %s", _result);
5360 outline1("LDA %s", address_displacement(_environment, _left, "1") );
5361 outline1("AND %s", address_displacement(_environment, _right, "1") );
5362 outline1("STA %s", address_displacement(_environment, _result, "1"));
5363
5365
5366}
5367
5368void cpu_and_32bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5369
5371
5372 inline( cpu_and_16bit )
5373
5374 outline1("LDA %s", _left );
5375 outline1("AND %s", _right );
5376 outline1("STA %s", _result);
5377 outline1("LDA %s", address_displacement(_environment, _left, "1") );
5378 outline1("AND %s", address_displacement(_environment, _right, "1") );
5379 outline1("STA %s", address_displacement(_environment, _result, "1"));
5380 outline1("LDA %s", address_displacement(_environment, _left, "2") );
5381 outline1("AND %s", address_displacement(_environment, _right, "2") );
5382 outline1("STA %s", address_displacement(_environment, _result, "2"));
5383 outline1("LDA %s", address_displacement(_environment, _left, "3") );
5384 outline1("AND %s", address_displacement(_environment, _right, "3") );
5385 outline1("STA %s", address_displacement(_environment, _result, "3"));
5386
5388
5389}
5390
5391void cpu_logical_or_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5392
5394
5395 inline( cpu_logical_or_8bit )
5396
5397 outline1("LDA %s", _left );
5398 outhead1("BNE %sd1", label );
5399 outline1("LDA %s", _right );
5400 outline1("BNE %sd1", label);
5401 outline1("JMP %s0", label);
5402 outhead1("%sd1:", label);
5403 outline0("LDA #$FF");
5404 outline1("STA %s", _result);
5405 outline1("JMP %sx", label);
5406 outhead1("%s0:", label);
5407 outline0("LDA #0");
5408 outline1("STA %s", _result);
5409 outhead1("%sx:", label);
5410
5412
5413}
5414
5415void cpu_or_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5416
5418
5419 inline( cpu_or_8bit )
5420
5421 outline1("LDA %s", _left );
5422 outline1("ORA %s", _right );
5423 outline1("STA %s", _result);
5424
5426
5427}
5428
5429void cpu_or_8bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
5430
5432
5433 inline( cpu_or_8bit_const )
5434
5435 outline1("LDA %s", _left );
5436 outline1("ORA #$%2.2x", _right );
5437 outline1("STA %s", _result);
5438
5440
5441}
5442
5443void cpu_or_16bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5444
5446
5447 inline( cpu_or_16bit )
5448
5449 outline1("LDA %s", _left );
5450 outline1("ORA %s", _right );
5451 outline1("STA %s", _result);
5452 outline1("LDA %s", address_displacement(_environment, _left, "1") );
5453 outline1("ORA %s", address_displacement(_environment, _right, "1") );
5454 outline1("STA %s", address_displacement(_environment, _result, "1"));
5455
5457
5458}
5459
5460void cpu_or_32bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5461
5463
5464 inline( cpu_or_32bit )
5465
5466 outline1("LDA %s", _left );
5467 outline1("ORA %s", _right );
5468 outline1("STA %s", _result);
5469 outline1("LDA %s", address_displacement(_environment, _left, "1") );
5470 outline1("ORA %s", address_displacement(_environment, _right, "1") );
5471 outline1("STA %s", address_displacement(_environment, _result, "1"));
5472 outline1("LDA %s", address_displacement(_environment, _left, "2") );
5473 outline1("ORA %s", address_displacement(_environment, _right, "2") );
5474 outline1("STA %s", address_displacement(_environment, _result, "2"));
5475 outline1("LDA %s", address_displacement(_environment, _left, "3") );
5476 outline1("ORA %s", address_displacement(_environment, _right, "3") );
5477 outline1("STA %s", address_displacement(_environment, _result, "3"));
5478
5480
5481}
5482
5483void cpu_xor_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5484
5486
5487 inline( cpu_xor_8bit )
5488
5489 outline1("LDA %s", _left );
5490 outline1("EOR %s", _right );
5491 outline1("STA %s", _result);
5492
5494
5495}
5496
5497void cpu_xor_8bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
5498
5500
5501 inline( cpu_xor_8bit )
5502
5503 outline1("LDA %s", _left );
5504 outline1("EOR #$%2.2x", _right );
5505 outline1("STA %s", _result);
5506
5508
5509}
5510
5511void cpu_xor_16bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5512
5514
5515 inline( cpu_xor_16bit )
5516
5517 outline1("LDA %s", _left );
5518 outline1("EOR %s", _right );
5519 outline1("STA %s", _result);
5520 outline1("LDA %s", address_displacement(_environment, _left, "1") );
5521 outline1("EOR %s", address_displacement(_environment, _right, "1") );
5522 outline1("STA %s", address_displacement(_environment, _result, "1"));
5523
5525
5526}
5527
5528void cpu_xor_16bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
5529
5531
5532 inline( cpu_xor_16bit )
5533
5534 outline1("LDA %s", _left );
5535 outline1("EOR #$%2.2x", (unsigned char)(_right&0xff) );
5536 outline1("STA %s", _result);
5537 outline1("LDA %s", address_displacement(_environment, _left, "1") );
5538 outline1("EOR #$%2.2x", (unsigned char)((_right>>8)&0xff) );
5539 outline1("STA %s", address_displacement(_environment, _result, "1"));
5540
5542
5543}
5544
5545void cpu_xor_32bit( Environment * _environment, char * _left, char * _right, char * _result ) {
5546
5548
5549 inline( cpu_xor_32bit )
5550
5551 outline1("LDA %s", _left );
5552 outline1("EOR %s", _right );
5553 outline1("STA %s", _result);
5554 outline1("LDA %s", address_displacement(_environment, _left, "1") );
5555 outline1("EOR %s", address_displacement(_environment, _right, "1") );
5556 outline1("STA %s", address_displacement(_environment, _result, "1"));
5557 outline1("LDA %s", address_displacement(_environment, _left, "2") );
5558 outline1("EOR %s", address_displacement(_environment, _right, "2") );
5559 outline1("STA %s", address_displacement(_environment, _result, "2"));
5560 outline1("LDA %s", address_displacement(_environment, _left, "3") );
5561 outline1("EOR %s", address_displacement(_environment, _right, "3") );
5562 outline1("STA %s", address_displacement(_environment, _result, "3"));
5563
5565
5566}
5567
5568void cpu_xor_32bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
5569
5571
5572 inline( cpu_xor_32bit )
5573
5574 outline1("LDA %s", _left );
5575 outline1("EOR #$%2.2x", (unsigned char)(_right&0xff) );
5576 outline1("STA %s", _result);
5577 outline1("LDA %s", address_displacement(_environment, _left, "1") );
5578 outline1("EOR #$%2.2x", (unsigned char)((_right>>8)&0xff) );
5579 outline1("STA %s", address_displacement(_environment, _result, "1"));
5580 outline1("LDA %s", address_displacement(_environment, _left, "2") );
5581 outline1("EOR #$%2.2x", (unsigned char)((_right>>16)&0xff) );
5582 outline1("STA %s", address_displacement(_environment, _result, "2"));
5583 outline1("LDA %s", address_displacement(_environment, _left, "3") );
5584 outline1("EOR #$%2.2x", (unsigned char)((_right>>24)&0xff) );
5585 outline1("STA %s", address_displacement(_environment, _result, "3"));
5586
5588
5589}
5590
5591void cpu_swap_8bit( Environment * _environment, char * _left, char * _right ) {
5592
5594
5595 inline( cpu_swap_8bit )
5596
5597 outline1("LDA %s", _left );
5598 outline0("PHA" );
5599 outline1("LDA %s", _right );
5600 outline1("STA %s", _left );
5601 outline0("PLA" );
5602 outline1("STA %s", _right);
5603
5605
5606}
5607
5608void cpu_swap_16bit( Environment * _environment, char * _left, char * _right ) {
5609
5611
5613
5615
5616 outline0("LDY #1" );
5617 outline1("LDA #>%s", _left );
5618 outline0("STA TMPPTR+1" );
5619 outline1("LDA #<%s", _left );
5620 outline0("STA TMPPTR" );
5621 outline1("LDA #>%s", _right );
5622 outline0("STA TMPPTR2+1" );
5623 outline1("LDA #<%s", _right );
5624 outline0("STA TMPPTR2" );
5625 outline0("JSR CPUSWAP" );
5626
5627 done( )
5628
5629}
5630
5631void cpu_swap_32bit( Environment * _environment, char * _left, char * _right ) {
5632
5634
5635 no_inline( cpu_swap_16bit ) // it is not an error, swap 16/32 share code
5636
5638
5639 outline0("LDY #3" );
5640 outline1("LDA #>%s", _left );
5641 outline0("STA TMPPTR+1" );
5642 outline1("LDA #<%s", _left );
5643 outline0("STA TMPPTR" );
5644 outline1("LDA #>%s", _right );
5645 outline0("STA TMPPTR2+1" );
5646 outline1("LDA #<%s", _right );
5647 outline0("STA TMPPTR2" );
5648 outline0("JSR CPUSWAP" );
5649
5650 done( )
5651
5652}
5653
5654void cpu_logical_not_8bit( Environment * _environment, char * _value, char * _result ) {
5655
5657
5658 inline( cpu_logical_not_8bit )
5659
5660 outline1("LDA %s", _value );
5661 outline0("EOR #$FF" );
5662 outline1("STA %s", _result );
5663
5665
5666}
5667
5668void cpu_not_8bit( Environment * _environment, char * _value, char * _result ) {
5669
5671
5672 inline( cpu_not_8bit )
5673
5674 outline1("LDA %s", _value );
5675 outline0("EOR #$FF" );
5676 outline1("STA %s", _result );
5677
5679
5680}
5681
5682void cpu_not_16bit( Environment * _environment, char * _value, char * _result ) {
5683
5685
5686 inline( cpu_not_16bit )
5687
5688 outline1("LDA %s", _value );
5689 outline0("EOR #$FF" );
5690 outline1("STA %s", _result );
5691 outline1("LDA %s", address_displacement(_environment, _value, "1") );
5692 outline0("EOR #$FF" );
5693 outline1("STA %s", address_displacement(_environment, _result, "1") );
5694
5696
5697}
5698
5699void cpu_not_32bit( Environment * _environment, char * _value, char * _result ) {
5700
5702
5703 inline( cpu_not_32bit )
5704
5705 outline1("LDA %s", _value );
5706 outline0("EOR #$FF" );
5707 outline1("STA %s", _result );
5708 outline1("LDA %s", address_displacement(_environment, _value, "1") );
5709 outline0("EOR #$FF" );
5710 outline1("STA %s", address_displacement(_environment, _result, "1") );
5711 outline1("LDA %s", address_displacement(_environment, _value, "2") );
5712 outline0("EOR #$FF" );
5713 outline1("STA %s", address_displacement(_environment, _result, "2") );
5714 outline1("LDA %s", address_displacement(_environment, _value, "3") );
5715 outline0("EOR #$FF" );
5716 outline1("STA %s", address_displacement(_environment, _result, "3") );
5717
5719
5720}
5721
5722void cpu_di( Environment * _environment ) {
5723
5724 inline( cpu_di )
5725
5726 outline0("SEI" );
5727
5729
5730}
5731
5732void cpu_ei( Environment * _environment ) {
5733
5734 inline( cpu_ei )
5735
5736 outline0("CLI" );
5737
5739
5740}
5741
5742void cpu_inc( Environment * _environment, char * _variable ) {
5743
5744 inline( cpu_inc )
5745
5746 outline1("INC %s", _variable );
5747
5749
5750}
5751
5752void cpu_inc_16bit( Environment * _environment, char * _variable ) {
5753
5755
5756 inline( cpu_inc_16bit )
5757
5758 outline1("INC %s", _variable );
5759 outline1("BNE %s", label );
5760 outline1("INC %s", address_displacement(_environment, _variable, "1") );
5761 outhead1("%s:", label );
5762
5764
5765}
5766
5767void cpu_inc_32bit( Environment * _environment, char * _variable ) {
5768
5770
5771 inline( cpu_inc_32bit )
5772
5773 outline1("INC %s", _variable );
5774 outline1("BNE %s", label );
5775 outline1("INC %s", address_displacement(_environment, _variable, "1") );
5776 outline1("BNE %s", label );
5777 outline1("INC %s", address_displacement(_environment, _variable, "2") );
5778 outline1("BNE %s", label );
5779 outline1("INC %s", address_displacement(_environment, _variable, "3") );
5780 outhead1("%s:", label );
5781
5783
5784}
5785
5786void cpu_inc_nbit( Environment * _environment, char * _variable, int _bits ) {
5787
5789
5790 inline( cpu_inc_nbit )
5791
5792 for( int i=0; i<(_bits>>3);++i ) {
5793 char offset[MAX_TEMPORARY_STORAGE]; sprintf(offset, "%d", i );
5794 outline1("INC %s", address_displacement(_environment, _variable, offset ) );
5795 outline1("BNE %s", label );
5796 }
5797 outhead1("%s:", label );
5798
5800
5801}
5802
5803void cpu_dec( Environment * _environment, char * _variable ) {
5804
5805 inline( cpu_dec )
5806
5807 outline1("DEC %s", _variable );
5808
5810
5811}
5812
5813void cpu_dec_16bit( Environment * _environment, char * _variable ) {
5814
5816
5817 inline( cpu_dec_16bit )
5818
5819 outline1("DEC %s", _variable );
5820 outline1("LDA %s", _variable );
5821 outline0("CMP #$FF" );
5822 outline1("BNE %s", label );
5823 outline1("DEC %s", address_displacement(_environment, _variable, "1") );
5824 outhead1("%s:", label );
5825
5827
5828}
5829
5830void cpu_dec_32bit( Environment * _environment, char * _variable ) {
5831
5833
5834 inline( cpu_dec_32bit )
5835
5836 outline1("DEC %s", _variable );
5837 outline1("LDA %s", _variable );
5838 outline0("CMP #$FF" );
5839 outline1("BNE %s", label );
5840 outline1("DEC %s", address_displacement(_environment, _variable, "1") );
5841 outline1("LDA %s", address_displacement(_environment, _variable, "1") );
5842 outline0("CMP #$FF" );
5843 outline1("BNE %s", label );
5844 outline1("DEC %s", address_displacement(_environment, _variable, "2") );
5845 outline1("LDA %s", address_displacement(_environment, _variable, "2") );
5846 outline0("CMP #$FF" );
5847 outline1("BNE %s", label );
5848 outline1("DEC %s", address_displacement(_environment, _variable, "3") );
5849 outline1("LDA %s", address_displacement(_environment, _variable, "3") );
5850 outhead1("%s:", label );
5851
5853
5854}
5855
5856void cpu_dec_nbit( Environment * _environment, char * _variable, int _bits ) {
5857
5859
5860 inline( cpu_dec_32bit )
5861
5862 for( int i=0; i<(_bits>>3); ++i ) {
5863 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
5864 outline1("DEC %s", address_displacement(_environment, _variable, offset) );
5865 outline1("LDA %s", address_displacement(_environment, _variable, offset) );
5866 outline0("CMP #$FF" );
5867 outline1("BNE %s", label );
5868 }
5869 outhead1("%s:", label );
5870
5872
5873}
5874
5875
5876void cpu_mem_move( Environment * _environment, char *_source, char *_destination, char *_size ) {
5877
5879
5880 inline( cpu_mem_move )
5881
5882 outline1("LDY %s", _size );
5883 outline1("BEQ %sdone", label );
5884 outline0("LDY #$0" );
5885 outline1("LDA %s", address_displacement(_environment, _source, "1") );
5886 outline0("STA TMPPTR+1" );
5887 outline1("LDA %s", _source );
5888 outline0("STA TMPPTR" );
5889 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
5890 outline0("STA TMPPTR2+1" );
5891 outline1("LDA %s", _destination );
5892 outline0("STA TMPPTR2" );
5893 outhead1("%s:", label );
5894 outline0("LDA (TMPPTR), Y" );
5895 outline0("STA (TMPPTR2), Y" );
5896 outline0("INY" );
5897 outline1("CPY %s", _size );
5898 outline1("BNE %s", label );
5899 outhead1("%sdone:", label );
5900
5902
5904
5905 outline1("LDX %s", _size );
5906 outline0("STX MATHPTR0" );
5907 outline0("LDX #$0" );
5908 outline0("STX MATHPTR1" );
5909 outline1("LDA %s", address_displacement(_environment, _source, "1") );
5910 outline0("STA TMPPTR+1" );
5911 outline1("LDA %s", _source );
5912 outline0("STA TMPPTR" );
5913 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
5914 outline0("STA TMPPTR2+1" );
5915 outline1("LDA %s", _destination );
5916 outline0("STA TMPPTR2" );
5917 outline0("JSR DUFFDEVICE" );
5918
5919 done()
5920
5921}
5922
5923void cpu_mem_move_16bit( Environment * _environment, char *_source, char *_destination, char *_size ) {
5924
5926
5928
5930
5932
5933 outline1("LDX %s", _size );
5934 outline0("STX MATHPTR0" );
5935 outline1("LDX %s", address_displacement(_environment, _size, "1") );
5936 outline0("STX MATHPTR1" );
5937 outline1("LDA %s", address_displacement(_environment, _source, "1") );
5938 outline0("STA TMPPTR+1" );
5939 outline1("LDA %s", _source );
5940 outline0("STA TMPPTR" );
5941 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
5942 outline0("STA TMPPTR2+1" );
5943 outline1("LDA %s", _destination );
5944 outline0("STA TMPPTR2" );
5945 outline0("JSR DUFFDEVICE" );
5946
5947 done()
5948
5949}
5950
5951void cpu_mem_move_direct( Environment * _environment, char *_source, char *_destination, char *_size ) {
5952
5954
5955 inline( cpu_mem_move ) // special case
5956
5957 outline1("LDY %s", _size );
5958 outline1("BEQ %sdone", label );
5959 outline0("LDY #$0" );
5960 outline1("LDA #>%s", _source );
5961 outline0("STA TMPPTR+1" );
5962 outline1("LDA #<%s", _source );
5963 outline0("STA TMPPTR" );
5964 outline1("LDA #>%s", _destination );
5965 outline0("STA TMPPTR2+1" );
5966 outline1("LDA #<%s", _destination );
5967 outline0("STA TMPPTR2" );
5968 outhead1("%s:", label );
5969 outline0("LDA (TMPPTR), Y" );
5970 outline0("STA (TMPPTR2), Y" );
5971 outline0("INY" );
5972 outline1("CPY %s", _size );
5973 outline1("BNE %s", label );
5974 outhead1("%sdone:", label );
5975
5977
5979
5980 outline1("LDX %s", _size );
5981 outline0("STX MATHPTR0" );
5982 outline0("LDX #$0" );
5983 outline0("STX MATHPTR1" );
5984 outline1("LDA #>%s", _source );
5985 outline0("STA TMPPTR+1" );
5986 outline1("LDA #<%s", _source );
5987 outline0("STA TMPPTR" );
5988 outline1("LDA #>%s", _destination );
5989 outline0("STA TMPPTR2+1" );
5990 outline1("LDA #<%s", _destination );
5991 outline0("STA TMPPTR2" );
5992 outline0("JSR DUFFDEVICE" );
5993
5994 done()
5995
5996}
5997
5998void cpu_mem_move_direct2_size( Environment * _environment, char *_source, char *_destination, int _size ) {
5999
6001
6002 inline( cpu_mem_move ) // special case
6003
6004 outline1("LDA #$%2.2x", ( _size >> 8 ) & 0xff );
6005 outline0("STA MATHPTR1" );
6006 outline1("LDA #$%2.2x", _size & 0xff );
6007 outline0("STA MATHPTR0" );
6008 outline0("ORA MATHPTR1" );
6009 outline1("BEQ %sdone", label );
6010 outline0("LDY #$0" );
6011 outline1("LDA %s+1", _source );
6012 outline0("STA TMPPTR+1" );
6013 outline1("LDA %s", _source );
6014 outline0("STA TMPPTR" );
6015 outline1("LDA #>%s", _destination );
6016 outline0("STA TMPPTR2+1" );
6017 outline1("LDA #<%s", _destination );
6018 outline0("STA TMPPTR2" );
6019 outhead1("%s:", label );
6020 outline0("LDA (TMPPTR), Y" );
6021 outline0("STA (TMPPTR2), Y" );
6022 outline0("INC TMPPTR" );
6023 outline1("BNE %sadd1", label );
6024 outline0("INC TMPPTR+1" );
6025 outhead1("%sadd1:", label );
6026 outline0("INC TMPPTR2" );
6027 outline1("BNE %sadd2", label );
6028 outline0("INC TMPPTR2+1" );
6029 outhead1("%sadd2:", label );
6030 outline0("DEC MATHPTR0" );
6031 outline1("BNE %sctr", label );
6032 outline0("DEC MATHPTR1" );
6033 outhead1("%sctr:", label );
6034 outline0("LDA MATHPTR0" );
6035 outline0("ORA MATHPTR1" );
6036 outline1("BNE %s:", label );
6037 outhead1("%sdone:", label );
6038
6040
6042
6043 outline1("LDA #$%2.2x", ( _size >> 8 ) & 0xff );
6044 outline0("STA MATHPTR1" );
6045 outline1("LDA #$%2.2x", _size & 0xff );
6046 outline0("STA MATHPTR0" );
6047 outline1("LDA %s+1", _source );
6048 outline0("STA TMPPTR+1" );
6049 outline1("LDA %s", _source );
6050 outline0("STA TMPPTR" );
6051 outline1("LDA #>%s", _destination );
6052 outline0("STA TMPPTR2+1" );
6053 outline1("LDA #<%s", _destination );
6054 outline0("STA TMPPTR2" );
6055 outline0("JSR DUFFDEVICE" );
6056
6057 done()
6058
6059}
6060
6061void cpu_mem_move_direct2( Environment * _environment, char *_source, char *_destination, char *_size ) {
6062
6064
6065 inline( cpu_mem_move ) // special case
6066
6067 outline1("LDA %s+1", _size );
6068 outline0("STA MATHPTR1" );
6069 outline1("LDA %s", _size );
6070 outline0("STA MATHPTR0" );
6071 outline0("ORA MATHPTR1" );
6072 outline1("BEQ %sdone", label );
6073 outline0("LDY #$0" );
6074 outline1("LDA %s+1", _source );
6075 outline0("STA TMPPTR+1" );
6076 outline1("LDA %s", _source );
6077 outline0("STA TMPPTR" );
6078 outline1("LDA #>%s", _destination );
6079 outline0("STA TMPPTR2+1" );
6080 outline1("LDA #<%s", _destination );
6081 outline0("STA TMPPTR2" );
6082 outhead1("%s:", label );
6083 outline0("LDA (TMPPTR), Y" );
6084 outline0("STA (TMPPTR2), Y" );
6085 outline0("INC TMPPTR" );
6086 outline1("BNE %sadd1", label );
6087 outline0("INC TMPPTR+1" );
6088 outhead1("%sadd1:", label );
6089 outline0("INC TMPPTR2" );
6090 outline1("BNE %sadd2", label );
6091 outline0("INC TMPPTR2+1" );
6092 outhead1("%sadd2:", label );
6093 outline0("DEC MATHPTR0" );
6094 outline1("BNE %sctr", label );
6095 outline0("DEC MATHPTR1" );
6096 outhead1("%sctr:", label );
6097 outline0("LDA MATHPTR0" );
6098 outline0("ORA MATHPTR1" );
6099 outline1("BNE %s:", label );
6100 outhead1("%sdone:", label );
6101
6103
6105
6106 outline1("LDA %s+1", _size );
6107 outline0("STA MATHPTR1" );
6108 outline1("LDA %s", _size );
6109 outline0("STA MATHPTR0" );
6110 outline1("LDA %s+1", _source );
6111 outline0("STA TMPPTR+1" );
6112 outline1("LDA %s", _source );
6113 outline0("STA TMPPTR" );
6114 outline1("LDA #>%s", _destination );
6115 outline0("STA TMPPTR2+1" );
6116 outline1("LDA #<%s", _destination );
6117 outline0("STA TMPPTR2" );
6118 outline0("JSR DUFFDEVICE" );
6119
6120 done()
6121
6122}
6123
6124void cpu_mem_move_size( Environment * _environment, char *_source, char *_destination, int _size ) {
6125
6126 if ( _size ) {
6127
6129
6130 inline( cpu_mem_move )
6131
6132 outline0("LDY #$0" );
6133 outline1("LDA %s", address_displacement(_environment, _source, "1") );
6134 outline0("STA TMPPTR+1" );
6135 outline1("LDA %s", _source );
6136 outline0("STA TMPPTR" );
6137 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6138 outline0("STA TMPPTR2+1" );
6139 outline1("LDA %s", _destination );
6140 outline0("STA TMPPTR2" );
6141 outhead1("%s:", label );
6142 outline0("LDA (TMPPTR), Y" );
6143 outline0("STA (TMPPTR2), Y" );
6144 outline0("INY" );
6145 outline1("CPY #$%2.2x", (_size & 0xff ) );
6146 outline1("BNE %s", label );
6147
6149
6151
6152 outline1("LDX #$%2.2X", (_size & 0xff ) );
6153 outline0("STX MATHPTR0" );
6154 outline1("LDX #$%2.2X", ( _size >> 8 ) & 0xff );
6155 outline0("STX MATHPTR1" );
6156 outline1("LDA %s", address_displacement(_environment, _source, "1") );
6157 outline0("STA TMPPTR+1" );
6158 outline1("LDA %s", _source );
6159 outline0("STA TMPPTR" );
6160 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6161 outline0("STA TMPPTR2+1" );
6162 outline1("LDA %s", _destination );
6163 outline0("STA TMPPTR2" );
6164 outline0("JSR DUFFDEVICE" );
6165
6166 done()
6167 }
6168
6169}
6170
6171void cpu_mem_move_direct_size( Environment * _environment, char *_source, char *_destination, int _size ) {
6172
6173 if ( _size ) {
6174
6176
6177 inline( cpu_mem_move )
6178
6179 if ( _size <= 0xff ) {
6180
6181 outline0("LDY #$0" );
6182 outline1("LDA #>%s", _source );
6183 outline0("STA TMPPTR+1" );
6184 outline1("LDA #<%s", _source );
6185 outline0("STA TMPPTR" );
6186 outline1("LDA #>%s", _destination );
6187 outline0("STA TMPPTR2+1" );
6188 outline1("LDA #<%s", _destination );
6189 outline0("STA TMPPTR2" );
6190 outhead1("%s:", label );
6191 outline0("LDA (TMPPTR), Y" );
6192 outline0("STA (TMPPTR2), Y" );
6193 outline0("INY" );
6194 outline1("CPY #$%2.2x", (_size & 0xff ) );
6195 outline1("BNE %s", label );
6196
6197 } else {
6198
6199 outline0("LDX #$0" );
6200 outline0("LDY #$0" );
6201 outline1("LDA #>(%s)", _source );
6202 outline0("STA TMPPTR+1" );
6203 outline1("LDA #<(%s)", _source );
6204 outline0("STA TMPPTR" );
6205 outline1("LDA #>(%s)", _destination );
6206 outline0("STA TMPPTR2+1" );
6207 outline1("LDA #<(%s)", _destination );
6208 outline0("STA TMPPTR2" );
6209 outhead1("%s:", label );
6210 outline0("LDA (TMPPTR), Y" );
6211 outline0("STA (TMPPTR2), Y" );
6212 outline0("INY" );
6213 outline0("CPY #$ff" );
6214 outline1("BNE %s", label );
6215 outline0("CLC" );
6216 outline0("LDA TMPPTR" );
6217 outline0("ADC #$FF" );
6218 outline0("STA TMPPTR" );
6219 outline0("LDA TMPPTR+1" );
6220 outline0("ADC #0" );
6221 outline0("STA TMPPTR+1" );
6222 outline0("CLC" );
6223 outline0("LDA TMPPTR2" );
6224 outline0("ADC #$FF" );
6225 outline0("STA TMPPTR2" );
6226 outline0("LDA TMPPTR2+1" );
6227 outline0("ADC #0" );
6228 outline0("STA TMPPTR2+1" );
6229 outline0("LDY #0" );
6230 outline1("CPX #$%2.2x", ( ( ( _size >> 8 ) & 0xff ) ) - 1 );
6231 outline1("BEQ %se", label );
6232 outline0("INX" );
6233 outline1("JMP %s", label );
6234 outhead1("%se:", label );
6235 outhead1("%sfinal:", label );
6236 outline0("LDA (TMPPTR), Y" );
6237 outline0("STA (TMPPTR2), Y" );
6238 outline0("INY" );
6239 outline1("CPY #$%2.2x", _size - ( ( ( ( _size >> 8 ) & 0xff ) ) ) * 0xff );
6240 outline1("BNE %sfinal", label );
6241
6242 }
6243
6245
6247
6248 outline1("LDX #$%2.2X", (_size & 0xff ) );
6249 outline0("STX MATHPTR0" );
6250 outline1("LDX #$%2.2X", ( _size >> 8 ) & 0xff );
6251 outline0("STX MATHPTR1" );
6252 outline1("LDA #>(%s)", _source );
6253 outline0("STA TMPPTR+1" );
6254 outline1("LDA #<(%s)", _source );
6255 outline0("STA TMPPTR" );
6256 outline1("LDA #>(%s)", _destination );
6257 outline0("STA TMPPTR2+1" );
6258 outline1("LDA #<(%s)", _destination );
6259 outline0("STA TMPPTR2" );
6260 outline0("JSR DUFFDEVICE" );
6261
6262 done()
6263
6264 }
6265
6266}
6267
6268void cpu_mem_move_direct_indirect_size( Environment * _environment, char *_source, char *_destination, int _size ) {
6269
6270 if ( _size ) {
6271
6273
6274 inline( cpu_mem_move )
6275
6276 if ( _size <= 0xff ) {
6277
6278 outline0("LDY #$0" );
6279 outline1("LDA #>%s", _source );
6280 outline0("STA TMPPTR+1" );
6281 outline1("LDA #<%s", _source );
6282 outline0("STA TMPPTR" );
6283 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6284 outline0("STA TMPPTR2+1" );
6285 outline1("LDA %s", _destination );
6286 outline0("STA TMPPTR2" );
6287 outhead1("%s:", label );
6288 outline0("LDA (TMPPTR), Y" );
6289 outline0("STA (TMPPTR2), Y" );
6290 outline0("INY" );
6291 outline1("CPY #$%2.2x", (_size & 0xff ) );
6292 outline1("BNE %s", label );
6293
6294 } else {
6295
6296 outline0("LDX #$0" );
6297 outline0("LDY #$0" );
6298 outline1("LDA #>%s", _source );
6299 outline0("STA TMPPTR+1" );
6300 outline1("LDA #<%s", _source );
6301 outline0("STA TMPPTR" );
6302 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6303 outline0("STA TMPPTR2+1" );
6304 outline1("LDA %s", _destination );
6305 outline0("STA TMPPTR2" );
6306 outhead1("%s:", label );
6307 outline0("LDA (TMPPTR), Y" );
6308 outline0("STA (TMPPTR2), Y" );
6309 outline0("INY" );
6310 outline0("CPY #$ff" );
6311 outline1("BNE %s", label );
6312 outline0("CLC" );
6313 outline0("LDA TMPPTR" );
6314 outline0("ADC #$FF" );
6315 outline0("STA TMPPTR" );
6316 outline0("LDA TMPPTR+1" );
6317 outline0("ADC #0" );
6318 outline0("STA TMPPTR+1" );
6319 outline0("CLC" );
6320 outline0("LDA TMPPTR2" );
6321 outline0("ADC #$FF" );
6322 outline0("STA TMPPTR2" );
6323 outline0("LDA TMPPTR2+1" );
6324 outline0("ADC #0" );
6325 outline0("STA TMPPTR2+1" );
6326 outline0("LDY #0" );
6327 outline1("CPX #$%2.2x", ( ( ( _size >> 8 ) & 0xff ) ) - 1 );
6328 outline1("BEQ %se", label );
6329 outline0("INX" );
6330 outline1("JMP %s", label );
6331 outhead1("%se:", label );
6332 outhead1("%sfinal:", label );
6333 outline0("LDA (TMPPTR), Y" );
6334 outline0("STA (TMPPTR2), Y" );
6335 outline0("INY" );
6336 outline1("CPY #$%2.2x", _size - ( ( ( ( _size >> 8 ) & 0xff ) ) ) * 0xff );
6337 outline1("BNE %sfinal", label );
6338
6339 }
6340
6342
6344
6345 outline1("LDX #$%2.2X", (_size & 0xff ) );
6346 outline0("STX MATHPTR0" );
6347 outline1("LDX #$%2.2X", ( _size >> 8 ) & 0xff );
6348 outline0("STX MATHPTR1" );
6349 outline1("LDA #>%s", _source );
6350 outline0("STA TMPPTR+1" );
6351 outline1("LDA #<%s", _source );
6352 outline0("STA TMPPTR" );
6353 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6354 outline0("STA TMPPTR2+1" );
6355 outline1("LDA %s", _destination );
6356 outline0("STA TMPPTR2" );
6357 outline0("JSR DUFFDEVICE" );
6358
6359 done()
6360
6361 }
6362
6363}
6364
6365void cpu_mem_move_indirect_direct_size( Environment * _environment, char *_source, char *_destination, int _size ) {
6366
6367 if ( _size ) {
6368
6370
6372
6374
6376
6377 outline1("LDX #$%2.2X", (_size & 0xff ) );
6378 outline0("STX MATHPTR0" );
6379 outline1("LDX #$%2.2X", ( _size >> 8 ) & 0xff );
6380 outline0("STX MATHPTR1" );
6381 outline1("LDA %s", _source );
6382 outline0("STA TMPPTR+1" );
6383 outline1("LDA %s", address_displacement(_environment, _source, "1") );
6384 outline0("STA TMPPTR" );
6385 outline1("LDA #>%s", _destination );
6386 outline0("STA TMPPTR2+1" );
6387 outline1("LDA #<%s", _destination );
6388 outline0("STA TMPPTR2" );
6389 outline0("JSR DUFFDEVICE" );
6390
6391 done()
6392
6393 }
6394
6395}
6396
6397void cpu_compare_memory( Environment * _environment, char *_source, char *_destination, char *_size, char * _result, int _equal ) {
6398
6400
6401 inline( cpu_compare_memory )
6402
6403 outline1("LDA %s", _size );
6404 outline1("BEQ %sequal", label );
6405 outline0("LDY #$0" );
6406 outline1("LDA %s", address_displacement(_environment, _source, "1") );
6407 outline0("STA TMPPTR+1" );
6408 outline1("LDA %s", _source );
6409 outline0("STA TMPPTR" );
6410 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6411 outline0("STA TMPPTR2+1" );
6412 outline1("LDA %s", _destination );
6413 outline0("STA TMPPTR2" );
6414 outhead1("%sloop:", label );
6415 outline0("LDA (TMPPTR2), Y" );
6416 outline0("CMP (TMPPTR), Y" );
6417 outline1("BNE %sdiff", label );
6418 outline0("INY" );
6419 outline1("CPY %s", _size );
6420 outline1("BNE %sloop", label );
6421 outhead1("%sequal:", label );
6422 outline1("LDA #%d", _equal ? 255 : 0 );
6423 outline1("STA %s", _result );
6424 outline1("JMP %sfinal", label );
6425 outhead1("%sdiff:", label );
6426 outline1("LDA #%d", _equal ? 0 : 255 );
6427 outline1("STA %s", _result );
6428 outhead1("%sfinal:", label );
6429
6431
6432}
6433
6434void cpu_compare_memory_size( Environment * _environment, char *_source, char *_destination, int _size, char * _result, int _equal ) {
6435
6437
6438 inline( cpu_compare_memory_size )
6439
6440 outline0("LDY #$0" );
6441 outline1("LDA %s", address_displacement(_environment, _source, "1") );
6442 outline0("STA TMPPTR+1" );
6443 outline1("LDA %s", _source );
6444 outline0("STA TMPPTR" );
6445 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6446 outline0("STA TMPPTR2+1" );
6447 outline1("LDA %s", _destination );
6448 outline0("STA TMPPTR2" );
6449 outhead1("%sloop:", label );
6450 outline0("LDA (TMPPTR2), Y" );
6451 outline0("CMP (TMPPTR), Y" );
6452 outline1("BNE %sdiff", label );
6453 outline0("INY" );
6454 outline1("CPY #$%2.2x", _size );
6455 outline1("BNE %sloop", label );
6456 outline1("LDA #%d", _equal ? 255 : 0 );
6457 outline1("STA %s", _result );
6458 outline1("JMP %sfinal", label );
6459 outhead1("%sdiff:", label );
6460 outline1("LDA #%d", _equal ? 0 : 255 );
6461 outline1("STA %s", _result );
6462 outhead1("%sfinal:", label );
6463
6465
6466}
6467
6468void cpu_less_than_memory( Environment * _environment, char *_source, char *_destination, char *_size, char * _result, int _equal ) {
6469
6471
6472 inline( cpu_less_than_memory )
6473
6474 outline0("LDY #$0" );
6475 outline1("LDA %s", address_displacement(_environment, _source, "1") );
6476 outline0("STA TMPPTR+1" );
6477 outline1("LDA %s", _source );
6478 outline0("STA TMPPTR" );
6479 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6480 outline0("STA TMPPTR2+1" );
6481 outline1("LDA %s", _destination );
6482 outline0("STA TMPPTR2" );
6483 outhead1("%sloop:", label );
6484 outline0("LDA (TMPPTR2), Y" );
6485 outline0("CMP (TMPPTR), Y" );
6486 if ( ! _equal ) {
6487 outline1("BEQ %sfalse", label);
6488 }
6489 outline1("BCS %strue", label);
6490 outline0("INY" );
6491 outline1("CPY %s", _size );
6492 outline1("BNE %sloop", label );
6493 outhead1("%sfalse:", label );
6494 outline0("LDA #0" );
6495 outline1("STA %s", _result );
6496 outline1("JMP %sfinal", label );
6497 outhead1("%strue:", label );
6498 outline0("LDA #$FF" );
6499 outline1("STA %s", _result );
6500 outhead1("%sfinal:", label );
6501
6503
6504}
6505
6506void cpu_less_than_memory_size( Environment * _environment, char *_source, char *_destination, int _size, char * _result, int _equal ) {
6507
6509
6511
6512 outline0("LDY #$0" );
6513 outline1("LDA %s", address_displacement(_environment, _source, "1") );
6514 outline0("STA TMPPTR+1" );
6515 outline1("LDA %s", _source );
6516 outline0("STA TMPPTR" );
6517 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6518 outline0("STA TMPPTR2+1" );
6519 outline1("LDA %s", _destination );
6520 outline0("STA TMPPTR2" );
6521 outhead1("%sloop:", label );
6522 outline0("LDA (TMPPTR2), Y" );
6523 outline0("CMP (TMPPTR), Y" );
6524 if ( ! _equal ) {
6525 outline1("BEQ %sfalse", label);
6526 }
6527 outline1("BCS %strue", label);
6528 outline0("INY" );
6529 outline1("CPY #$%2.2x", _size );
6530 outline1("BNE %sloop", label );
6531 outhead1("%sfalse:", label );
6532 outline0("LDA #0" );
6533 outline1("STA %s", _result );
6534 outline1("JMP %sfinal", label );
6535 outhead1("%strue:", label );
6536 outline0("LDA #$FF" );
6537 outline1("STA %s", _result );
6538 outhead1("%sfinal:", label );
6539
6541
6542}
6543
6544void cpu_greater_than_memory( Environment * _environment, char *_source, char *_destination, char *_size, char * _result, int _equal ) {
6545
6547
6548 inline( cpu_greater_than_memory )
6549
6550 outline0("LDY #$0" );
6551 outline1("LDA %s", address_displacement(_environment, _source, "1") );
6552 outline0("STA TMPPTR+1" );
6553 outline1("LDA %s", _source );
6554 outline0("STA TMPPTR" );
6555 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6556 outline0("STA TMPPTR2+1" );
6557 outline1("LDA %s", _destination );
6558 outline0("STA TMPPTR2" );
6559 outhead1("%sloop:", label );
6560 outline0("LDA (TMPPTR), Y" );
6561 outline0("CMP (TMPPTR2), Y" );
6562 if ( ! _equal ) {
6563 outline1("BEQ %sfalse", label);
6564 }
6565 outline1("BCC %sfalse", label);
6566 outline0("INY" );
6567 outline1("CPY %s", _size );
6568 outline1("BNE %sloop", label );
6569 outhead1("%strue:", label );
6570 outline0("LDA #$FF" );
6571 outline1("STA %s", _result );
6572 outline1("JMP %sfinal", label );
6573 outhead1("%sfalse:", label );
6574 outline0("LDA #0" );
6575 outline1("STA %s", _result );
6576 outhead1("%sfinal:", label );
6577
6579
6580}
6581
6582void cpu_greater_than_memory_size( Environment * _environment, char *_source, char *_destination, int _size, char * _result, int _equal ) {
6583
6585
6587
6588 outline0("LDY #$0" );
6589 outline1("LDA %s", address_displacement(_environment, _source, "1") );
6590 outline0("STA TMPPTR+1" );
6591 outline1("LDA %s", _source );
6592 outline0("STA TMPPTR" );
6593 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
6594 outline0("STA TMPPTR2+1" );
6595 outline1("LDA %s", _destination );
6596 outline0("STA TMPPTR2" );
6597 outhead1("%sloop:", label );
6598 outline0("LDA (TMPPTR), Y" );
6599 outline0("CMP (TMPPTR2), Y" );
6600 if ( ! _equal ) {
6601 outline1("BEQ %sfalse", label);
6602 }
6603 outline1("BCC %sfalse", label);
6604 outline0("INY" );
6605 outline1("CPY #$%2.2x", _size );
6606 outline1("BNE %sloop", label );
6607 outhead1("%strue:", label );
6608 outline0("LDA #$FF" );
6609 outline1("STA %s", _result );
6610 outline1("JMP %sfinal", label );
6611 outhead1("%sfalse:", label );
6612 outline0("LDA #0" );
6613 outline1("STA %s", _result );
6614 outhead1("%sfinal:", label );
6615
6617
6618}
6619
6620void cpu_move_8bit_indirect( Environment * _environment, char *_source, char * _value ) {
6621
6622 inline( cpu_move_8bit_indirect )
6623
6624 outline1("LDA %s", _value);
6625 outline0("STA TMPPTR");
6626 outline1("LDA %s", address_displacement(_environment, _value, "1"));
6627 outline0("STA TMPPTR+1");
6628 outline1("LDA %s", _source);
6629 outline0("LDY #$0" );
6630 outline0("STA (TMPPTR),Y");
6631
6633
6634}
6635
6636void cpu_move_8bit_indirect_with_offset( Environment * _environment, char *_source, char * _value, int _offset ) {
6637
6638 inline( cpu_move_8bit_with_offset )
6639
6641
6642 outline1("LDA %s", _value);
6643 outline1("STA %s+1", label);
6644 outline1("LDA %s", address_displacement(_environment, _value, "1"));
6645 outline1("STA %s+2", label);
6646 outline1("LDA %s", _source);
6647 outline1("LDY #$%2.2x", (_offset & 0xff ) );
6648 outhead1("%s:", label );
6649 outline0("STA $FF00,Y");
6650
6651 no_embedded( cpu_move_8bit_with_offset )
6652
6653}
6654
6655void cpu_move_8bit_indirect_with_offset2( Environment * _environment, char *_source, char * _value, char * _offset ) {
6656
6658
6659 outline1("LDA %s", _value);
6660 outline0("STA TMPPTR");
6661 outline1("LDA %s", address_displacement(_environment, _value, "1"));
6662 outline0("STA TMPPTR+1");
6663 outline1("LDA %s", _source);
6664 outline1("LDY %s", _offset );
6665 outline0("STA (TMPPTR),Y");
6666
6668
6669}
6670
6671void cpu_move_8bit_with_offset2( Environment * _environment, char *_source, char * _value, char * _offset ) {
6672
6674
6675 outline1("LDA #<%s", _value);
6676 outline0("STA TMPPTR");
6677 outline1("LDA #>%s", _value);
6678 outline0("STA TMPPTR+1");
6679 outline1("LDA %s", _source);
6680 outline1("LDY %s", _offset );
6681 outline0("STA (TMPPTR),Y");
6682
6684
6685}
6686
6687void cpu_move_8bit_indirect2( Environment * _environment, char * _value, char *_source ) {
6688
6689 inline( cpu_move_8bit_indirect2 )
6690
6691 outline1("LDA %s", _value);
6692 outline0("STA TMPPTR");
6693 outline1("LDA %s", address_displacement(_environment, _value, "1"));
6694 outline0("STA TMPPTR+1");
6695 outline0("LDY #$0" );
6696 outline0("LDA (TMPPTR),Y");
6697 outline1("STA %s", _source);
6698
6700
6701}
6702
6703void cpu_move_16bit_indirect( Environment * _environment, char *_source, char * _value ) {
6704
6705 inline( cpu_move_16bit_indirect )
6706
6707 outline1("LDA %s", _value);
6708 outline0("STA TMPPTR");
6709 outline1("LDA %s", address_displacement(_environment, _value, "1"));
6710 outline0("STA TMPPTR+1");
6711 outline1("LDA %s", _source);
6712 outline0("LDY #$0" );
6713 outline0("STA (TMPPTR),Y");
6714 outline1("LDA %s", address_displacement(_environment, _source, "1"));
6715 outline0("LDY #$1" );
6716 outline0("STA (TMPPTR),Y");
6717
6719
6720}
6721
6722void cpu_move_16bit_indirect2( Environment * _environment, char * _value, char *_source ) {
6723
6724 inline( cpu_move_16bit_indirect2 )
6725
6726 outline1("LDA %s", _value);
6727 outline0("STA TMPPTR");
6728 outline1("LDA %s", address_displacement(_environment, _value, "1"));
6729 outline0("STA TMPPTR+1");
6730 outline0("LDY #$0" );
6731 outline0("LDA (TMPPTR),Y");
6732 outline1("STA %s", _source);
6733 outline0("LDY #$1" );
6734 outline0("LDA (TMPPTR),Y");
6735 outline1("STA %s", address_displacement(_environment, _source, "1"));
6736
6738
6739}
6740
6741void cpu_move_16bit_indirect2_8bit( Environment * _environment, char * _value, char * _index, char *_source ) {
6742
6744
6745 outline1("LDA #<%s", _value);
6746 outline0("STA TMPPTR");
6747 outline1("LDA #>%s", _value);
6748 outline0("STA TMPPTR+1");
6749 outline1("LDA %s", _index );
6750 outline0("ASL");
6751 outline0("TAY");
6752 outline0("LDA (TMPPTR),Y");
6753 outline1("STA %s", _source);
6754 outline0("INY" );
6755 outline0("LDA (TMPPTR),Y");
6756 outline1("STA %s", address_displacement(_environment, _source, "1"));
6757
6759
6760}
6761
6762void cpu_move_32bit_indirect( Environment * _environment, char *_source, char * _value ) {
6763
6764 inline( cpu_move_32bit_indirect )
6765
6766 outline1("LDA %s", _value);
6767 outline0("STA TMPPTR");
6768 outline1("LDA %s", address_displacement(_environment, _value, "1"));
6769 outline0("STA TMPPTR+1");
6770 outline1("LDA %s", _source);
6771 outline0("LDY #$0" );
6772 outline0("STA (TMPPTR),Y");
6773 outline1("LDA %s", address_displacement(_environment, _source, "1"));
6774 outline0("LDY #$1" );
6775 outline0("STA (TMPPTR),Y");
6776 outline1("LDA %s", address_displacement(_environment, _source, "2"));
6777 outline0("LDY #$2" );
6778 outline0("STA (TMPPTR),Y");
6779 outline1("LDA %s", address_displacement(_environment, _source, "2"));
6780 outline0("LDY #$3" );
6781 outline0("STA (TMPPTR),Y");
6782
6784
6785}
6786
6787void cpu_move_32bit_indirect2( Environment * _environment, char * _value, char *_source ) {
6788
6789 inline( cpu_move_32bit_indirect2 )
6790
6791 outline1("LDA %s", _value);
6792 outline0("STA TMPPTR");
6793 outline1("LDA %s", address_displacement(_environment, _value, "1"));
6794 outline0("STA TMPPTR+1");
6795 outline0("LDY #$0" );
6796 outline0("LDA (TMPPTR),Y");
6797 outline1("STA %s", _source);
6798 outline0("LDY #$1" );
6799 outline0("LDA (TMPPTR),Y");
6800 outline1("STA %s", address_displacement(_environment, _source, "1"));
6801 outline0("LDY #$2" );
6802 outline0("LDA (TMPPTR),Y");
6803 outline1("STA %s", address_displacement(_environment, _source, "2"));
6804 outline0("LDY #$3" );
6805 outline0("LDA (TMPPTR),Y");
6806 outline1("STA %s", address_displacement(_environment, _source, "3"));
6807
6809
6810}
6811
6812void cpu_move_nbit_indirect( Environment * _environment, int _n, char *_source, char * _value ) {
6813
6814 outline1("LDA %s", _value);
6815 outline0("STA TMPPTR");
6816 outline1("LDA %s", address_displacement(_environment, _value, "1"));
6817 outline0("STA TMPPTR+1");
6818
6819 char step[MAX_TEMPORARY_STORAGE];
6820 char step1[MAX_TEMPORARY_STORAGE];
6821 char step2[MAX_TEMPORARY_STORAGE];
6822 char step3[MAX_TEMPORARY_STORAGE];
6823
6824 int stepIndex = 0;
6825 while( _n ) {
6826 sprintf( step, "%d", stepIndex );
6827 sprintf( step1, "%d", stepIndex+1 );
6828 sprintf( step2, "%d", stepIndex+2 );
6829 sprintf( step3, "%d", stepIndex+3 );
6830 if ( _n >= 32 ) {
6831 outline1("LDA %s", address_displacement(_environment, _source, step));
6832 outline1("LDY #$%2.2x", stepIndex );
6833 outline0("STA (TMPPTR),Y");
6834 outline1("LDA %s", address_displacement(_environment, _source, step1));
6835 outline1("LDY #$%2.2x", stepIndex + 1 );
6836 outline0("STA (TMPPTR),Y");
6837 outline1("LDA %s", address_displacement(_environment, _source, step2));
6838 outline1("LDY #$%2.2x", stepIndex + 2 );
6839 outline0("STA (TMPPTR),Y");
6840 outline1("LDA %s", address_displacement(_environment, _source, step3));
6841 outline1("LDY #$%2.2x", stepIndex + 3 );
6842 outline0("STA (TMPPTR),Y");
6843 stepIndex += 4;
6844 _n -= 32;
6845 } else {
6846 switch( _n ) {
6847 case 32: case 31: case 30: case 29:
6848 case 28: case 27: case 26: case 25:
6849 outline1("LDA %s", address_displacement(_environment, _source, step));
6850 outline1("LDY #$%2.2x", stepIndex );
6851 outline0("STA (TMPPTR),Y");
6852 outline1("LDA %s", address_displacement(_environment, _source, step1));
6853 outline1("LDY #$%2.2x", stepIndex + 1 );
6854 outline0("STA (TMPPTR),Y");
6855 outline1("LDA %s", address_displacement(_environment, _source, step2));
6856 outline1("LDY #$%2.2x", stepIndex + 2 );
6857 outline0("STA (TMPPTR),Y");
6858 outline1("LDA %s", address_displacement(_environment, _source, step3));
6859 outline1("LDY #$%2.2x", stepIndex + 3 );
6860 outline0("STA (TMPPTR),Y");
6861 break;
6862 case 24: case 23: case 22: case 21:
6863 case 20: case 19: case 18: case 17:
6864 outline1("LDA %s", address_displacement(_environment, _source, step));
6865 outline1("LDY #$%2.2x", stepIndex );
6866 outline0("STA (TMPPTR),Y");
6867 outline1("LDA %s", address_displacement(_environment, _source, step1));
6868 outline1("LDY #$%2.2x", stepIndex + 1 );
6869 outline0("STA (TMPPTR),Y");
6870 outline1("LDA %s", address_displacement(_environment, _source, step2));
6871 outline1("LDY #$%2.2x", stepIndex + 2 );
6872 outline0("STA (TMPPTR),Y");
6873 break;
6874 case 16: case 15: case 14: case 13:
6875 case 12: case 11: case 10: case 9:
6876 outline1("LDA %s", address_displacement(_environment, _source, step));
6877 outline1("LDY #$%2.2x", stepIndex );
6878 outline0("STA (TMPPTR),Y");
6879 outline1("LDA %s", address_displacement(_environment, _source, step1));
6880 outline1("LDY #$%2.2x", stepIndex + 1 );
6881 outline0("STA (TMPPTR),Y");
6882 break;
6883 case 8: case 7: case 6: case 5:
6884 case 4: case 3: case 2: case 1:
6885 outline1("LDA %s", address_displacement(_environment, _source, step));
6886 outline1("LDY #$%2.2x", stepIndex );
6887 outline0("STA (TMPPTR),Y");
6888 break;
6889 }
6890 _n = 0;
6891 }
6892 }
6893}
6894
6895void cpu_move_nbit_indirect2( Environment * _environment, int _n, char * _value, char *_source ) {
6896
6897 outline1("LDA %s", _value);
6898 outline0("STA TMPPTR");
6899 outline1("LDA %s", address_displacement(_environment, _value, "1"));
6900 outline0("STA TMPPTR+1");
6901
6902 char step[MAX_TEMPORARY_STORAGE];
6903 char step1[MAX_TEMPORARY_STORAGE];
6904 char step2[MAX_TEMPORARY_STORAGE];
6905 char step3[MAX_TEMPORARY_STORAGE];
6906
6907 int stepIndex = 0;
6908 while( _n ) {
6909 sprintf( step, "%d", stepIndex );
6910 sprintf( step1, "%d", stepIndex+1 );
6911 sprintf( step2, "%d", stepIndex+2 );
6912 sprintf( step3, "%d", stepIndex+3 );
6913 if ( _n >= 32 ) {
6914 outline1("LDY #$%2.2x", stepIndex );
6915 outline0("LDA (TMPPTR),Y");
6916 outline1("STA %s", address_displacement(_environment, _source, step));
6917 outline1("LDY #$%2.2x", stepIndex + 1 );
6918 outline0("LDA (TMPPTR),Y");
6919 outline1("STA %s", address_displacement(_environment, _source, step1));
6920 outline1("LDY #$%2.2x", stepIndex + 2 );
6921 outline0("LDA (TMPPTR),Y");
6922 outline1("STA %s", address_displacement(_environment, _source, step2));
6923 outline1("LDY #$%2.2x", stepIndex + 3 );
6924 outline0("LDA (TMPPTR),Y");
6925 outline1("STA %s", address_displacement(_environment, _source, step3));
6926 stepIndex += 4;
6927 _n -= 32;
6928 } else {
6929 switch( _n ) {
6930 case 32: case 31: case 30: case 29:
6931 case 28: case 27: case 26: case 25:
6932 outline1("LDY #$%2.2x", stepIndex );
6933 outline0("LDA (TMPPTR),Y");
6934 outline1("STA %s", address_displacement(_environment, _source, step));
6935 outline1("LDY #$%2.2x", stepIndex + 1 );
6936 outline0("LDA (TMPPTR),Y");
6937 outline1("STA %s", address_displacement(_environment, _source, step1));
6938 outline1("LDY #$%2.2x", stepIndex + 2 );
6939 outline0("LDA (TMPPTR),Y");
6940 outline1("STA %s", address_displacement(_environment, _source, step2));
6941 outline1("LDY #$%2.2x", stepIndex + 3 );
6942 outline0("LDA (TMPPTR),Y");
6943 outline1("STA %s", address_displacement(_environment, _source, step3));
6944 break;
6945 case 24: case 23: case 22: case 21:
6946 case 20: case 19: case 18: case 17:
6947 outline1("LDY #$%2.2x", stepIndex );
6948 outline0("LDA (TMPPTR),Y");
6949 outline1("STA %s", address_displacement(_environment, _source, step));
6950 outline1("LDY #$%2.2x", stepIndex + 1 );
6951 outline0("LDA (TMPPTR),Y");
6952 outline1("STA %s", address_displacement(_environment, _source, step1));
6953 outline1("LDY #$%2.2x", stepIndex + 2 );
6954 outline0("LDA (TMPPTR),Y");
6955 outline1("STA %s", address_displacement(_environment, _source, step2));
6956 break;
6957 case 16: case 15: case 14: case 13:
6958 case 12: case 11: case 10: case 9:
6959 outline1("LDY #$%2.2x", stepIndex );
6960 outline0("LDA (TMPPTR),Y");
6961 outline1("STA %s", address_displacement(_environment, _source, step));
6962 outline1("LDY #$%2.2x", stepIndex + 1 );
6963 outline0("LDA (TMPPTR),Y");
6964 outline1("STA %s", address_displacement(_environment, _source, step1));
6965 break;
6966 case 8: case 7: case 6: case 5:
6967 case 4: case 3: case 2: case 1:
6968 outline1("LDY #$%2.2x", stepIndex );
6969 outline0("LDA (TMPPTR),Y");
6970 outline1("STA %s", address_displacement(_environment, _source, step));
6971 break;
6972 }
6973 _n = 0;
6974 }
6975 }
6976
6977}
6978
6979
6980void cpu_move_8bit_indirect2_8bit( Environment * _environment, char * _value, char * _offset, char *_source ) {
6981
6983
6984 outline1("LDA #<%s", _value);
6985 outline0("STA TMPPTR");
6986 outline1("LDA #>%s", _value);
6987 outline0("STA TMPPTR+1");
6988 outline1("LDY %s", _offset );
6989 outline0("LDA (TMPPTR),Y");
6990 outline1("STA %s", _source);
6991
6993
6994}
6995
6996void cpu_move_8bit_indirect2_16bit( Environment * _environment, char * _value, char * _offset, char *_source ) {
6997
6999
7000 outline0("CLC");
7001 outline1("LDA #<%s", _value);
7002 outline1("ADC %s", address_displacement( _environment, _offset, "0" ) );
7003 outline0("STA TMPPTR");
7004 outline1("LDA #>%s", _value);
7005 outline1("ADC %s", address_displacement( _environment, _offset, "1" ) );
7006 outline0("STA TMPPTR+1");
7007 outline0("LDY #0" );
7008 outline0("LDA (TMPPTR),Y");
7009 outline1("STA %s", _source);
7010
7012
7013}
7014
7015void cpu_uppercase( Environment * _environment, char *_source, char *_size, char *_result ) {
7016
7018
7019 inline( cpu_uppercase )
7020
7021 outline0("LDY #$0" );
7022 outline1("LDA %s", address_displacement(_environment, _source, "1") );
7023 outline0("STA TMPPTR+1" );
7024 outline1("LDA %s", _source );
7025 outline0("STA TMPPTR" );
7026 if ( _result ) {
7027 outline1("LDA %s", address_displacement(_environment, _result, "1") );
7028 outline0("STA TMPPTR2+1" );
7029 outline1("LDA %s", _result );
7030 outline0("STA TMPPTR2" );
7031 } else {
7032 outline1("LDA %s", address_displacement(_environment, _source, "1") );
7033 outline0("STA TMPPTR2+1" );
7034 outline1("LDA %s", _source );
7035 outline0("STA TMPPTR2" );
7036 }
7037 outhead1("%supper:", label );
7038 outline0("LDA (TMPPTR), Y" );
7039
7040 outline0("CMP #65");
7041 outline1("BCC %snext", label);
7042
7043 outline0("CMP #90");
7044 outline1("BCS %snext", label);
7045
7046 outline0("CLC");
7047 outline0("ADC #128");
7048
7049 outhead1("%snext:", label );
7050 outline0("STA (TMPPTR2), Y" );
7051 outline0("INY" );
7052 outline1("CPY %s", _size );
7053 outline1("BNE %supper", label );
7054
7056
7057 outline1("LDX %s", _size );
7058 outline1("LDA %s", address_displacement(_environment, _source, "1") );
7059 outline0("STA TMPPTR+1" );
7060 outline1("LDA %s", _source );
7061 outline0("STA TMPPTR" );
7062 if ( _result ) {
7063 outline1("LDA %s", address_displacement(_environment, _result, "1") );
7064 outline0("STA TMPPTR2+1" );
7065 outline1("LDA %s", _result );
7066 outline0("STA TMPPTR2" );
7067 } else {
7068 outline1("LDA %s", address_displacement(_environment, _source, "1") );
7069 outline0("STA TMPPTR2+1" );
7070 outline1("LDA %s", _source );
7071 outline0("STA TMPPTR2" );
7072 }
7073 outline0("JSR CPUUPPERCASE" );
7074
7075 done()
7076}
7077
7078void cpu_lowercase( Environment * _environment, char *_source, char *_size, char *_result ) {
7079
7081
7082 inline( cpu_lowercase )
7083
7084 outline0("LDY #$0" );
7085 outline1("LDA %s", address_displacement(_environment, _source, "1") );
7086 outline0("STA TMPPTR+1" );
7087 outline1("LDA %s", _source );
7088 outline0("STA TMPPTR" );
7089 if ( _result ) {
7090 outline1("LDA %s", address_displacement(_environment, _result, "1") );
7091 outline0("STA TMPPTR2+1" );
7092 outline1("LDA %s", _result );
7093 outline0("STA TMPPTR2" );
7094 } else {
7095 outline1("LDA %s", address_displacement(_environment, _source, "1") );
7096 outline0("STA TMPPTR2+1" );
7097 outline1("LDA %s", _source );
7098 outline0("STA TMPPTR2" );
7099 }
7100 outhead1("%slower:", label );
7101 outline0("LDA (TMPPTR), Y" );
7102
7103 outline0("CMP #193");
7104 outline1("BCC %snext", label);
7105
7106 outline0("CMP #218");
7107 outline1("BCS %snext", label);
7108
7109 outline0("SEC");
7110 outline0("SBC #128");
7111
7112 outhead1("%snext:", label );
7113 outline0("STA (TMPPTR2), Y" );
7114 outline0("INY" );
7115 outline1("CPY %s", _size );
7116 outline1("BNE %slower", label );
7117
7119
7120 outline1("LDX %s", _size );
7121 outline1("LDA %s", address_displacement(_environment, _source, "1") );
7122 outline0("STA TMPPTR+1" );
7123 outline1("LDA %s", _source );
7124 outline0("STA TMPPTR" );
7125 if ( _result ) {
7126 outline1("LDA %s", address_displacement(_environment, _result, "1") );
7127 outline0("STA TMPPTR2+1" );
7128 outline1("LDA %s", _result );
7129 outline0("STA TMPPTR2" );
7130 } else {
7131 outline1("LDA %s", address_displacement(_environment, _source, "1") );
7132 outline0("STA TMPPTR2+1" );
7133 outline1("LDA %s", _source );
7134 outline0("STA TMPPTR2" );
7135 }
7136 outline0("JSR CPULOWERCASE" );
7137
7138 done()
7139
7140}
7141
7142void cpu_convert_string_into_8bit( Environment * _environment, char * _string, char * _len, char * _value ) {
7143
7145
7147
7149
7150 outline1("LDA %s", address_displacement(_environment, _string, "1") );
7151 outline0("STA TMPPTR+1" );
7152 outline1("LDA %s", _string );
7153 outline0("STA TMPPTR" );
7154 outline1("LDX %s", _len );
7155 outline0("JSR CPUCONVERTSTRINGINTO16BIT" );
7156 outline0("LDA CPUCONVERTSTRINGINTO16BIT_VALUE" );
7157 outline1("STA %s", _value );
7158
7159 done()
7160
7161}
7162
7163void cpu_convert_string_into_16bit( Environment * _environment, char * _string, char * _len, char * _value ) {
7164
7166
7168
7169 outline0("LDA #$0" );
7170 outline1("STA %s", _value );
7171 outline1("STA %s", address_displacement(_environment, _value, "1") );
7172
7173 outline1("LDA %s", address_displacement(_environment, _string, "1") );
7174 outline0("STA TMPPTR+1" );
7175 outline1("LDA %s", _string );
7176 outline0("STA TMPPTR" );
7177
7178 outline0("LDY #$0"); // mine
7179
7180 outhead1("%srepeat:", label );
7181
7182 outline0("LDA (TMPPTR),Y" );
7183 outline0("CMP #$39" );
7184 outline1("BCS %send", label);
7185 outline0("CMP #$30" );
7186 outline1("BCC %send", label);
7187 outline0("SBC #$30" );
7188
7189 outline0("CLC");
7190 outline1("ADC %s", _value);
7191 outline1("STA %s", _value);
7192 outline0("LDA #$0");
7193 outline1("ADC %s", address_displacement(_environment, _value, "1"));
7194 outline1("STA %s", address_displacement(_environment, _value, "1"));
7195
7196 outline1("LDA %s", address_displacement(_environment, _value, "1") );
7197 outline0("STA TMPPTR2+1" );
7198 outline1("LDA %s", _value );
7199 outline0("STA TMPPTR2" );
7200
7201 outline0("INY");
7202 outline1("CPY %s", _len );
7203 outline1("BEQ %send", label );
7204
7205 outline0("LDA TMPPTR2" );
7206 outline1("STA %s", _value );
7207 outline0("LDA TMPPTR2+1" );
7208 outline1("STA %s", address_displacement(_environment, _value, "1") );
7209 outline1("ASL %s", _value );
7210 outline1("ROL %s", address_displacement(_environment, _value, "1") );
7211 outline1("ASL %s", _value );
7212 outline1("ROL %s", address_displacement(_environment, _value, "1") );
7213 outline0("CLC" );
7214 outline0("LDA TMPPTR2" );
7215 outline1("ADC %s", _value );
7216 outline1("STA %s", _value );
7217 outline0("LDA TMPPTR2+1" );
7218 outline1("ADC %s", address_displacement(_environment, _value, "1") );
7219 outline1("STA %s", address_displacement(_environment, _value, "1") );
7220 outline1("ASL %s", _value );
7221 outline1("ROL %s", address_displacement(_environment, _value, "1") );
7222
7223 outline1("JMP %srepeat", label );
7224
7225 outhead1("%send:", label );
7226
7228
7229 outline1("LDA %s", address_displacement(_environment, _string, "1") );
7230 outline0("STA TMPPTR+1" );
7231 outline1("LDA %s", _string );
7232 outline0("STA TMPPTR" );
7233 outline1("LDX %s", _len );
7234 outline0("JSR CPUCONVERTSTRINGINTO16BIT" );
7235 outline0("LDA CPUCONVERTSTRINGINTO16BIT_VALUE" );
7236 outline1("STA %s", _value );
7237 outline0("LDA CPUCONVERTSTRINGINTO16BIT_VALUE+1" );
7238 outline1("STA %s", address_displacement(_environment, _value, "1") );
7239
7240 done()
7241}
7242
7243void cpu_fill_indirect( Environment * _environment, char * _address, char * _size, char * _pattern, int _size_size ) {
7244
7246
7248
7250
7251 outline1("LDA %s", _address);
7252 outline0("STA TMPPTR");
7253 outline1("LDA %s", address_displacement(_environment, _address, "1"));
7254 outline0("STA TMPPTR+1");
7255
7256 if ( _size_size >= 16 ) {
7257 outline1("LDA %s", _size);
7258 outline0("STA MATHPTR0");
7259 outline1("LDA %s", address_displacement(_environment, _size, "1"));
7260 outline0("STA MATHPTR0+1");
7261 }
7262
7263 if ( _pattern ) {
7264 outline1("LDA %s", _pattern );
7265 } else {
7266 outline0("LDA #0");
7267 }
7268 outline0("STA TMPPTR2");
7269 outline1("LDA %s", address_displacement(_environment, _pattern, "1"));
7270 outline0("STA TMPPTR2+1");
7271 outline0("LDY #0");
7272 outline0("LDA (TMPPTR2),Y");
7273
7274 if ( _size_size >= 16 ) {
7275 outline0("JSR CPUFILL16");
7276 } else {
7277 outline1("LDX %s", _size);
7278 outline0("JSR CPUFILL8");
7279 }
7280
7281 done()
7282
7283}
7284
7285void cpu_flip_8bit( Environment * _environment, char * _source, char * _destination ) {
7286
7288
7290
7291 outline1("LDA %s", _source);
7292 outline0("JSR CPUFLIP8");
7293 if ( _destination ) {
7294 outline1("STA %s", _destination);
7295 } else {
7296 outline1("STA %s", _source);
7297 }
7298
7299 done( )
7300
7301}
7302
7303void cpu_flip( Environment * _environment, char * _source, char * _size, char * _destination ) {
7304
7306
7308
7309 outline1("LDA %s", _source);
7310 outline0("STA TMPPTR");
7311 outline1("LDA %s", address_displacement(_environment, _source, "1"));
7312 outline0("STA TMPPTR+1");
7313
7314 outline1("LDA %s", _destination);
7315 outline0("STA TMPPTR2");
7316 outline1("LDA %s", address_displacement(_environment, _destination, "1"));
7317 outline0("STA TMPPTR2+1");
7318
7319 outline1("LDA %s", _size);
7320 outline0("JSR CPUFLIP");
7321
7322 done( )
7323
7324}
7325
7326void cpu_bit_check( Environment * _environment, char * _value, int _position, char *_result, int _bitwidth ) {
7327
7329
7331
7332 outline1("LDA #<%s", _value);
7333 outline0("STA TMPPTR");
7334 outline1("LDA #>%s", _value );
7335 outline0("STA TMPPTR+1");
7336 outline1("LDA #$%2.2x", _position );
7337 outline0("JSR CPUBITCHECKEXTENDED" );
7338
7339 if ( _result ) {
7340 outline1("STA %s", _result);
7341 }
7342
7343 done( )
7344
7345}
7346
7347void cpu_bit_check_extended( Environment * _environment, char * _value, char * _position, char *_result, int _bitwidth ) {
7348
7350
7352
7354
7355 outline1("LDA #<%s", _value);
7356 outline0("STA TMPPTR");
7357 outline1("LDA #>%s", _value );
7358 outline0("STA TMPPTR+1");
7359 outline1("LDA %s", _position );
7360 outline0("JSR CPUBITCHECKEXTENDED" );
7361
7362 if ( _result ) {
7363 outline1("STA %s", _result);
7364 }
7365
7366 done( )
7367
7368}
7369
7370void cpu_bit_inplace_8bit( Environment * _environment, char * _value, int _position, int * _bit ) {
7371
7372 _environment->bitmaskNeeded = 1;
7373
7375
7376 no_inline( cpu_bit_inplace )
7377
7378 embedded( cpu_bit_inplace, src_hw_6502_cpu_bit_inplace_asm );
7379
7380 if ( !_bit ) {
7381 outline0("PHA");
7382 }
7383 outline1("LDA #<%s", _value);
7384 outline0("STA TMPPTR");
7385 outline1("LDA #>%s", _value );
7386 outline0("STA TMPPTR+1");
7387 if ( _bit ) {
7388 if ( *_bit ) {
7389 outline0("SEC");
7390 } else {
7391 outline0("CLC");
7392 }
7393 } else {
7394 outline0("PLA");
7395 outline0("ROR");
7396 }
7397 outline1("LDA #$%2.2x", _position);
7398 outline0("JSR CPUBITINPLACE");
7399
7400 done( )
7401
7402}
7403
7404void cpu_bit_inplace_8bit_extended_indirect( Environment * _environment, char * _address, char * _position, char * _bit ) {
7405
7406 _environment->bitmaskNeeded = 1;
7407
7409
7410 no_inline( cpu_bit_inplace )
7411
7412 embedded( cpu_bit_inplace, src_hw_6502_cpu_bit_inplace_asm );
7413
7414 if ( !_bit ) {
7415 outline0("PHA");
7416 }
7417 outline1("LDA %s", _address);
7418 outline0("STA TMPPTR");
7419 outline1("LDA %s", address_displacement( _environment, _address, "1" ) );
7420 outline0("STA TMPPTR+1");
7421 if ( _bit ) {
7422 outline1("LDA %s", _bit);
7423 } else {
7424 outline0("PLA");
7425 }
7426 outline1("BEQ %s", label);
7427 outline0("SEC");
7428 outhead1("%s:", label);
7429 outline1("LDA %s", _position);
7430 outline0("JSR CPUBITINPLACE");
7431
7432 done( )
7433
7434}
7435
7436void cpu_number_to_string( Environment * _environment, char * _number, char * _string, char * _string_size, int _bits, int _signed ) {
7437
7439
7440 deploy( numberToString, src_hw_6502_number_to_string_asm );
7441
7442 outline1("LDA #<%s", _number );
7443 outline0("STA TMPPTR" );
7444 outline1("LDA #>%s", _number );
7445 outline0("STA TMPPTR+1" );
7446 outline0("LDA #<N2STRINGNUMBER" );
7447 outline0("STA TMPPTR2" );
7448 outline0("LDA #>N2STRINGNUMBER" );
7449 outline0("STA TMPPTR2+1" );
7450 outline1("LDA #$%2.2x", _bits >> 3 );
7451 outline0("STA MATHPTR0" );
7452 outline0("STA N2STRINGBYTES" );
7453 outline0("LDA #0" );
7454 outline0("STA MATHPTR0+1" );
7455 outline0("JSR CPUMEMMOVE" );
7456 outline1("LDA %s", _string );
7457 outline0("STA TMPPTR");
7458 outline1("LDA %s", address_displacement(_environment, _string, "1") );
7459 outline0("STA TMPPTR+1");
7460 if ( _signed ) {
7461 outline0("JSR N2STRING" );
7462 } else {
7463 outline0("JSR N2STRINGGO" );
7464 }
7465
7466 outline0("LDA MATHPTR5" );
7467 outline1("STA %s", _string_size);
7468
7469}
7470
7471void cpu_bits_to_string( Environment * _environment, char * _number, char * _string, char * _string_size, int _bits, char * _zero, char * _one ) {
7472
7474
7475 deploy( bitsToString, src_hw_6502_bits_to_string_asm );
7476
7477 if ( _zero ) {
7478 outline1("LDA %s", _zero);
7479 } else {
7480 outline0("LDA #'0'" );
7481 }
7482 outline0("STA BINTOSTRDIGIT0+1" );
7483
7484 if ( _one ) {
7485 outline1("LDA %s", _one);
7486 } else {
7487 outline0("LDA #'1'" );
7488 }
7489 outline0("STA BINTOSTRDIGIT1+1" );
7490
7491 outline1("LDA #<%s", _number);
7492 outline0("STA TMPPTR");
7493 outline1("LDA #>%s", _number);
7494 outline0("STA TMPPTR+1");
7495 outline1("LDA %s", _string);
7496 outline0("STA TMPPTR2");
7497 outline1("LDA %s+1", _string);
7498 outline0("STA TMPPTR2+1");
7499
7500 outline1("LDA #$%2.2x", _bits);
7501 outline1("STA %s", _string_size);
7502 outline0("JSR BINTOSTR");
7503
7504}
7505
7506void cpu_hex_to_string_calc_string( Environment * _environment, char * _size, int _separator, char * _string_size ) {
7507
7509
7511
7512 outline1("LDA %s", _size);
7513 outline0("STA CPUMATHMUL8BITTO16BIT_SOURCE");
7514 outline1("LDA #$%2.2x", 2+(_separator?1:0));
7515 outline0("STA CPUMATHMUL8BITTO16BIT_DESTINATION");
7516 outline0("JSR CPUMATHMUL8BITTO16BIT")
7517 outline0("LDA CPUMATHMUL8BITTO16BIT_OTHER");
7518 outline1("STA %s", _string_size );
7519
7520}
7521
7522void cpu_hex_to_string_calc_string_size( Environment * _environment, int _size, int _separator, char * _string_size ) {
7523
7525
7527
7528 outline1("LDA #$%2.2x", (unsigned char)(_size & 0xff));
7529 outline0("STA CPUMATHMUL8BITTO16BIT_SOURCE");
7530 outline1("LDA #$%2.2x", 2+(_separator?1:0));
7531 outline0("STA CPUMATHMUL8BITTO16BIT_DESTINATION");
7532 outline0("JSR CPUMATHMUL8BITTO16BIT")
7533 outline0("LDA CPUMATHMUL8BITTO16BIT_OTHER");
7534 outline1("STA %s", _string_size );
7535
7536}
7537
7538void cpu_hex_to_string( Environment * _environment, char * _number, char * _string, char * _size, int _separator ) {
7539
7541
7542 inline( cpu_hex_to_string )
7543
7545
7546 outline1("LDY #$%2.2x", (unsigned char)( _separator * 3 ) );
7547 outline1("LDX %s", _size );
7548 outline1("LDA %s", _number );
7549 outline0("STA TMPPTR" );
7550 outline1("LDA %s", address_displacement( _environment, _number, "1" ) );
7551 outline0("STA TMPPTR+1" );
7552 outline1("LDA %s", _string );
7553 outline0("STA TMPPTR2" );
7554 outline1("LDA %s", address_displacement(_environment, _string, "1") );
7555 outline0("STA TMPPTR2+1" );
7556
7557 outline0("JSR H2STRING" );
7558
7559 done()
7560}
7561
7562void cpu_dsdefine( Environment * _environment, char * _string, char * _index ) {
7563
7565 deploy( dstring, src_hw_6502_dstring_asm );
7566
7567 outline1( "LDA #<%s", _string );
7568 outline0( "STA DSADDRLO" );
7569 outline1( "LDA #>%s", _string );
7570 outline0( "STA DSADDRHI" );
7571 outline0( "JSR DSDEFINE" );
7572 outline1( "STX %s", _index );
7573
7574}
7575
7576void cpu_dsalloc( Environment * _environment, char * _size, char * _index ) {
7577
7579 deploy( dstring, src_hw_6502_dstring_asm );
7580
7581 outline1( "LDA %s", _size );
7582 outline0( "STA DSSIZE" );
7583 outline0( "JSR DSALLOC" );
7584 outline1( "STX %s", _index );
7585
7586}
7587
7588void cpu_dsalloc_size( Environment * _environment, int _size, char * _index ) {
7589
7591 deploy( dstring, src_hw_6502_dstring_asm );
7592
7593 outline1( "LDA #$%2.2x", _size );
7594 outline0( "STA DSSIZE" );
7595 outline0( "JSR DSALLOC" );
7596 outline1( "STX %s", _index );
7597
7598}
7599
7600void cpu_dsfree( Environment * _environment, char * _index ) {
7601
7603 deploy( dstring, src_hw_6502_dstring_asm );
7604
7605 outline1( "LDX %s", _index );
7606 outline0( "JSR DSFREE" );
7607
7608}
7609
7610void cpu_dswrite( Environment * _environment, char * _index ) {
7611
7613 deploy( dstring, src_hw_6502_dstring_asm );
7614
7615 outline1( "LDX %s", _index );
7616 outline0( "JSR DSWRITE" );
7617
7618}
7619
7620void cpu_dsresize( Environment * _environment, char * _index, char * _resize ) {
7621
7623 deploy( dstring, src_hw_6502_dstring_asm );
7624
7625 outline1( "LDX %s", _index );
7626 outline1( "LDA %s", _resize );
7627 outline0( "STA DSSIZE" );
7628 outline0( "JSR DSRESIZE" );
7629
7630}
7631
7632void cpu_dsresize_size( Environment * _environment, char * _index, int _resize ) {
7633
7636
7637 outline1( "LDX %s", _index );
7638 outline1( "LDA #$%2.2x", _resize );
7639 outline0( "STA DSSIZE" );
7640 outline0( "JSR DSRESIZE" );
7641
7642}
7643
7644void cpu_dsgc( Environment * _environment ) {
7645
7648
7649 outline0( "JSR DSGC" );
7650
7651}
7652
7653void cpu_dsinit( Environment * _environment ) {
7654
7657
7658 outline0( "JSR DSINIT" );
7659
7660}
7661
7662void cpu_dsdescriptor( Environment * _environment, char * _index, char * _address, char * _size ) {
7663
7666
7667 if ( _address || _size ) {
7668 outline1( "LDX %s", _index );
7669 outline0( "JSR DSDESCRIPTOR" );
7670 if ( _address ) {
7671 outline0( "LDA DSADDRLO" );
7672 outline1( "STA %s", _address );
7673 outline0( "LDA DSADDRHI" );
7674 outline1( "STA %s", address_displacement(_environment, _address, "1") );
7675 }
7676 if ( _size ) {
7677 outline0( "LDA DSSIZE" );
7678 outline1( "STA %s", _size );
7679 }
7680 }
7681
7682}
7683
7684void cpu_dsassign( Environment * _environment, char * _original, char * _copy ) {
7685
7687 deploy( dstring, src_hw_6502_dstring_asm );
7688
7689 outline1( "LDX %s", _copy );
7690 outline1( "LDY %s", _original );
7691 outline0( "JSR DSASSIGN" );
7692 outline1( "STX %s", _copy );
7693
7694}
7695
7696void cpu_dsassign_string( Environment * _environment, char * _string, char * _copy ) {
7697
7699 deploy( dstring, src_hw_6502_dstring_asm );
7700
7701 outline1( "LDX %s", _copy );
7702 outline1( "LDA #<%s", _string );
7703 outline0( "STA DSADDRLO" );
7704 outline1( "LDA #>%s", _string );
7705 outline0( "STA DSADDRHI" );
7706 outline0( "JSR DSASSIGNSTR" );
7707 outline1( "STX %s", _copy );
7708
7709}
7710
7711void cpu_store_8bit_with_offset( Environment * _environment, char *_destination, int _value, int _offset ) {
7712
7713 outline1("LDY #$%2.2x", _offset);
7714 outline1("LDA #<%s", _destination);
7715 outline0("STA TMPPTR");
7716 outline1("LDA #>%s", _destination);
7717 outline0("STA TMPPTR+1");
7718 outline1("LDA #$%2.2x", _value);
7719 outline0("STA (TMPPTR),Y");
7720
7721}
7722
7723void cpu_store_8bit_with_offset2( Environment * _environment, char *_destination, char * _offset, int _value ) {
7724
7725 outline1("LDY %s", _offset);
7726 outline1("LDA #<%s", _destination);
7727 outline0("STA TMPPTR");
7728 outline1("LDA #>%s", _destination);
7729 outline0("STA TMPPTR+1");
7730 outline1("LDA #$%2.2x", _value);
7731 outline0("STA (TMPPTR),Y");
7732
7733}
7734
7735void cpu_complement2_8bit( Environment * _environment, char * _source, char * _destination ) {
7736 outline1( "LDA %s", _source );
7737 outline0( "EOR #$FF" );
7738 if ( _destination ) {
7739 outline1( "STA %s", _destination );
7740 } else {
7741 outline1( "STA %s", _source );
7742 }
7743 if ( _destination ) {
7744 cpu_inc( _environment, _destination );
7745 } else {
7746 cpu_inc( _environment, _source );
7747 }
7748}
7749
7750void cpu_complement2_16bit( Environment * _environment, char * _source, char * _destination ) {
7751 outline1( "LDA %s", _source );
7752 outline0( "EOR #$FF" );
7753 if ( _destination ) {
7754 outline1( "STA %s", _destination );
7755 } else {
7756 outline1( "STA %s", _source );
7757 }
7758 outline1( "LDA %s", address_displacement(_environment, _source, "1") );
7759 outline0( "EOR #$FF" );
7760 if ( _destination ) {
7761 outline1( "STA %s", address_displacement(_environment, _destination, "1") );
7762 } else {
7763 outline1( "STA %s", address_displacement(_environment, _source, "1") );
7764 }
7765 if ( _destination ) {
7766 cpu_inc_16bit( _environment, _destination );
7767 } else {
7768 cpu_inc_16bit( _environment, _source );
7769 }
7770}
7771
7772void cpu_complement2_32bit( Environment * _environment, char * _source, char * _destination ) {
7773 outline1( "LDA %s", _source );
7774 outline0( "EOR #$FF" );
7775 if ( _destination ) {
7776 outline1( "STA %s", _destination );
7777 } else {
7778 outline1( "STA %s", _source );
7779 }
7780 outline1( "LDA %s", address_displacement(_environment, _source, "1") );
7781 outline0( "EOR #$FF" );
7782 if ( _destination ) {
7783 outline1( "STA %s", address_displacement(_environment, _destination, "1") );
7784 } else {
7785 outline1( "STA %s", address_displacement(_environment, _source, "1") );
7786 }
7787 outline1( "LDA %s", address_displacement(_environment, _source, "2") );
7788 outline0( "EOR #$FF" );
7789 if ( _destination ) {
7790 outline1( "STA %s", address_displacement(_environment, _destination, "2") );
7791 } else {
7792 outline1( "STA %s", address_displacement(_environment, _source, "2") );
7793 }
7794 outline1( "LDA %s", address_displacement(_environment, _source, "3") );
7795 outline0( "EOR #$FF" );
7796 if ( _destination ) {
7797 outline1( "STA %s", address_displacement(_environment, _destination, "3") );
7798 } else {
7799 outline1( "STA %s", address_displacement(_environment, _source, "3") );
7800 }
7801 if ( _destination ) {
7802 cpu_inc_32bit( _environment, _destination );
7803 } else {
7804 cpu_inc_32bit( _environment, _source );
7805 }
7806
7807}
7808
7809void cpu_complement2_nbit( Environment * _environment, char * _source, char * _destination, int _bits ) {
7810
7811 for( int i=0; i<(_bits>>3); ++i ) {
7812 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
7813 outline1( "LDA %s", address_displacement(_environment, _source, offset) );
7814 outline0( "EOR #$FF" );
7815 if ( _destination ) {
7816 outline1( "STA %s", address_displacement(_environment, _destination, "1") );
7817 } else {
7818 outline1( "STA %s", address_displacement(_environment, _source, "1") );
7819 }
7820 }
7821 if ( _destination ) {
7822 cpu_inc_nbit( _environment, _destination, _bits );
7823 } else {
7824 cpu_inc_nbit( _environment, _source, _bits );
7825 }
7826
7827}
7828
7829void cpu_sqroot( Environment * _environment, char * _number, char * _result ) {
7830
7832
7833 outline1("LDA %s", _number );
7834 outline0("STA Numberl" );
7835 outline1("LDA %s", address_displacement(_environment, _number, "1") );
7836 outline0("STA Numberh" );
7837
7838 outline0("JSR SQROOT" );
7839
7840 outline0("LDA Root" );
7841 outline1("STA %s", _result );
7842
7843}
7844
7845void emit_segment_if_enough_space( Environment * _environment, int _space ) {
7846 MemoryArea * actual = _environment->memoryAreas;
7847 int id = 0;
7848 while( actual ) {
7849 if ( actual->size > _space ) {
7850 outhead1(".segment \"MA%3.3x\"", id );
7851 actual->size -= _space;
7852 break;
7853 }
7854 actual = actual->next;
7855 ++id;
7856 }
7857}
7858
7859void cpu_dstring_vars( Environment * _environment ) {
7860
7861 int count = _environment->dstring.count == 0 ? DSTRING_DEFAULT_COUNT : _environment->dstring.count;
7862 int space = _environment->dstring.space == 0 ? DSTRING_DEFAULT_SPACE : _environment->dstring.space;
7863
7864 emit_segment_if_enough_space( _environment, 1 );
7865 outhead1("stringscount = %d", count );
7866 outhead1("stringsspace = %d", space );
7867 outhead0("MAXSTRINGS: .BYTE stringscount" );
7868 outhead0(".segment \"CODE\"" );
7869
7870 emit_segment_if_enough_space( _environment, count );
7871 outhead0("DESCRIPTORS_STATUS: .RES stringscount,0" );
7872 outhead0(".segment \"CODE\"" );
7873
7874 emit_segment_if_enough_space( _environment, count );
7875 outhead0("DESCRIPTORS_ADDRESS_LO: .RES stringscount,0" );
7876 outhead0(".segment \"CODE\"" );
7877
7878 emit_segment_if_enough_space( _environment, count );
7879 outhead0("DESCRIPTORS_ADDRESS_HI: .RES stringscount,0" );
7880 outhead0(".segment \"CODE\"" );
7881
7882 emit_segment_if_enough_space( _environment, count );
7883 outhead0("DESCRIPTORS_SIZE: .RES stringscount,0" );
7884 outhead0(".segment \"CODE\"" );
7885
7886 emit_segment_if_enough_space( _environment, space );
7887 outhead0("WORKING: .RES stringsspace,0" );
7888 outhead0(".segment \"CODE\"" );
7889
7890 emit_segment_if_enough_space( _environment, space );
7891 outhead0("TEMPORARY: .RES stringsspace,0" );
7892 outhead0(".segment \"CODE\"" );
7893
7894 emit_segment_if_enough_space( _environment, 2 );
7895 outhead0("FREE_STRING: .WORD (stringsspace-1)" );
7896 outhead0(".segment \"CODE\"" );
7897
7898
7899}
7900
7901void cpu_protothread_vars( Environment * _environment ) {
7902
7903 int count = _environment->protothreadConfig.count;
7904
7905 outhead1("PROTOTHREADLC: .RES %d,0", count );
7906 outhead1("PROTOTHREADST: .RES %d,0", count );
7907 outhead0("PROTOTHREADCT: .BYTE 0" );
7908 outhead0("PROTOTHREADLOOP:");
7909
7910 for( int i=0; i<count; ++i ) {
7911 outline1("LDX #%d", i );
7912 outline0("STX PROTOTHREADCT" );
7913 outline0("JSR PROTOTHREADVOID" );
7914 }
7915
7916 outline0("RTS" );
7917
7918}
7919
7920void cpu_protothread_loop( Environment * _environment ) {
7921
7923
7924 outline0("JSR PROTOTHREADLOOP" );
7925
7926}
7927
7928void cpu_protothread_register_at( Environment * _environment, char * _index, char * _label ) {
7929
7931
7932 outline1("LDA #<%s", _label );
7933 outline0("STA TMPPTR" );
7934 outline1("LDA #>%s", _label );
7935 outline0("STA TMPPTR+1" );
7936 outline1("LDY %s", _index );
7937
7938 outline0("JSR PROTOTHREADREGAT" );
7939
7940}
7941
7942void cpu_protothread_register( Environment * _environment, char * _label, char * _index ) {
7943
7945
7946 outline1("LDA #<%s", _label );
7947 outline0("STA TMPPTR" );
7948 outline1("LDA #>%s", _label );
7949 outline0("STA TMPPTR+1" );
7950
7951 outline0("JSR PROTOTHREADREG" );
7952
7953 outline1("STY %s", _index );
7954
7955}
7956
7957void cpu_protothread_unregister( Environment * _environment, char * _index ) {
7958
7960
7961 outline1("LDY %s", _index );
7962
7963 outline0("JSR PROTOTHREADUNREG" );
7964
7965}
7966
7967void cpu_protothread_save( Environment * _environment, char * _index, int _step ) {
7968
7970
7971 outline1("LDY %s", _index );
7972 outline1("LDX #$%2.2x", _step );
7973
7974 outline0("JSR PROTOTHREADSAVE" );
7975
7976}
7977
7978void cpu_protothread_restore( Environment * _environment, char * _index, char * _step ) {
7979
7981
7982 outline1("LDY %s", _index );
7983
7984 outline0("JSR PROTOTHREADRESTORE" );
7985
7986 outline1("STX %s", _step );
7987
7988}
7989
7990void cpu_protothread_set_state( Environment * _environment, char * _index, int _state ) {
7991
7993
7994 outline1("LDY %s", _index );
7995 outline1("LDX #$%2.2x", _state );
7996
7997 outline0("JSR PROTOTHREADSETSTATE" );
7998
7999}
8000
8001void cpu_protothread_get_state( Environment * _environment, char * _index, char * _state ) {
8002
8004
8005 outline1("LDY %s", _index );
8006
8007 outline0("JSR PROTOTHREADGETSTATE" );
8008
8009 outline1("STX %s", _state );
8010
8011}
8012
8013void cpu_protothread_current( Environment * _environment, char * _current ) {
8014
8016
8017 outline0("LDX PROTOTHREADCT" );
8018 outline1("STX %s", _current );
8019
8020}
8021
8022void cpu_protothread_get_address( Environment * _environment, char * _index, char * _address ) {
8023
8025
8026 outline1("LDY %s", _index );
8027
8028 outline0("JSR PROTOTHREADGETADDRESS" );
8029
8030 outline0("LDA TMPPTR" );
8031 outline1("STA %s", _address );
8032 outline0("LDA TMPPTR+1" );
8033 outline1("STA %s", address_displacement( _environment, _address, "1" ) );
8034
8035}
8036
8037void cpu_set_callback( Environment * _environment, char * _callback, char * _label ) {
8038
8039 outline1("LDA #<(%s)", address_displacement(_environment, _callback, "1"));
8040 outline0("STA TMPPTR");
8041 outline1("LDA #>(%s)", address_displacement(_environment, _callback, "1"));
8042 outline0("STA TMPPTR+1");
8043 outline0("LDY #0");
8044 outline1("LDA #<%s", _label);
8045 outline0("STA (TMPPTR), Y");
8046 outline0("INY");
8047 outline1("LDA #>%s", _label);
8048 outline0("STA (TMPPTR), Y");
8049
8050}
8051
8052void cpu_msc1_uncompress_direct_direct( Environment * _environment, char * _input, char * _output ) {
8053
8055
8056 inline( cpu_msc1_uncompress )
8057
8058 embedded( cpu_msc1_uncompress, src_hw_6502_msc1_asm );
8059
8060 outline1("LDA #<%s", _input);
8061 outline0("STA TMPPTR");
8062 outline1("LDA #>%s", _input);
8063 outline0("STA TMPPTR+1");
8064 outline1("LDA #<%s", _output);
8065 outline0("STA TMPPTR2");
8066 outline1("LDA #>%s", _output);
8067 outline0("STA TMPPTR2+1");
8068
8069 outline0("JSR MSC1UNCOMPRESS");
8070
8071 done()
8072
8073}
8074
8075void cpu_msc1_uncompress_direct_indirect( Environment * _environment, char * _input, char * _output ) {
8076
8078
8079 inline( cpu_msc1_uncompress )
8080
8081 embedded( cpu_msc1_uncompress, src_hw_6502_msc1_asm );
8082
8083 outline1("LDA #<%s", _input);
8084 outline0("STA TMPPTR");
8085 outline1("LDA #>%s", _input);
8086 outline0("STA TMPPTR+1");
8087 outline1("LDA %s", _output);
8088 outline0("STA TMPPTR2");
8089 outline1("LDA %s", address_displacement(_environment, _output, "1"));
8090 outline0("STA TMPPTR2+1");
8091
8092 outline0("JSR MSC1UNCOMPRESS");
8093
8094 done()
8095
8096}
8097
8098void cpu_msc1_uncompress_indirect_direct( Environment * _environment, char * _input, char * _output ) {
8099
8101
8102 inline( cpu_msc1_uncompress )
8103
8104 embedded( cpu_msc1_uncompress, src_hw_6502_msc1_asm );
8105
8106 outline1("LDA %s", _input);
8107 outline0("STA TMPPTR");
8108 outline1("LDA %s", address_displacement(_environment, _input, "1"));
8109 outline0("STA TMPPTR+1");
8110 outline1("LDA #<%s", _output);
8111 outline0("STA TMPPTR2");
8112 outline1("LDA #>%s", _output);
8113 outline0("STA TMPPTR2+1");
8114
8115 outline0("JSR MSC1UNCOMPRESS");
8116
8117 done()
8118
8119}
8120
8121void cpu_msc1_uncompress_indirect_indirect( Environment * _environment, char * _input, char * _output ) {
8122
8124
8125 inline( cpu_msc1_uncompress )
8126
8127 embedded( cpu_msc1_uncompress, src_hw_6502_msc1_asm );
8128
8129 outline1("LDA %s", _input);
8130 outline0("STA TMPPTR");
8131 outline1("LDA %s", address_displacement(_environment, _input, "1"));
8132 outline0("STA TMPPTR+1");
8133 outline1("LDA %s", _output);
8134 outline0("STA TMPPTR2");
8135 outline1("LDA %s", address_displacement(_environment, _output, "1"));
8136 outline0("STA TMPPTR2+1");
8137
8138 outline0("JSR MSC1UNCOMPRESS");
8139
8140 done()
8141
8142}
8143
8144void cpu_out( Environment * _environment, char * _port, char * _value ) {
8145
8146}
8147
8148void cpu_in( Environment * _environment, char * _port, char * _value ) {
8149
8150}
8151
8152void cpu_out_direct( Environment * _environment, char * _port, char * _value ) {
8153
8154}
8155
8156void cpu_in_direct( Environment * _environment, char * _port, char * _value ) {
8157
8158}
8159
8160void cpu_string_sub( Environment * _environment, char * _source, char * _source_size, char * _pattern, char * _pattern_size, char * _destination, char * _destination_size ) {
8161
8163
8164 inline( cpu_string_sub )
8165
8167
8168 outline1("LDA %s", _source);
8169 outline0("STA TMPPTR");
8170 outline1("LDA %s", address_displacement(_environment, _source, "1"));
8171 outline0("STA TMPPTR+1");
8172 outline1("LDA %s", _source_size);
8173 outline0("STA MATHPTR0");
8174 outline1("LDA %s", _pattern);
8175 outline0("STA TMPPTR2");
8176 outline1("LDA %s", address_displacement(_environment, _pattern, "1"));
8177 outline0("STA TMPPTR2+1");
8178 outline1("LDA %s", _pattern_size);
8179 outline0("STA MATHPTR1");
8180 outline1("LDA %s", _destination);
8181 outline0("STA MATHPTR4");
8182 outline1("LDA %s", address_displacement(_environment, _destination, "1"));
8183 outline0("STA MATHPTR4+1");
8184
8185 outline0("JSR CPUSTRINGSUB");
8186
8187 outline0("LDA MATHPTR2");
8188 outline1("STA %s", _destination_size);
8189
8190 done()
8191}
8192
8193static char cpu_BLIT_REGISTER[][9] = {
8194 "BLITR0",
8195 "BLITR1",
8196 "BLITR2",
8197 "BLITR3"
8198};
8199
8200#define cpu_BLIT_REGISTER_COUNT ( sizeof( cpu_BLIT_REGISTER ) / 9 )
8201
8202void cpu_blit_initialize( Environment * _environment ) {
8203
8204 _environment->blit.freeRegisters = 0;
8205 _environment->blit.usedMemory = 0;
8206
8207}
8208
8209void cpu_blit_finalize( Environment * _environment ) {
8210
8211 _environment->blit.freeRegisters = 0;
8212 _environment->blit.usedMemory = 0;
8213
8214}
8215
8216char * cpu_blit_register_name( Environment * _environment, int _register ) {
8217
8218 if ( _register < cpu_BLIT_REGISTER_COUNT ) {
8219 return &cpu_BLIT_REGISTER[_register][0];
8220 } else {
8221 return &cpu_BLIT_REGISTER[ (_register & 0xff00) >> 8][0];
8222 }
8223}
8224
8226
8227 int reg = 0;
8228
8229 for( reg = 0; reg < cpu_BLIT_REGISTER_COUNT; ++reg ) {
8230 int registerMask = ( 0x01 << reg );
8231 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
8232 if ( ! isRegisterUsed ) {
8233 _environment->blit.freeRegisters |= registerMask;
8234 // printf( "cpu_blit_alloc_register() %4.4x -> $%4.4x\n", _environment->blit.freeRegisters, reg );
8235 return reg;
8236 }
8237 }
8238
8239 int location = _environment->blit.usedMemory++;
8240
8241 if ( location > 0xff ) {
8243 }
8244
8245 for( reg = 0; reg < cpu_BLIT_REGISTER_COUNT; ++reg ) {
8246 int registerMask = ( 0x10 << reg );
8247 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
8248 if ( ! isRegisterUsed ) {
8249 outline1( "LDA %s", &cpu_BLIT_REGISTER[reg][0] );
8250 outline2( "STA %sbs+$%2.2x", _environment->blit.realName, location );
8251 _environment->blit.freeRegisters |= registerMask;
8252 // printf( "cpu_blit_alloc_register() -> %4.4x $%4.4x\n", _environment->blit.freeRegisters, ( ( reg << 8 ) | location ) );
8253 return ( ( (reg+1) << 8 ) | location );
8254 }
8255 }
8256
8258
8259}
8260
8261void cpu_blit_free_register( Environment * _environment, int _register ) {
8262
8263 // printf( "cpu_blit_free_register($%4.4x)\n", _register );
8264
8265 int location = _register & 0xff;
8266 int reg;
8267
8268 if ( _register < cpu_BLIT_REGISTER_COUNT ) {
8269 int registerMask = ( 0x01 << _register );
8270 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
8271 if ( isRegisterUsed ) {
8272 _environment->blit.freeRegisters &= ~registerMask;
8273 return;
8274 } else {
8275 CRITICAL_BLIT_INVALID_FREE_REGISTER( _environment->blit.name, _register );
8276 }
8277 } else {
8278 int registerMask = 0x10 << ( ( ( _register >> 8 ) & 0xff ) - 1 );
8279 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
8280 if ( isRegisterUsed ) {
8281 outline2( "LDA (%sbs+$%2.2x)", _environment->blit.realName, location );
8282 outline1( "LDA %s", &cpu_BLIT_REGISTER[reg][0] );
8283 _environment->blit.freeRegisters &= ~registerMask;
8284 return;
8285 }
8286 }
8287
8288 CRITICAL_BLIT_INVALID_FREE_REGISTER( _environment->blit.name, _register );
8289
8290}
8291
8300void cpu_store_nbit( Environment * _environment, char *_destination, int _n, int _value[] ) {
8301
8302 int i = 0;
8303 while( _n ) {
8304 char destinationAddress[MAX_TEMPORARY_STORAGE]; sprintf( destinationAddress, "%s+%d", _destination, i*4 );
8305 if ( _n <= 32 ) {
8306 switch( _n ) {
8307 case 1: case 2: case 3: case 4:
8308 case 5: case 6: case 7: case 8:
8309 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)] & (0xff>>(8-_n)) ) );
8310 break;
8311 case 9: case 10: case 11: case 12:
8312 case 13: case 14: case 15: case 16:
8313 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)] & (0xff) ) );
8314 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
8315 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)+1] & (0xff>>(16-_n)) ) );
8316 break;
8317 case 17: case 18: case 19: case 20:
8318 case 21: case 22: case 23: case 24:
8319 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)] & (0xff) ) );
8320 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
8321 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)+1] & (0xff) ) );
8322 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
8323 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)+2] & (0xff>>(24-_n)) ) );
8324 break;
8325 case 25: case 26: case 27: case 28:
8326 case 29: case 30: case 31: case 32:
8327 default:
8328 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)] & (0xff) ) );
8329 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
8330 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)+1] & (0xff) ) );
8331 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
8332 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)+2] & (0xff) ) );
8333 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
8334 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)+3] & (0xff>>(32-_n)) ) );
8335 break;
8336 }
8337 _n = 0;
8338 } else {
8339 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)] & (0xff) ) );
8340 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
8341 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)+1] & (0xff) ) );
8342 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
8343 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)+2] & (0xff) ) );
8344 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
8345 cpu_store_8bit( _environment, destinationAddress, ( _value[(i*4)+3] & (0xff>>(32-_n)) ) );
8346 _n -= 32;
8347 }
8348 ++i;
8349 }
8350
8351
8352}
8353
8354//
8355// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
8356// SINGLE (32) seeeeeee emmmmmmm mmmmmmmm mmmmmmmm
8357//
8358
8359void cpu_float_fast_from_double_to_int_array( Environment * _environment, double _value, int _result[] ) {
8360 cpu_float_single_from_double_to_int_array( _environment, _value, _result );
8361}
8362
8363// const double sonda = 1.0;
8364
8365void cpu_float_single_from_double_to_int_array( Environment * _environment, double _value, int _result[] ) {
8366
8367 double value = 0.0;
8368 double integral = 0.0;
8369 double fractional = 0.0;
8370 int sign = 0;
8371 int left = 0;
8372 int right[3];
8373 int steps = 0;
8374 int exp = 0;
8375 int mantissa_bits = 23;
8376 int mantissaScaled = 0;
8377
8378 // printf("------------------\nVALUE = %f\n", _value );
8379
8380 memset( &_result[0], 0, sizeof( int ) * 4 );
8381 memset( &right[0], 0, sizeof( int ) * 3 );
8382
8383 if ( _value != 0.0 ) {
8384
8385 // Step 1: Determine Sign
8386 // If the number is positive, then the sign bit will be 0. If the number is negative, then the sign bit
8387 // will be 1. For the number zero, both positive and negative zero are possible, and these are considered
8388 // different values (a quirk of using sign bits).
8389
8390 if ( _value >= 0 ) {
8391 sign = 0;
8392 } else {
8393 sign = 1;
8394 }
8395
8396 value = fabs( _value );
8397
8398 // Step 2: Convert the Integral Portion to Unsigned Binary
8399 // Convert the integral portion of the floating-point value to unsigned binary (not two's complement).
8400 // The integral portion is the part of the number before the decimal point. For example, if the
8401 // number to convert is -0.75, then 0 is the integral portion, and it's unsigned binary representation
8402 // is simply 0. As another example, if the number to convert is 127.99, then the integral portion would
8403 // be 127, and it's unsigned binary representation is 1111111.
8404
8405 fractional = modf(value, &integral);
8406
8407 left = (unsigned int) integral;
8408
8409 // if ( _value == sonda ) {
8410 // printf("============================\n" );
8411 // printf("value = %f, left = %d, integral = %f, fractional = %f\n", value, left, integral, fractional );
8412 // }
8413
8414 // Step 3: Convert the Fractional Portion to Binary
8415 // The fractional portion of the number must also be converted to binary, though the conversion process
8416 // is much different from what you're used to. The algorithm you'll used is based on performing repeated
8417 // multiplications by 2, and then checking if the result is >= 1.0. If the result is >= 1.0, then a 1 is
8418 // recorded for the binary fractional component, and the leading 1 is chopped of the result. If the
8419 // result is < 1.0, then a 0 is recorded for the binary fractional component, and the result is kept
8420 // as-is. The recorded builds are built-up left-to-right. The result keeps getting chained along in this
8421 // way until one of the following is true:
8422 // - The result is exactly 1.0
8423 // - 23 iterations of this process have occurred; i.e. the final converted binary value holds 23 bits
8424 // With the first possible terminating condition (the result is exactly 1.0), this means that the fractional
8425 // component has been represented without any loss of precision. With the second possible terminating
8426 // condition (23 iterations have passed), this means that we ran out of bits in the final result, which
8427 // can never exceed 23. In this case, precision loss occurs (an unfortunate consequence of using a finite
8428 // number of bits).
8429
8430 if ( fractional != 0.0 ) {
8431
8432 if ( fractional != 1.0 ) {
8433 exp = -1;
8434 } else {
8435 exp = -2;
8436 }
8437
8438 // mantissaScaled = 1;
8439
8440 // if ( _value == sonda ) {
8441 // printf("%d-) exp = %d right = %2.2x %2.2x %2.2x fractional = %f\n", steps, exp, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2], fractional );
8442 // }
8443
8444 // fractional = fractional * 2;
8445
8446 // if ( fractional > 1.0 ) {
8447 // fractional = modf(fractional, &integral);
8448 // printf("%d!) exp = %d right = %2.2x %2.2x %2.2x fractional = %f\n", steps, exp, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2], fractional );
8449 // ++steps;
8450 // } else {
8451 // fractional = fractional / 2;
8452 // }
8453
8454 while( ( fractional != 1.0 ) && ( steps < mantissa_bits ) ) {
8455
8456 fractional = fractional * 2;
8457
8458 if ( fractional != 1.0 ) {
8459
8460 if ( fractional > 1.0 ) {
8461 right[2] |= 1;
8462 fractional = modf(fractional, &integral);
8463 }
8464
8465 ++steps;
8466
8467 // if ( _value == sonda ) {
8468 // printf("%d) exp = %d right = %2.2x %2.2x %2.2x fractional = %f\n", steps, exp, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2], fractional );
8469 // }
8470
8471 // if ( ( fractional != 1.0 ) && ( steps < mantissa_bits ) ) {
8472
8473 right[2] = right[2] << 1;
8474 right[1] = right[1] << 1;
8475 right[0] = right[0] << 1;
8476 if ( ( right[2] & 0x100 ) ) {
8477 right[1] = right[1] | 0x1;
8478 }
8479 if ( ( right[1] & 0x100 ) ) {
8480 right[0] = right[0] | 0x1;
8481 }
8482 right[2] = right[2] & 0xff;
8483 right[1] = right[1] & 0xff;
8484 right[0] = right[0] & 0xff;
8485
8486 // }
8487
8488 }
8489
8490 }
8491
8492 // if ( _value == sonda ) {
8493 // printf("%d*) exp = %d right = %2.2x %2.2x %2.2x fractional = %f\n", steps, exp, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2], fractional );
8494 // }
8495
8496 }
8497
8498 // Step 4: Normalize the Value via Adjusting the Exponent
8499 // A trick to encode an extra bit is to make it so that the binary scientific representation is always
8500 // of the form 1.XXXX * 2YYYY. That is, a 1 always leads, so there is no need to explicitly encode it.
8501 // In order to encode this properly, we need to move the decimal point to a position where it is
8502 // immediately after the first 1, and then record exactly how we moved it. To see this in action, consider
8503 // again the example of 0.75, which is encoded in binary as such (not IEEE-754 notation):
8504 // 0.11
8505 // In order to make the decimal point be after the first 1, we will need to move it one position to the right, like so:
8506 // 1.1
8507 // Most importantly, we need to record that we moved the decimal point by one position to the right.
8508 // Moves to the right result in negative exponents, and moves to the left result in positive exponents.
8509 // In this case, because we moved the decimal point one position to the right, the recorded exponent should be -1.
8510 // As another example, consider the following binary floating point representation (again, not IEEE-754):
8511 // 1111111.11100
8512 // In this case, we need to move the decimal point six positions to the left to make this begin with a single 1, like so:
8513 // 1.11111111100
8514 // Because this moves six positions to the left, the recorded exponent should be 6.
8515
8516 int mantissa_high_bit = 0x80000000 >> ( 32 - mantissa_bits);
8517 int mantissa_mask = 0xffffffff >> ( 32 - mantissa_bits);
8518
8519 if ( left == 0 ) {
8520
8521 if ( value != 0 && !mantissaScaled ) {
8522
8523 while( left == 0 ) {
8524
8525 // if ( _value == sonda ) {
8526 // printf("a) exp = %d left = %2.2x right = %2.2x %2.2x %2.2x fractional = %f\n", exp, (unsigned char) left, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2], fractional );
8527 // }
8528
8529 if ( ! right[0] && ! right[1] && ! right[2] ) {
8530 left = 0x1;
8531 }
8532
8533 if ( right[0] & 0x80 ) {
8534 left = 0x1;
8535 }
8536
8537 right[0] = right[0] << 1;
8538 right[1] = right[1] << 1;
8539 right[2] = right[2] << 1;
8540 if ( ( right[1] & 0x100 )) {
8541 right[0] = right[0] | 0x1;
8542 }
8543 if ( ( right[2] & 0x100 )) {
8544 right[1] = right[1] | 0x1;
8545 }
8546 right[0] = right[0] & 0xff;
8547 right[1] = right[1] & 0xff;
8548 right[2] = right[2] & 0xff;
8549
8550 --exp;
8551 }
8552
8553 } else {
8554
8555 // exp = -1;
8556
8557 }
8558
8559 // if ( _value == sonda ) {
8560 // printf("ax) exp = %d left = %2.2x right = %2.2x %2.2x %2.2x\n", exp, (unsigned char) left, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2] );
8561 // }
8562
8563 while( left ) {
8564
8565 // if ( _value == sonda ) {
8566 // printf("ay) left = %8.8x right = %2.2x %2.2x %2.2x\n", left, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2] );
8567 // }
8568
8569 if ( ( right[0] & 0x01 ) ) {
8570 right[1] = right[1] | 0x100;
8571 }
8572 if ( ( right[1] & 0x01 ) ) {
8573 right[2] = right[2] | 0x100;
8574 }
8575 right[0] = right[0] >> 1;
8576 right[1] = right[1] >> 1;
8577 right[2] = right[2] >> 1;
8578
8579 // IEEE-754
8580 // if ( ( left & 0x1 ) && left != 1 ) {
8581 if ( ( left & 0x1 ) ) {
8582 right[0] = right[0] | 0x80;
8583 }
8584 left = left >> 1;
8585
8586 if( left ) {
8587 exp = exp + 1;
8588 }
8589
8590 }
8591
8592 // IEEE-754
8593 // ++exp;
8594
8595 } else {
8596
8597 if ( left > 1 ) {
8598 while( left > 1 ) {
8599
8600 // if ( _value == sonda ) {
8601 // printf("bx) exp = %d left = %8.8x right = %2.2x %2.2x %2.2x\n", exp, left, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2] );
8602 // }
8603
8604 if ( ( right[0] & 0x01 ) ) {
8605 right[1] = right[1] | 0x100;
8606 }
8607 if ( ( right[1] & 0x01 ) ) {
8608 right[2] = right[2] | 0x100;
8609 }
8610 right[0] = right[0] >> 1;
8611 right[1] = right[1] >> 1;
8612 right[2] = right[2] >> 1;
8613 if ( ( left & 0x1 ) ) {
8614 right[0] = right[0] | 0x80;
8615 }
8616 left = left >> 1;
8617 ++exp;
8618 }
8619
8620 // ++exp;
8621
8622 }
8623
8624 if ( !sign ) {
8625 --exp;
8626 }
8627
8628 if ( integral == 1.0 && !sign ) {
8629 --exp;
8630 }
8631
8632 // if ( _value == sonda ) {
8633 // printf("bx*) exp = %d left = %8.8x right = %2.2x %2.2x %2.2x\n", exp, left, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2] );
8634 // }
8635
8636 }
8637
8638 // Step 5: Add Bias to the Exponent
8639 // Internally, IEEE-754 values store their exponents in an unsigned representation, which may seem odd considering that
8640 // the exponent can be negative. Negative exponents are accomodated by using a biased representation, wherein a
8641 // pre-set number is always subtracted from the given unsigned number. Because the given unsigned number may be less
8642 // than this number, this allows for negative values to be effectively encoded without resorting to two's complement.
8643 // Specifically, for the binary32 representation, the number 127 will be subtracted from anything encoded in the
8644 // exponent field of the IEEE-754 number. As such, in this step, we need to add 127 to the normalized exponent value
8645 // from the previous step.
8646
8647 // IEEE-754
8648 // exp += 127;
8649 exp += 129;
8650
8651 // if ( _value == sonda ) {
8652 // printf("exp = %2.2x\n", exp );
8653 // }
8654
8655 // Step 6: Convert the Biased Exponent to Unsigned Binary
8656 // The biased exponent value from the previous step must be converted into unsigned binary, using the usual process.
8657 // The result must be exactly 8 bits. It should not be possible to need more than 8 bits. If fewer than 8 bits are
8658 // needed in this conversion process, then leading zeros must be added to the front of the result to produce an
8659 // 8-bit value.
8660
8661 exp = exp & 0xff;
8662
8663 // if ( _value == sonda ) {
8664 // printf("exp = %d\n", exp );
8665 // }
8666
8667 // Step 7: Determine the Final Bits for the Mantissa
8668 // After step 4, there are a bunch of bits after the normalized decimal point. These bits will become the
8669 // mantissa (note that we ignore the bits to the left of the decimal point - normalization allows us to do this,
8670 // because it should always be just a 1). We need exactly 23 mantissa bits. If less than 23 mantissa bits follow the
8671 // decimal point, and the algorithm in step 3 ended with a result that wasn't 1.0, then follow the algorithm in step 3
8672 // until we can fill enough bits. If that's still not enough (eventually reaching 1.0 before we had enough bits, or
8673 // perhaps it had ended with 1.0 already), then the right side can be padded with zeros until 23 bits is reached.
8674 // If there are more than 23 bits after the decimal point in step 4, then these extra bits are simply cutoff from the
8675 // right. For example, if we had 26 bits to the right of the decimal point, then the last three would need to be cutoff
8676 // to get us to 23 bits. Note that in this case we will necessarily lose some precision.
8677
8678 // Step 8: Put it All Together
8679 // The sign bit from step 1 will be the first bit of the final result. The next 8 bits will be from the exponent from
8680 // step 6. The last 23 bits will be from the mantissa from step 7. The result will be a 32-bit number encoded in
8681 // IEEE-754 binary32 format, assuming no mistakes were made in the process.
8682
8683 // [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
8684 // SINGLE (32) seeeeeee emmmmmmm mmmmmmmm mmmmmmmm
8685
8686 // IEEE-754 format
8687 // _result[0] = ( sign << 7 ) | ( exp >> 1 );
8688 // _result[1] = ( ( exp & 0x01 ) << 7 ) | ( right[0] >> 1 );
8689 // _result[2] = ( ( right[0] & 0x01 ) << 7 ) | ( right[1] >> 1 );
8690 // _result[3] = ( ( right[1] & 0x01 ) << 7 ) | ( right[2] >> 1 );
8691
8692 // WOZNIAK format
8693 _result[0] = exp;
8694 _result[1] = ( ( sign & 0x01 ) << 7 ) | ( right[0] >> 1 );
8695 _result[2] = ( ( right[0] & 0x01 ) << 7 ) | ( right[1] >> 1 );
8696 _result[3] = ( ( right[1] & 0x01 ) << 7 ) | ( right[2] >> 1 );
8697
8698 }
8699
8700 // if ( _value == sonda ) {
8701 // printf( "--------------> %f %2.2x %2.2x %2.2x %2.2x\n\n", _value, _result[0], _result[1], _result[2], _result[3] );
8702 // }
8703
8704}
8705void cpu_float_fast_from_int_array_to_double( Environment * _environment, int _value[], double * _result ) {
8706 cpu_float_single_from_int_array_to_double( _environment, _value, _result );
8707}
8708
8709void cpu_float_single_from_int_array_to_double( Environment * _environment, int _value[], double * _result ) {
8710
8711 // printf( " value = %2.2x%2.2x%2.2x%2.2x\n", _value[0], _value[1], _value[2], _value[3] );
8712
8713 // IEEE-754
8714 // int sign = ( ( _value[0] & 0x80 ) ? -1 : 1 );
8715 int sign = ( ( _value[1] & 0x80 ) ? -1 : 1 );
8716
8717 // IEEE-754
8718 // int exp = ( ( _value[0] << 1 ) & 0xff ) | ( ( _value[1] & 0x80 ) ? 0x01 : 0x00 );
8719 // exp = exp - 127;
8720 int exp = _value[0] & 0xff;
8721 exp = exp - 128;
8722
8723 // printf( " exp = %d\n", exp );
8724
8725 int mantissa = ( (( _value[1] & 0x7f ) << 16) | (_value[2] << 8 ) | _value[3] ) << 1;
8726
8727 // printf( " mantissa = %6.6x\n", mantissa );
8728
8729 // IEEE-754
8730 // *_result = 0 * sign;
8731 if ( mantissa == 0 ) {
8732 *_result = 2.0 * sign;
8733 } else {
8734 *_result = 1.0 * sign;
8735 }
8736
8737 double step = 0.5;
8738
8739 for( int i=0; i<24; ++i ) {
8740 // printf( " %i) %f ->", i, *_result );
8741 // IEEE-754
8742 // if ( mantissa & 0x800000 ) {
8743 if ( mantissa & 0x400000 ) {
8744 *_result += (sign * step);
8745 }
8746 // printf( " %f\n", *_result );
8747 step = step / 2;
8748 mantissa = mantissa & 0x3fffff;
8749 mantissa = mantissa << 1;
8750 }
8751
8752 if ( exp > 0 ) {
8753
8754 for( int i=0; i<exp; ++i ) {
8755 // printf( " x %i) %f ->", i, *_result );
8756 *_result = *_result * 2;
8757 // printf( " %f\n", *_result );
8758 }
8759
8760 } else if ( exp < 0 ) {
8761
8762 exp = -exp;
8763
8764 for( int i=0; i<exp; ++i ) {
8765 // printf( " x %i) %f ->", i, *_result );
8766 *_result = *_result / 2;
8767 // printf( " %f\n", *_result );
8768 }
8769
8770 }
8771
8772}
8773
8774void cpu_float_fast_to_string( Environment * _environment, char * _x, char * _string, char * _string_size ) {
8775 cpu_float_single_to_string( _environment, _x, _string, _string_size );
8776}
8777
8778void cpu_float_single_to_string( Environment * _environment, char * _x, char * _string, char * _string_size ) {
8779
8781
8783
8784 outline1( "LDA %s", address_displacement( _environment, _x, "0" ) );
8785 outline0( "STA X1" );
8786 outline1( "LDA %s", address_displacement( _environment, _x, "1" ) );
8787 outline0( "STA M1" );
8788 outline1( "LDA %s", address_displacement( _environment, _x, "2" ) );
8789 outline0( "STA M1+1" );
8790 outline1( "LDA %s", address_displacement( _environment, _x, "3" ) );
8791 outline0( "STA M1+2" );
8792
8793 outline1( "LDA %s", address_displacement( _environment, _string, "0" ) );
8794 outline0( "STA TMPPTR" );
8795 outline1( "LDA %s", address_displacement( _environment, _string, "1" ) );
8796 outline0( "STA TMPPTR+1" );
8797 outline0( "LDA #$0" );
8798 outline0( "STA TMPPTR2" );
8799
8800 outline0( "JSR BEGIN" );
8801
8802 outline0( "LDA TMPPTR2" );
8803 outline1( "STA %s", _string_size );
8804
8805 // outline0( "JSR FIX" );
8806
8807 // Variable * number = variable_temporary( _environment, VT_WORD, "(number) ");
8808 // outline0( "LDA M1" );
8809 // outline1( "STA %s", address_displacement( _environment, number->realName, "1") );
8810 // outline0( "LDA M1+1" );
8811 // outline1( "STA %s", address_displacement( _environment, number->realName, "0") );
8812
8813 // cpu_number_to_string( _environment, number->realName, _string, _string_size, 16, 1 );
8814
8815}
8816
8817void cpu_float_fast_from_8( Environment * _environment, char * _value, char * _result, int _signed ) {
8818 cpu_float_single_from_8( _environment, _value, _result, _signed );
8819}
8820
8821void cpu_float_single_from_8( Environment * _environment, char * _value, char * _result, int _signed ) {
8822
8824
8826
8827 if ( _signed ) {
8828 outline1( "LDA %s", address_displacement( _environment, _value, "0" ) );
8829 outline0( "AND #$80" );
8830 outline1( "BEQ %s", label );
8831 outline0( "LDA #$ff" );
8832 outline1( "JMP %sdone", label );
8833 outhead1( "%s:", label );
8834 outline0( "LDA #$0" );
8835 outline1( "JMP %sdone", label );
8836 outhead1( "%sdone:", label );
8837 } else {
8838 outline0( "LDA #$0" );
8839 }
8840 outline0( "STA M1" );
8841 outline1( "LDA %s", address_displacement( _environment, _value, "0" ) );
8842 outline0( "STA M1+1" );
8843 outline0( "JSR FLOAT");
8844 outline0( "LDA X1" );
8845 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
8846 outline0( "LDA M1" );
8847 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
8848 outline0( "LDA M1+1" );
8849 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
8850 outline0( "LDA M1+2" );
8851 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
8852
8853}
8854
8855void cpu_float_fast_from_16( Environment * _environment, char * _value, char * _result, int _signed ) {
8856 cpu_float_single_from_16( _environment, _value, _result, _signed );
8857}
8858
8859void cpu_float_single_from_16( Environment * _environment, char * _value, char * _result, int _signed ) {
8860
8862
8863 outline1( "LDA %s", address_displacement( _environment, _value, "1" ) );
8864 outline0( "STA M1" );
8865 outline1( "LDA %s", address_displacement( _environment, _value, "0" ) );
8866 outline0( "STA M1+1" );
8867 outline0( "JSR FLOAT");
8868 outline0( "LDA X1" );
8869 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
8870 outline0( "LDA M1" );
8871 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
8872 outline0( "LDA M1+1" );
8873 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
8874 outline0( "LDA M1+2" );
8875 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
8876
8877}
8878
8879void cpu_float_fast_to_8( Environment * _environment, char * _value, char * _result, int _signed ) {
8880 cpu_float_single_to_8( _environment, _value, _result, _signed );
8881}
8882
8883void cpu_float_single_to_8( Environment * _environment, char * _value, char * _result, int _signed ) {
8884
8885 (int)_signed;
8886
8888
8889 outline1( "LDA %s", address_displacement( _environment, _value, "0" ) );
8890 outline0( "STA X1" );
8891 outline1( "LDA %s", address_displacement( _environment, _value, "1" ) );
8892 outline0( "STA M1" );
8893 outline1( "LDA %s", address_displacement( _environment, _value, "2" ) );
8894 outline0( "STA M1+1" );
8895 outline1( "LDA %s", address_displacement( _environment, _value, "3" ) );
8896 outline0( "STA M1+2" );
8897 outline0( "JSR FIX" );
8898 outline0( "LDA M1+1" );
8899 outline1( "STA %s", _result );
8900
8901}
8902
8903void cpu_float_fast_to_16( Environment * _environment, char * _value, char * _result, int _signed ) {
8904 cpu_float_single_to_16( _environment, _value, _result, _signed );
8905}
8906
8907void cpu_float_single_to_16( Environment * _environment, char * _value, char * _result, int _signed ) {
8908
8909 (int)_signed;
8910
8912
8913 outline1( "LDA %s", address_displacement( _environment, _value, "0" ) );
8914 outline0( "STA X1" );
8915 outline1( "LDA %s", address_displacement( _environment, _value, "1" ) );
8916 outline0( "STA M1" );
8917 outline1( "LDA %s", address_displacement( _environment, _value, "2" ) );
8918 outline0( "STA M1+1" );
8919 outline1( "LDA %s", address_displacement( _environment, _value, "3" ) );
8920 outline0( "STA M1+2" );
8921 outline0( "JSR FIX" );
8922 outline0( "LDA M1" );
8923 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
8924 outline0( "LDA M1+1" );
8925 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
8926
8927}
8928
8929void cpu_float_fast_sub( Environment * _environment, char * _x, char * _y, char * _result ) {
8930 cpu_float_single_sub( _environment, _x, _y, _result );
8931}
8932
8933void cpu_float_single_sub( Environment * _environment, char * _x, char * _y, char * _result ) {
8934
8936
8937 outline1( "LDA %s", address_displacement( _environment, _y, "0" ) );
8938 outline0( "STA X1" );
8939 outline1( "LDA %s", address_displacement( _environment, _y, "1" ) );
8940 outline0( "STA M1" );
8941 outline1( "LDA %s", address_displacement( _environment, _y, "2" ) );
8942 outline0( "STA M1+1" );
8943 outline1( "LDA %s", address_displacement( _environment, _y, "3" ) );
8944 outline0( "STA M1+2" );
8945
8946 outline1( "LDA %s", address_displacement( _environment, _x, "0" ) );
8947 outline0( "STA X2" );
8948 outline1( "LDA %s", address_displacement( _environment, _x, "1" ) );
8949 outline0( "STA M2" );
8950 outline1( "LDA %s", address_displacement( _environment, _x, "2" ) );
8951 outline0( "STA M2+1" );
8952 outline1( "LDA %s", address_displacement( _environment, _x, "3" ) );
8953 outline0( "STA M2+2" );
8954
8955 outline0( "JSR FSUB");
8956
8957 outline0( "LDA X1" );
8958 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
8959 outline0( "LDA M1" );
8960 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
8961 outline0( "LDA M1+1" );
8962 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
8963 outline0( "LDA M1+2" );
8964 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
8965
8966}
8967
8968void cpu_float_fast_add( Environment * _environment, char * _x, char * _y, char * _result ) {
8969 cpu_float_single_add( _environment, _x, _y, _result );
8970}
8971
8972void cpu_float_single_add( Environment * _environment, char * _x, char * _y, char * _result ) {
8973
8975
8976 outline1( "LDA %s", address_displacement( _environment, _x, "0" ) );
8977 outline0( "STA X1" );
8978 outline1( "LDA %s", address_displacement( _environment, _x, "1" ) );
8979 outline0( "STA M1" );
8980 outline1( "LDA %s", address_displacement( _environment, _x, "2" ) );
8981 outline0( "STA M1+1" );
8982 outline1( "LDA %s", address_displacement( _environment, _x, "3" ) );
8983 outline0( "STA M1+2" );
8984
8985 outline1( "LDA %s", address_displacement( _environment, _y, "0" ) );
8986 outline0( "STA X2" );
8987 outline1( "LDA %s", address_displacement( _environment, _y, "1" ) );
8988 outline0( "STA M2" );
8989 outline1( "LDA %s", address_displacement( _environment, _y, "2" ) );
8990 outline0( "STA M2+1" );
8991 outline1( "LDA %s", address_displacement( _environment, _y, "3" ) );
8992 outline0( "STA M2+2" );
8993
8994 outline0( "JSR FADD");
8995
8996 outline0( "LDA X1" );
8997 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
8998 outline0( "LDA M1" );
8999 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
9000 outline0( "LDA M1+1" );
9001 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
9002 outline0( "LDA M1+2" );
9003 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
9004
9005}
9006
9007void cpu_float_fast_cmp( Environment * _environment, char * _x, char * _y, char * _result ) {
9008 cpu_float_single_cmp( _environment, _x, _y, _result );
9009}
9010
9011void cpu_float_single_cmp( Environment * _environment, char * _x, char * _y, char * _result ) {
9012
9014
9016
9017 outline1( "LDA %s", address_displacement( _environment, _x, "0" ) );
9018 outline0( "STA X1" );
9019 outline1( "LDA %s", address_displacement( _environment, _x, "1" ) );
9020 outline0( "STA M1" );
9021 outline1( "LDA %s", address_displacement( _environment, _x, "2" ) );
9022 outline0( "STA M1+1" );
9023 outline1( "LDA %s", address_displacement( _environment, _x, "3" ) );
9024 outline0( "STA M1+2" );
9025
9026 outline1( "LDA %s", address_displacement( _environment, _y, "0" ) );
9027 outline0( "STA X2" );
9028 outline1( "LDA %s", address_displacement( _environment, _y, "1" ) );
9029 outline0( "STA M2" );
9030 outline1( "LDA %s", address_displacement( _environment, _y, "2" ) );
9031 outline0( "STA M2+1" );
9032 outline1( "LDA %s", address_displacement( _environment, _y, "3" ) );
9033 outline0( "STA M2+2" );
9034
9035 outline0( "JSR FCMP");
9036
9037 outline1( "STA %s", _result );
9038
9039}
9040
9041void cpu_float_fast_mul( Environment * _environment, char * _x, char * _y, char * _result ) {
9042 cpu_float_single_mul( _environment, _x, _y, _result );
9043}
9044
9045void cpu_float_single_mul( Environment * _environment, char * _x, char * _y, char * _result ) {
9046
9048
9050
9051 outline1( "LDA %s", address_displacement( _environment, _x, "0" ) );
9052 outline0( "STA X1" );
9053 outline1( "LDA %s", address_displacement( _environment, _x, "1" ) );
9054 outline0( "STA M1" );
9055 outline1( "LDA %s", address_displacement( _environment, _x, "2" ) );
9056 outline0( "STA M1+1" );
9057 outline1( "LDA %s", address_displacement( _environment, _x, "3" ) );
9058 outline0( "STA M1+2" );
9059
9060 outline1( "LDA %s", address_displacement( _environment, _y, "0" ) );
9061 outline0( "STA X2" );
9062 outline1( "LDA %s", address_displacement( _environment, _y, "1" ) );
9063 outline0( "STA M2" );
9064 outline1( "LDA %s", address_displacement( _environment, _y, "2" ) );
9065 outline0( "STA M2+1" );
9066 outline1( "LDA %s", address_displacement( _environment, _y, "3" ) );
9067 outline0( "STA M2+2" );
9068
9069 outline0( "JSR FMUL");
9070
9071 outline0( "LDA X1" );
9072 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
9073 outline0( "LDA M1" );
9074 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
9075 outline0( "LDA M1+1" );
9076 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
9077 outline0( "LDA M1+2" );
9078 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
9079
9080}
9081
9082void cpu_float_fast_div( Environment * _environment, char * _x, char * _y, char * _result ) {
9083 cpu_float_single_div( _environment, _x, _y, _result );
9084}
9085
9086void cpu_float_single_div( Environment * _environment, char * _x, char * _y, char * _result ) {
9087
9089
9091
9092 outline1( "LDA %s", address_displacement( _environment, _y, "0" ) );
9093 outline0( "STA X1" );
9094 outline1( "LDA %s", address_displacement( _environment, _y, "1" ) );
9095 outline0( "STA M1" );
9096 outline1( "LDA %s", address_displacement( _environment, _y, "2" ) );
9097 outline0( "STA M1+1" );
9098 outline1( "LDA %s", address_displacement( _environment, _y, "3" ) );
9099 outline0( "STA M1+2" );
9100
9101 outline1( "LDA %s", address_displacement( _environment, _x, "0" ) );
9102 outline0( "STA X2" );
9103 outline1( "LDA %s", address_displacement( _environment, _x, "1" ) );
9104 outline0( "STA M2" );
9105 outline1( "LDA %s", address_displacement( _environment, _x, "2" ) );
9106 outline0( "STA M2+1" );
9107 outline1( "LDA %s", address_displacement( _environment, _x, "3" ) );
9108 outline0( "STA M2+2" );
9109
9110 outline0( "JSR FDIV");
9111
9112 outline0( "LDA X1" );
9113 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
9114 outline0( "LDA M1" );
9115 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
9116 outline0( "LDA M1+1" );
9117 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
9118 outline0( "LDA M1+2" );
9119 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
9120
9121}
9122
9123void cpu_float_fast_sin( Environment * _environment, char * _angle, char * _result ) {
9124 cpu_float_single_sin( _environment, _angle, _result );
9125}
9126
9127void cpu_float_single_sin( Environment * _environment, char * _angle, char * _result ) {
9128
9130
9132
9133 outline1( "LDA %s", address_displacement( _environment, _angle, "0" ) );
9134 outline0( "STA X1" );
9135 outline1( "LDA %s", address_displacement( _environment, _angle, "1" ) );
9136 outline0( "STA M1" );
9137 outline1( "LDA %s", address_displacement( _environment, _angle, "2" ) );
9138 outline0( "STA M1+1" );
9139 outline1( "LDA %s", address_displacement( _environment, _angle, "3" ) );
9140 outline0( "STA M1+2" );
9141
9142 outline0( "JSR FSIN");
9143
9144 outline0( "LDA X1" );
9145 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
9146 outline0( "LDA M1" );
9147 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
9148 outline0( "LDA M1+1" );
9149 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
9150 outline0( "LDA M1+2" );
9151 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
9152
9153}
9154
9155void cpu_float_fast_log( Environment * _environment, char * _value, char * _result ) {
9156 cpu_float_single_log( _environment, _value, _result );
9157}
9158
9159void cpu_float_single_log( Environment * _environment, char * _value, char * _result ) {
9160
9162
9164
9165 outline1( "LDA %s", address_displacement( _environment, _value, "0" ) );
9166 outline0( "STA X1" );
9167 outline1( "LDA %s", address_displacement( _environment, _value, "1" ) );
9168 outline0( "STA M1" );
9169 outline1( "LDA %s", address_displacement( _environment, _value, "2" ) );
9170 outline0( "STA M1+1" );
9171 outline1( "LDA %s", address_displacement( _environment, _value, "3" ) );
9172 outline0( "STA M1+2" );
9173
9174 outline0( "JSR FPLOG");
9175
9176 outline0( "LDA X1" );
9177 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
9178 outline0( "LDA M1" );
9179 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
9180 outline0( "LDA M1+1" );
9181 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
9182 outline0( "LDA M1+2" );
9183 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
9184
9185}
9186
9187void cpu_float_fast_exp( Environment * _environment, char * _value, char * _result ) {
9188 cpu_float_single_exp( _environment, _value, _result );
9189}
9190
9191void cpu_float_single_exp( Environment * _environment, char * _value, char * _result ) {
9192
9194
9196
9197 outline1( "LDA %s", address_displacement( _environment, _value, "0" ) );
9198 outline0( "STA X1" );
9199 outline1( "LDA %s", address_displacement( _environment, _value, "1" ) );
9200 outline0( "STA M1" );
9201 outline1( "LDA %s", address_displacement( _environment, _value, "2" ) );
9202 outline0( "STA M1+1" );
9203 outline1( "LDA %s", address_displacement( _environment, _value, "3" ) );
9204 outline0( "STA M1+2" );
9205
9206 outline0( "JSR FPEXP");
9207
9208 outline0( "LDA X1" );
9209 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
9210 outline0( "LDA M1" );
9211 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
9212 outline0( "LDA M1+1" );
9213 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
9214 outline0( "LDA M1+2" );
9215 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
9216
9217}
9218
9219void cpu_float_fast_cos( Environment * _environment, char * _angle, char * _result ) {
9220 cpu_float_single_cos( _environment, _angle, _result );
9221}
9222
9223void cpu_float_single_cos( Environment * _environment, char * _angle, char * _result ) {
9224
9226
9228
9229 outline1( "LDA %s", address_displacement( _environment, _angle, "0" ) );
9230 outline0( "STA X1" );
9231 outline1( "LDA %s", address_displacement( _environment, _angle, "1" ) );
9232 outline0( "STA M1" );
9233 outline1( "LDA %s", address_displacement( _environment, _angle, "2" ) );
9234 outline0( "STA M1+1" );
9235 outline1( "LDA %s", address_displacement( _environment, _angle, "3" ) );
9236 outline0( "STA M1+2" );
9237
9238 outline0( "JSR FCOS");
9239
9240 outline0( "LDA X1" );
9241 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
9242 outline0( "LDA M1" );
9243 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
9244 outline0( "LDA M1+1" );
9245 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
9246 outline0( "LDA M1+2" );
9247 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
9248
9249}
9250
9251void cpu_float_fast_tan( Environment * _environment, char * _angle, char * _result ) {
9252 cpu_float_single_tan( _environment, _angle, _result );
9253}
9254
9255void cpu_float_single_tan( Environment * _environment, char * _angle, char * _result ) {
9256
9258
9260
9261 outline1( "LDA %s", address_displacement( _environment, _angle, "0" ) );
9262 outline0( "STA X1" );
9263 outline1( "LDA %s", address_displacement( _environment, _angle, "1" ) );
9264 outline0( "STA M1" );
9265 outline1( "LDA %s", address_displacement( _environment, _angle, "2" ) );
9266 outline0( "STA M1+1" );
9267 outline1( "LDA %s", address_displacement( _environment, _angle, "3" ) );
9268 outline0( "STA M1+2" );
9269
9270 outline0( "JSR FTAN");
9271
9272 outline0( "LDA X1" );
9273 outline1( "STA %s", address_displacement( _environment, _result, "0" ) );
9274 outline0( "LDA M1" );
9275 outline1( "STA %s", address_displacement( _environment, _result, "1" ) );
9276 outline0( "LDA M1+1" );
9277 outline1( "STA %s", address_displacement( _environment, _result, "2" ) );
9278 outline0( "LDA M1+2" );
9279 outline1( "STA %s", address_displacement( _environment, _result, "3" ) );
9280
9281}
9282
9283void cpu_address_table_build( Environment * _environment, char * _table, int * _values, char *_address[], int _count ) {
9284
9285 outhead1("%s:", _table );
9286 for( int i=0; i<_count; ++i ) {
9287 outline2(".word $%4.4x, %s", _values[i], _address[i] );
9288 }
9289
9290}
9291
9292void cpu_address_table_lookup( Environment * _environment, char * _table, int _count ) {
9293
9294 outhead1("LOOKFOR%s:", _table );
9295 if ( _count ) {
9296 outline1("LDA #<%s", _table );
9297 outline0("STA MATHPTR2" );
9298 outline1("LDA #>%s", _table );
9299 outline0("STA MATHPTR2+1" );
9300 outline0("LDY #0" );
9301 outhead1("LOOKFOR%sL1:", _table );
9302 outline0("LDA (MATHPTR2), Y" );
9303 outline0("CMP MATHPTR0" );
9304 outline1("BNE LOOKFOR%sNEXT3", _table );
9305 outline0("INY" );
9306 outline0("LDA (MATHPTR2), Y" );
9307 outline0("CMP MATHPTR1" );
9308 outline1("BNE LOOKFOR%sNEXT2", _table );
9309 outline0("INY" );
9310 outline0("LDA (MATHPTR2), Y" );
9311 outline0("STA MATHPTR0" );
9312 outline0("INY" );
9313 outline0("LDA (MATHPTR2), Y" );
9314 outline0("STA MATHPTR1" );
9315 outline0("RTS" );
9316 outhead1("LOOKFOR%sNEXT3:", _table );
9317 outline0("INY" );
9318 outhead1("LOOKFOR%sNEXT2:", _table );
9319 outline0("INY" );
9320 outline0("INY" );
9321 outline1("CPY #$%2.2x", (_count+1) * 4 );
9322 outline1("BNE LOOKFOR%sL1", _table );
9323 }
9324 outline0("RTS" );
9325
9326}
9327
9328void cpu_address_table_call( Environment * _environment, char * _table, char * _value, char * _address ) {
9329
9330 outline1("LDA %s", _value );
9331 outline0("STA MATHPTR0" );
9332 outline1("LDA %s", address_displacement( _environment, _value, "1" ) );
9333 outline0("STA MATHPTR1" );
9334 outline1("JSR LOOKFOR%s", _table );
9335 outline0("LDA MATHPTR0" );
9336 outline1("STA %s", _address );
9337 outline0("LDA MATHPTR1" );
9338 outline1("STA %s", address_displacement( _environment, _address, "1" ) );
9339
9340}
9341
9342void cpu_move_8bit_signed_16bit_signed( Environment * _environment, char *_source, char *_destination ) {
9343
9344 outline1("LDA %s", _source );
9345 outline1("STA %s", _destination );
9346 outline0("LDA #$7F" );
9347 outline1("CMP %s", _destination );
9348 outline0("SBC #$7F" );
9349 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9350
9351}
9352
9353void cpu_move_8bit_signed_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9354
9355 outline1("LDA %s", _source );
9356 outline1("STA %s", _destination );
9357 outline0("LDA #$7F" );
9358 outline1("CMP %s", _destination );
9359 outline0("SBC #$7F" );
9360 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9361
9362}
9363
9364void cpu_move_8bit_unsigned_16bit_signed( Environment * _environment, char *_source, char *_destination ){
9365
9366 outline1("LDA %s", _source );
9367 outline1("STA %s", _destination );
9368 outline0("LDA #0" );
9369 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9370
9371}
9372
9373void cpu_move_8bit_unsigned_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9374
9375 outline1("LDA %s", _source );
9376 outline1("STA %s", _destination );
9377 outline0("LDA #0" );
9378 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9379
9380}
9381
9382void cpu_move_8bit_signed_32bit_signed( Environment * _environment, char *_source, char *_destination ){
9383
9384 outline1("LDA %s", _source );
9385 outline1("STA %s", _destination );
9386 outline0("LDA #$7F" );
9387 outline1("CMP %s", _destination );
9388 outline0("SBC #$7F" );
9389 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9390 outline1("STA %s", address_displacement( _environment, _destination, "2" ) );
9391 outline1("STA %s", address_displacement( _environment, _destination, "3" ) );
9392
9393}
9394
9395void cpu_move_8bit_signed_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9396
9397 outline1("LDA %s", _source );
9398 outline1("STA %s", _destination );
9399 outline0("LDA #$7F" );
9400 outline1("CMP %s", _destination );
9401 outline0("SBC #$7F" );
9402 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9403 outline1("STA %s", address_displacement( _environment, _destination, "2" ) );
9404 outline1("STA %s", address_displacement( _environment, _destination, "3" ) );
9405
9406}
9407
9408void cpu_move_8bit_unsigned_32bit_signed( Environment * _environment, char *_source, char *_destination ){
9409
9410 outline1("LDA %s", _source );
9411 outline1("STA %s", _destination );
9412 outline0("LDA #0" );
9413 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9414 outline1("STA %s", address_displacement( _environment, _destination, "2" ) );
9415 outline1("STA %s", address_displacement( _environment, _destination, "3" ) );
9416
9417}
9418void cpu_move_8bit_unsigned_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9419
9420 outline1("LDA %s", _source );
9421 outline1("STA %s", _destination );
9422 outline0("LDA #0" );
9423 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9424 outline1("STA %s", address_displacement( _environment, _destination, "2" ) );
9425 outline1("STA %s", address_displacement( _environment, _destination, "3" ) );
9426
9427}
9428
9429void cpu_move_16bit_signed_8bit_signed( Environment * _environment, char *_source, char *_destination ){
9430
9431 outline1("LDA %s", _source );
9432 outline1("STA %s", _destination );
9433
9434}
9435void cpu_move_16bit_signed_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9436
9437 outline1("LDA %s", _source );
9438 outline1("STA %s", _destination );
9439
9440}
9441void cpu_move_16bit_unsigned_8bit_signed( Environment * _environment, char *_source, char *_destination ){
9442
9443 outline1("LDA %s", _source );
9444 outline1("STA %s", _destination );
9445
9446}
9447void cpu_move_16bit_unsigned_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9448
9449 outline1("LDA %s", _source );
9450 outline1("STA %s", _destination );
9451
9452}
9453
9454void cpu_move_16bit_signed_32bit_signed( Environment * _environment, char *_source, char *_destination ){
9455
9456 outline1("LDA %s", _source );
9457 outline1("STA %s", _destination );
9458 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
9459 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9460 outline0("LDA #$7F" );
9461 outline1("CMP %s", address_displacement( _environment, _destination, "1" ) );
9462 outline0("SBC #$7F" );
9463 outline1("STA %s", address_displacement( _environment, _destination, "2" ) );
9464 outline1("STA %s", address_displacement( _environment, _destination, "3" ) );
9465
9466}
9467
9468void cpu_move_16bit_signed_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9469
9470
9471 outline1("LDA %s", _source );
9472 outline1("STA %s", _destination );
9473 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
9474 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9475 outline0("LDA #$7F" );
9476 outline1("CMP %s", address_displacement( _environment, _destination, "1" ) );
9477 outline0("SBC #$7F" );
9478 outline1("STA %s", address_displacement( _environment, _destination, "2" ) );
9479 outline1("STA %s", address_displacement( _environment, _destination, "3" ) );
9480
9481}
9482
9483void cpu_move_16bit_unsigned_32bit_signed( Environment * _environment, char *_source, char *_destination ){
9484
9485 outline1("LDA %s", _source );
9486 outline1("STA %s", _destination );
9487 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
9488 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9489 outline0("LDA #0" );
9490 outline1("STA %s", address_displacement( _environment, _destination, "2" ) );
9491 outline1("STA %s", address_displacement( _environment, _destination, "3" ) );
9492
9493}
9494void cpu_move_16bit_unsigned_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9495
9496 outline1("LDA %s", _source );
9497 outline1("STA %s", _destination );
9498 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
9499 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9500 outline0("LDA #0" );
9501 outline1("STA %s", address_displacement( _environment, _destination, "2" ) );
9502 outline1("STA %s", address_displacement( _environment, _destination, "3" ) );
9503
9504}
9505
9506void cpu_move_32bit_signed_8bit_signed( Environment * _environment, char *_source, char *_destination ){
9507
9508 outline1("LDA %s", _source );
9509 outline1("STA %s", _destination );
9510 outline0("LDA #0" );
9511 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9512 outline1("STA %s", address_displacement( _environment, _destination, "2" ) );
9513 outline1("STA %s", address_displacement( _environment, _destination, "3" ) );
9514
9515}
9516void cpu_move_32bit_signed_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9517
9518 outline1("LDA %s", _source );
9519 outline1("STA %s", _destination );
9520
9521}
9522void cpu_move_32bit_unsigned_8bit_signed( Environment * _environment, char *_source, char *_destination ){
9523
9524 outline1("LDA %s", _source );
9525 outline1("STA %s", _destination );
9526
9527}
9528void cpu_move_32bit_unsigned_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9529
9530 outline1("LDA %s", _source );
9531 outline1("STA %s", _destination );
9532
9533}
9534
9535void cpu_move_32bit_signed_16bit_signed( Environment * _environment, char *_source, char *_destination ){
9536
9537 outline1("LDA %s", _source );
9538 outline1("STA %s", _destination );
9539 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
9540 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9541
9542}
9543
9544void cpu_move_32bit_signed_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9545
9546 outline1("LDA %s", _source );
9547 outline1("STA %s", _destination );
9548 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
9549 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9550
9551}
9552
9553void cpu_move_32bit_unsigned_16bit_signed( Environment * _environment, char *_source, char *_destination ){
9554
9555 outline1("LDA %s", _source );
9556 outline1("STA %s", _destination );
9557 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
9558 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9559
9560}
9561
9562void cpu_move_32bit_unsigned_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
9563
9564 outline1("LDA %s", _source );
9565 outline1("STA %s", _destination );
9566 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
9567 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
9568
9569}
9570
9571void cpu_encrypt( Environment * _environment, char * _data, char * _data_size, char * _key, char * _key_size, char * _output ) {
9572
9574
9575 outline1("LDA %s", _data );
9576 outline0("STA TMPPTR" );
9577 outline1("LDA %s", address_displacement( _environment, _data, "1" ) );
9578 outline0("STA TMPPTR+1" );
9579 outline1("LDA %s", _key );
9580 outline0("STA TMPPTR2" );
9581 outline1("LDA %s", address_displacement( _environment, _key, "1" ) );
9582 outline0("STA TMPPTR2+1" );
9583 outline1("LDA %s", _output );
9584 outline0("STA MATHPTR4" );
9585 outline1("LDA %s", address_displacement( _environment, _output, "1" ) );
9586 outline0("STA MATHPTR4+1" );
9587 outline1("LDA %s", _data_size );
9588 outline0("STA MATHPTR6" );
9589 outline1("LDA %s", _key_size );
9590 outline0("STA MATHPTR7" );
9591 outline0("JSR ENCRYPT" );
9592
9593}
9594
9595void cpu_decrypt( Environment * _environment, char * _data, char * _data_size, char * _key, char * _key_size, char * _output, char * _result ) {
9596
9598
9599 outline1("LDA %s", _data );
9600 outline0("STA TMPPTR" );
9601 outline1("LDA %s", address_displacement( _environment, _data, "1" ) );
9602 outline0("STA TMPPTR+1" );
9603 outline1("LDA %s", _key );
9604 outline0("STA TMPPTR2" );
9605 outline1("LDA %s", address_displacement( _environment, _key, "1" ) );
9606 outline0("STA TMPPTR2+1" );
9607 outline1("LDA %s", _output );
9608 outline0("STA MATHPTR4" );
9609 outline1("LDA %s", address_displacement( _environment, _output, "1" ) );
9610 outline0("STA MATHPTR4+1" );
9611 outline1("LDA %s", _data_size );
9612 outline0("STA MATHPTR6" );
9613 outline1("LDA %s", _key_size );
9614 outline0("STA MATHPTR7" );
9615 outline0("JSR DECRYPT" );
9616 cpu_ztoa( _environment );
9617 outline1("STA %s", _result );
9618
9619}
9620
9621void cpu_hex_to_bin( Environment * _environment, char * _value_address, char * _value_size, char * _variable_address, char * _variable_size, char * _result ) {
9622
9623 deploy( hex2bin, src_hw_6502_hex2bin_asm );
9624
9625 outline1("LDA %s", _value_address );
9626 outline0("STA TMPPTR" );
9627 outline1("LDA %s", address_displacement( _environment, _value_address, "1" ) );
9628 outline0("STA TMPPTR+1" );
9629 outline1("LDA %s", _variable_address );
9630 outline0("STA HEX2BINADDR+1" );
9631 outline1("LDA %s", address_displacement( _environment, _variable_address, "1" ) );
9632 outline0("STA HEX2BINADDR+2" );
9633 outline1("LDX %s", _value_size );
9634 outline1("LDY %s", _variable_size );
9635 outline0("JSR HEX2BIN" );
9636 outline1("STA %s", _result );
9637
9638}
9639
9640void cpu_dsfill( Environment * _environment, char * _string, char * _value ) {
9641
9643 deploy( dstring, src_hw_6502_dstring_asm );
9644
9645 outline1( "LDX %s", _string );
9646 outline1( "LDA %s", _value );
9647 outline0( "JSR DSFILL" );
9648
9649}
9650
9651void cpu_dsfill_value( Environment * _environment, char * _string, int _value ) {
9652
9654 deploy( dstring, src_hw_6502_dstring_asm );
9655
9656 outline1( "LDX %s", _string );
9657 outline1( "LDA #$%2.2x", (unsigned char)(_value&0xff) );
9658 outline0( "JSR DSFILL" );
9659
9660}
9661
9662
9663#endif
void cpu_move_32bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6309.c:5398
void cpu_less_than_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6309.c:5034
void cpu_combine_nibbles(Environment *_environment, char *_low_nibble, char *_hi_nibble, char *_byte)
Definition 6309.c:3724
void cpu_di(Environment *_environment)
Definition 6309.c:4547
void cpu_math_double_32bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6309: emit code to double a 32 bit value
Definition 6309.c:3279
void cpu_not_16bit(Environment *_environment, char *_value, char *_result)
Definition 6309.c:4517
void cpu_math_mul2_const_16bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6309: emit code to halves for several times a 8 bit value
Definition 6309.c:2461
void cpu_math_div_16bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6309.c:2009
void cpu_math_mul_16bit_to_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _signed)
CPU 6309: emit code to multiply two 16 bit values in a 32 bit register
Definition 6309.c:1752
void cpu_bveq(Environment *_environment, char *_value, char *_label)
Definition 6309.c:334
void cpu_bit_check_extended(Environment *_environment, char *_value, char *_position, char *_result, int _bitwidth)
Definition 6309.c:5605
void cpu_math_div_32bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6309.c:2554
void cpu_math_mul2_const_8bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6309: emit code to double for several times a 8 bit value
Definition 6309.c:1397
void cpu_math_mul2_const_32bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6309: emit code to double for several times a 32 bit value
Definition 6309.c:3547
void cpu_uppercase(Environment *_environment, char *_source, char *_size, char *_result)
Definition 6309.c:5414
void cpu_math_add_16bit_with_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
Definition 6309.c:1708
void cpu_mem_move(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6309.c:4692
void cpu_math_add_32bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to add two 32 bit values
Definition 6309.c:3219
void cpu_store_char(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:785
void cpu_math_complement_const_32bit(Environment *_environment, char *_source, int _value)
CPU 6309: emit code to calculate a 32 bit complement of a number
Definition 6309.c:3352
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 16 bit
Definition 6309.c:1503
void cpu_and_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6309.c:4230
void cpu_math_double_16bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6309: emit code to double a 16 bit value
Definition 6309.c:1728
void cpu_math_sub_32bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to subtract two 32 bit values
Definition 6309.c:3304
void cpu_math_div2_const_8bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6309: emit code to halves for several times a 8 bit value
Definition 6309.c:1329
void cpu_less_than_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6309.c:4969
void cpu_math_div_nbit_to_nbit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _bits)
Definition 6309.c:2571
void cpu_math_add_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to add two 8 bit values
Definition 6309.c:1017
void cpu_move_8bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6309.c:5239
void cpu_string_sub(Environment *_environment, char *_source, char *_source_size, char *_pattern, char *_pattern_size, char *_destination, char *_destination_size)
Definition 6309.c:6370
void cpu_compare_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:811
void cpu_math_and_const_32bit(Environment *_environment, char *_source, int _mask)
CPU 6309: emit code to mask with "and" a value of 32 bit
Definition 6309.c:3698
void cpu_dec_16bit(Environment *_environment, char *_variable)
Definition 6309.c:4640
void cpu_inc(Environment *_environment, char *_variable)
Definition 6309.c:4555
void cpu_jump_indirect(Environment *_environment, char *_value)
Definition 6309.c:3783
void cpu_math_complement_const_8bit(Environment *_environment, char *_source, int _value)
CPU 6309: emit code to calculate an 8 bit complement of a number
Definition 6309.c:1432
void cpu_math_complement_const_16bit(Environment *_environment, char *_source, int _value)
CPU 6309: emit code to calculate a 16 bit complement of a number
Definition 6309.c:2337
void cpu_math_mul2_const_nbit(Environment *_environment, char *_source, int _steps, int _bits)
Definition 6309.c:3664
void cpu_move_32bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 32 bit
Definition 6309.c:2520
void cpu_less_than_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:950
#define cpu_BLIT_REGISTER_COUNT
Definition 6309.c:6401
void cpu_dec_32bit(Environment *_environment, char *_variable)
Definition 6309.c:4652
void cpu_math_add_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to add two 16 bit values
Definition 6309.c:1661
void cpu_greater_than_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:1632
void cpu_math_add_16bit_const(Environment *_environment, char *_source, int _destination, char *_other)
Definition 6309.c:1674
void cpu_protothread_vars(Environment *_environment)
Definition 6309.c:6143
void cpu_math_add_16bit_with_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to add two 16 bit values
Definition 6309.c:1696
void cpu_compare_and_branch_16bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:1578
void cpu_move_32bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6309.c:5382
void cpu_greater_than_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:989
void cpu_or_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4320
void cpu_fill(Environment *_environment, char *_address, char *_bytes, int _bytes_width, char *_pattern)
CPU 6309: emit code to fill up a memory area
Definition 6309.c:534
void cpu_move_16bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6309.c:5339
void cpu_limit_16bit(Environment *_environment, char *_variable, int _value)
Definition 6309.c:4164
void cpu_move_8bit_indirect_with_offset2(Environment *_environment, char *_source, char *_value, char *_offset)
Definition 6309.c:5262
void cpu_less_than_32bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:2985
void cpu_and_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4216
void cpu_math_mul_8bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _signed)
CPU 6309: emit code to multiply two 8bit values in a 16 bit register
Definition 6309.c:1088
void cpu_math_sub_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to subtract two 16 bit values
Definition 6309.c:2305
void cpu_compare_and_branch_32bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 32 bit values and jump if they are equal/different
Definition 6309.c:2914
void cpu_math_and_const_16bit(Environment *_environment, char *_source, int _mask)
CPU 6309: emit code to mask with "and" a value of 16 bit
Definition 6309.c:2496
void cpu_move_8bit_indirect2_8bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6309.c:5307
void cpu_compare_and_branch_char_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:925
void cpu_less_than_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _bits)
Definition 6309.c:3065
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_dec(Environment *_environment, char *_variable)
Definition 6309.c:4630
void cpu_and_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4244
void cpu_logical_not_8bit(Environment *_environment, char *_value, char *_result)
Definition 6309.c:4493
void cpu_logical_and_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4198
void cpu_or_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6309.c:4306
void cpu_math_div2_const_32bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6309: emit code to halves for several times a 32 bit value
Definition 6309.c:3376
void cpu_halt(Environment *_environment)
Definition 6309.c:4050
void cpu_end(Environment *_environment)
Definition 6309.c:4064
void cpu_compare_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6309.c:4849
void cpu_xor_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4354
void cpu_lowercase(Environment *_environment, char *_source, char *_size, char *_result)
Definition 6309.c:5451
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 16 bit
Definition 6309.c:1474
void cpu_move_8bit_with_offset2(Environment *_environment, char *_source, char *_value, char *_offset)
Definition 6309.c:5278
void cpu_bneq(Environment *_environment, char *_label)
CPU 6309: emit code to make long conditional jump
Definition 6309.c:324
void cpu_move_16bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6309.c:5352
void cpu_math_double_8bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6309: emit code to double a 8 bit value
Definition 6309.c:1068
void cpu_less_than_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _bits)
Definition 6309.c:3021
void cpu_not_32bit(Environment *_environment, char *_value, char *_result)
Definition 6309.c:4530
void cpu_greater_than_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6309.c:5170
void cpu_hex_to_string(Environment *_environment, char *_number, char *_string, char *_size, int _separator)
Definition 6309.c:5865
void cpu_or_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4292
void cpu_move_8bit_indirect2_16bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6309.c:5323
void cpu_math_add_32bit_const(Environment *_environment, char *_source, int _destination, char *_other)
Definition 6309.c:3257
void cpu_greater_than_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:3117
void cpu_call_indirect(Environment *_environment, char *_value)
Definition 6309.c:3765
void cpu_call(Environment *_environment, char *_label)
Definition 6309.c:3755
void cpu_random_8bit(Environment *_environment, char *_entropy, char *_result)
Definition 6309.c:4129
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void cpu_swap_8bit(Environment *_environment, char *_left, char *_right)
Definition 6309.c:4451
void cpu_compare_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6309: emit code to compare two 32 bit values
Definition 6309.c:2769
void cpu_jump(Environment *_environment, char *_label)
Definition 6309.c:3739
void cpu_fill_blocks(Environment *_environment, char *_address, char *_blocks, char *_pattern)
CPU 6309: emit code to fill up a memory area
Definition 6309.c:484
void cpu_bvneq(Environment *_environment, char *_value, char *_label)
Definition 6309.c:345
void cpu_compare_and_branch_16bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6309.c:1552
void cpu_poke(Environment *_environment, char *_address, char *_source)
Definition 6309.c:377
void cpu_random_32bit(Environment *_environment, char *_entropy, char *_result)
Definition 6309.c:4151
void cpu_less_than_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:960
void cpu_greater_than_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _bits)
Definition 6309.c:3189
void cpu_less_than_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:1603
void cpu_math_and_const_8bit(Environment *_environment, char *_source, int _mask)
CPU 6309: emit code to mask with "and" a value of 8 bit
Definition 6309.c:1451
void cpu_inc_32bit(Environment *_environment, char *_variable)
Definition 6309.c:4586
void cpu_xor_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4413
void cpu_return(Environment *_environment)
Definition 6309.c:4030
void cpu_move_8bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6309.c:5294
void cpu_inc_nbit(Environment *_environment, char *_variable, int _bits)
Definition 6309.c:4613
void cpu_pop(Environment *_environment)
Definition 6309.c:4040
void cpu_math_sub_16bit_with_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
Definition 6309.c:2317
void cpu_random_16bit(Environment *_environment, char *_entropy, char *_result)
Definition 6309.c:4140
void cpu_ei(Environment *_environment)
Definition 6309.c:4551
void cpu_or_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4335
void cpu_math_div2_const_16bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6309: emit code to halves for several times a 16 bit value
Definition 6309.c:2356
void cpu_inc_16bit(Environment *_environment, char *_variable)
Definition 6309.c:4565
void cpu_logical_or_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4275
void cpu_compare_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive, int _bits)
Definition 6309.c:2804
void cpu_ztoa(Environment *_environment)
Definition 6309.c:262
void cpu_random(Environment *_environment, char *_entropy)
Definition 6309.c:4075
void cpu_compare_and_branch_8bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6309.c:851
void cpu_ctoa(Environment *_environment)
Definition 6309.c:279
void cpu_move_16bit_indirect2_8bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6309.c:5365
void cpu_math_sub_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6309.c:3325
void cpu_math_div2_const_nbit(Environment *_environment, char *_source, int _steps, int _bits, char *_remainder)
Definition 6309.c:3503
void cpu_busy_wait(Environment *_environment, char *_timing)
Definition 6309.c:4183
void cpu_greater_than_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6309.c:5105
void cpu_store_32bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 32 bit
Definition 6309.c:2540
void cpu_flip(Environment *_environment, char *_source, char *_size, char *_destination)
Definition 6309.c:5562
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
void cpu_beq(Environment *_environment, char *_label)
CPU 6309: emit code to make long conditional jump
Definition 6309.c:308
void cpu_compare_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6309: emit code to compare two 16 bit values
Definition 6309.c:1523
void cpu_peek(Environment *_environment, char *_address, char *_target)
Definition 6309.c:366
void cpu_convert_string_into_16bit(Environment *_environment, char *_string, char *_len, char *_value)
Definition 6309.c:5502
void cpu_not_8bit(Environment *_environment, char *_value, char *_result)
Definition 6309.c:4505
void cpu_math_div_8bit_to_8bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6309.c:1163
void cpu_math_add_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6309.c:3238
void cpu_xor_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4382
void cpu_swap_16bit(Environment *_environment, char *_left, char *_right)
Definition 6309.c:4465
void cpu_compare_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:876
void cpu_less_than_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 32 bit values
Definition 6309.c:2949
void cpu_compare_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6309.c:4906
void cpu_math_add_8bit_const(Environment *_environment, char *_source, int _destination, char *_other)
Definition 6309.c:1029
void cpu_less_than_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:1613
#define IS_REGISTER(x)
Definition 6309.h:58
@ REGISTER_Y
Definition 6309.h:68
@ REGISTER_A
Definition 6309.h:63
@ REGISTER_X
Definition 6309.h:67
@ REGISTER_S
Definition 6309.h:70
@ REGISTER_NONE
Definition 6309.h:62
@ REGISTER_PC
Definition 6309.h:71
@ STACK_NONE
Definition 6309.h:78
@ STACK_BYTE
Definition 6309.h:79
@ STACK_WORD
Definition 6309.h:80
@ STACK_DWORD
Definition 6309.h:81
void cpu_and_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5368
void cpu_float_single_cos(Environment *_environment, char *_angle, char *_result)
Definition 6502.c:9223
void cpu_protothread_get_state(Environment *_environment, char *_index, char *_state)
Definition 6502.c:8001
void cpu_set_callback(Environment *_environment, char *_callback, char *_label)
Definition 6502.c:8037
void cpu_move_32bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6502.c:6787
void cpu_dsfree(Environment *_environment, char *_index)
Definition 6502.c:7600
void cpu_less_than_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6502.c:6506
void cpu_dsresize_size(Environment *_environment, char *_index, int _resize)
Definition 6502.c:7632
void cpu_hex_to_string_calc_string(Environment *_environment, char *_size, int _separator, char *_string_size)
Definition 6502.c:7506
void cpu_move_8bit_signed_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9395
void cpu_float_fast_from_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6502.c:8817
void cpu_in(Environment *_environment, char *_port, char *_value)
Definition 6502.c:8148
void cpu_hex_to_string_calc_string_size(Environment *_environment, int _size, int _separator, char *_string_size)
Definition 6502.c:7522
void cpu_pokew(Environment *_environment, char *_address, char *_source)
Definition 6502.c:227
void cpu_move_32bit_signed_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9544
void cpu_combine_nibbles(Environment *_environment, char *_low_nibble, char *_hi_nibble, char *_byte)
Definition 6502.c:4593
char * cpu_blit_register_name(Environment *_environment, int _register)
Definition 6502.c:8216
void cpu_di(Environment *_environment)
Definition 6502.c:5722
void cpu_float_fast_tan(Environment *_environment, char *_angle, char *_result)
Definition 6502.c:9251
void cpu_math_double_32bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6502: emit code to double a 32 bit value
Definition 6502.c:4267
void cpu_protothread_restore(Environment *_environment, char *_index, char *_step)
Definition 6502.c:7978
void cpu_msc1_uncompress_indirect_indirect(Environment *_environment, char *_input, char *_output)
Definition 6502.c:8121
void cpu_not_16bit(Environment *_environment, char *_value, char *_result)
Definition 6502.c:5682
void cpu_move_8bit_unsigned_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9408
void cpu_math_mul2_const_16bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6502: emit code to halves for several times a 8 bit value
Definition 6502.c:3099
void cpu_math_div_16bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6502.c:2582
void cpu_move_16bit_signed_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9454
void cpu_move_8bit_unsigned_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9364
void cpu_compare_32bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive)
CPU 6309: emit code to compare two 32 bit values
Definition 6502.c:3703
void cpu_math_mul_16bit_to_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _signed)
CPU 6502: emit code to multiply two 16 bit values in a 32 bit register
Definition 6502.c:2234
void cpu_swap_32bit(Environment *_environment, char *_left, char *_right)
Definition 6502.c:5631
void cpu_float_fast_from_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6502.c:8855
void cpu_bveq(Environment *_environment, char *_value, char *_label)
Definition 6502.c:126
void cpu_dsresize(Environment *_environment, char *_index, char *_resize)
Definition 6502.c:7620
void cpu_move_nbit_indirect(Environment *_environment, int _n, char *_source, char *_value)
Definition 6502.c:6812
void cpu_math_div_8bit_to_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _signed)
Definition 6502.c:1451
void cpu_bit_check_extended(Environment *_environment, char *_value, char *_position, char *_result, int _bitwidth)
Definition 6502.c:7347
void cpu_math_div_32bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6502.c:3203
void cpu_math_mul2_const_8bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6502: emit code to double for several times a 8 bit value
Definition 6502.c:1638
void cpu_float_fast_div(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6502.c:9082
void cpu_move_32bit_signed_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9535
void cpu_move_32bit_unsigned_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9528
void cpu_math_mul2_const_32bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6502: emit code to double for several times a 32 bit value
Definition 6502.c:4504
void cpu_uppercase(Environment *_environment, char *_source, char *_size, char *_result)
Definition 6502.c:7015
void cpu_math_add_16bit_with_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
Definition 6502.c:2171
void cpu_address_table_build(Environment *_environment, char *_table, int *_values, char *_address[], int _count)
Definition 6502.c:9283
void cpu_mem_move(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6502.c:5876
void cpu_set_asmio_indirect(Environment *_environment, int _asmio, char *_value)
Definition 6502.c:4914
void cpu_msc1_uncompress_direct_indirect(Environment *_environment, char *_input, char *_output)
Definition 6502.c:8075
void cpu_math_sub_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6502: emit code to subtract two 8 bit values
Definition 6502.c:1168
void cpu_xor_32bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6502.c:5568
void cpu_math_add_32bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6502: emit code to add two 32 bit values
Definition 6502.c:4163
void cpu_protothread_save(Environment *_environment, char *_index, int _step)
Definition 6502.c:7967
void cpu_store_char(Environment *_environment, char *_destination, int _value)
CPU 6502: emit code to store a char
Definition 6502.c:724
void cpu_math_complement_const_32bit(Environment *_environment, char *_source, int _value)
CPU 6502: emit code to calculate a 32 bit complement of a number
Definition 6502.c:4377
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6502: emit code to store 16 bit
Definition 6502.c:1763
void cpu_poked(Environment *_environment, char *_address, char *_source)
Definition 6502.c:290
void cpu_and_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6502.c:5336
void cpu_dsassign(Environment *_environment, char *_original, char *_copy)
Definition 6502.c:7684
void cpu_math_double_16bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6502: emit code to double a 16 bit value
Definition 6502.c:2202
void cpu_math_sub_32bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6502: emit code to subtract two 32 bit values
Definition 6502.c:4312
void cpu_complement2_8bit(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:7735
void cpu_msc1_uncompress_indirect_direct(Environment *_environment, char *_input, char *_output)
Definition 6502.c:8098
void cpu_math_div2_const_8bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6502: emit code to halves for several times a 8 bit value
Definition 6502.c:1568
void cpu_less_than_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6502.c:6468
void cpu_dsalloc_size(Environment *_environment, int _size, char *_index)
Definition 6502.c:7588
void cpu_get_asmio_indirect(Environment *_environment, int _asmio, char *_value)
Definition 6502.c:5012
void cpu_move_16bit_unsigned_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9447
void cpu_float_fast_cos(Environment *_environment, char *_angle, char *_result)
Definition 6502.c:9219
void cpu_protothread_set_state(Environment *_environment, char *_index, int _state)
Definition 6502.c:7990
void cpu_math_div_nbit_to_nbit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _bits)
Definition 6502.c:3424
void cpu_math_add_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6502: emit code to add two 8 bit values
Definition 6502.c:1122
void cpu_float_single_add(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6502.c:8972
void cpu_float_single_sub(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6502.c:8933
void cpu_bit_inplace_8bit_extended_indirect(Environment *_environment, char *_address, char *_position, char *_bit)
Definition 6502.c:7404
void cpu_move_8bit_unsigned_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9418
void cpu_move_8bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6502.c:6620
void cpu_string_sub(Environment *_environment, char *_source, char *_source_size, char *_pattern, char *_pattern_size, char *_destination, char *_destination_size)
Definition 6502.c:8160
void cpu_compare_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6502: emit code to compare two 8 bit values
Definition 6502.c:748
void cpu_math_and_const_32bit(Environment *_environment, char *_source, int _mask)
CPU 6502: emit code to mask with "and" a value of 32 bit
Definition 6502.c:4572
void cpu_fill_direct_size(Environment *_environment, char *_address, int _bytes, char *_pattern)
CPU 6502: emit code to fill up a memory area
Definition 6502.c:595
void cpu_addressof_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:1743
void cpu_dec_16bit(Environment *_environment, char *_variable)
Definition 6502.c:5813
void cpu_dsgc(Environment *_environment)
Definition 6502.c:7644
void cpu_move_16bit_signed_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9468
void cpu_inc(Environment *_environment, char *_variable)
Definition 6502.c:5742
void cpu_poke_const(Environment *_environment, char *_address, int _source)
Definition 6502.c:192
void cpu_fill_direct(Environment *_environment, char *_address, char *_bytes, char *_pattern)
CPU 6502: emit code to fill up a memory area
Definition 6502.c:555
void cpu_jump_indirect(Environment *_environment, char *_value)
Definition 6502.c:4734
void cpu_math_complement_const_8bit(Environment *_environment, char *_source, int _value)
CPU 6502: emit code to calculate an 8 bit complement of a number
Definition 6502.c:1687
void cpu_dsdefine(Environment *_environment, char *_string, char *_index)
Definition 6502.c:7562
void cpu_math_complement_const_16bit(Environment *_environment, char *_source, int _value)
CPU 6502: emit code to calculate a 16 bit complement of a number
Definition 6502.c:3017
void cpu_move_16bit_unsigned_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9494
void cpu_math_mul2_const_nbit(Environment *_environment, char *_source, int _steps, int _bits)
Definition 6502.c:4538
void cpu_float_single_exp(Environment *_environment, char *_value, char *_result)
Definition 6502.c:9191
void cpu_move_32bit(Environment *_environment, char *_source, char *_destination)
CPU 6502: emit code to move 32 bit
Definition 6502.c:3162
void cpu_fill_size(Environment *_environment, char *_address, int _bytes, char *_pattern)
CPU 6502: emit code to fill up a memory area
Definition 6502.c:462
void cpu_dsfill(Environment *_environment, char *_string, char *_value)
Definition 6502.c:9640
void cpu_less_than_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6502: emit code to compare two 8 bit values
Definition 6502.c:934
void cpu_fill_direct_size_value(Environment *_environment, char *_address, int _bytes, int _pattern)
CPU 6502: emit code to fill up a memory area
Definition 6502.c:646
void cpu_dec_32bit(Environment *_environment, char *_variable)
Definition 6502.c:5830
void cpu_greater_than_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6502.c:2080
void cpu_protothread_get_address(Environment *_environment, char *_index, char *_address)
Definition 6502.c:8022
void cpu_math_add_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6502: emit code to add two 16 bit values
Definition 6502.c:2099
void cpu_greater_than_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6502: emit code to compare two 8 bit values
Definition 6502.c:2065
void cpu_bit_inplace_8bit(Environment *_environment, char *_value, int _position, int *_bit)
Definition 6502.c:7370
void cpu_math_add_16bit_const(Environment *_environment, char *_source, int _destination, char *_other)
CPU 6502: emit code to add two 16 bit values
Definition 6502.c:2131
void cpu_protothread_vars(Environment *_environment)
Definition 6502.c:7901
void cpu_poked_const(Environment *_environment, char *_address, int _source)
Definition 6502.c:315
void cpu_math_add_16bit_with_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6502: emit code to add two 16 bit values
Definition 6502.c:2155
void cpu_float_fast_from_int_array_to_double(Environment *_environment, int _value[], double *_result)
Definition 6502.c:8705
void cpu_compare_and_branch_16bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6502: emit code to compare two 16 bit values and jump if they are equal/different
Definition 6502.c:1885
void cpu_move_32bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6502.c:6762
void cpu_dswrite(Environment *_environment, char *_index)
Definition 6502.c:7610
void cpu_complement2_nbit(Environment *_environment, char *_source, char *_destination, int _bits)
Definition 6502.c:7809
void cpu_greater_than_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6502: emit code to compare two 8 bit values
Definition 6502.c:1088
void cpu_or_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5443
void cpu_fill(Environment *_environment, char *_address, char *_bytes, int _bytes_width, char *_pattern)
CPU 6502: emit code to fill up a memory area
Definition 6502.c:406
void cpu_move_16bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6502.c:6703
void cpu_limit_16bit(Environment *_environment, char *_variable, int _value)
Definition 6502.c:5266
void cpu_move_8bit_indirect_with_offset2(Environment *_environment, char *_source, char *_value, char *_offset)
Definition 6502.c:6655
void cpu_less_than_32bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6502.c:3891
void cpu_move_nbit_indirect2(Environment *_environment, int _n, char *_value, char *_source)
Definition 6502.c:6895
void cpu_and_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5322
void cpu_float_single_log(Environment *_environment, char *_value, char *_result)
Definition 6502.c:9159
void cpu_math_mul_8bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _signed)
CPU 6502: emit code to multiply two 8bit values in a 16 bit register
Definition 6502.c:1235
void cpu_compare_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive)
CPU 6502: emit code to compare two 16 bit values
Definition 6502.c:1826
void cpu_math_sub_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6502: emit code to subtract two 16 bit values
Definition 6502.c:2962
void cpu_compare_and_branch_32bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6502: emit code to compare two 32 bit values and jump if they are equal/different
Definition 6502.c:3742
void cpu_store_nbit(Environment *_environment, char *_destination, int _n, int _value[])
CPU 6502: emit code to store n bit
Definition 6502.c:8300
void cpu_mem_move_direct_indirect_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6502.c:6268
void cpu_dec_nbit(Environment *_environment, char *_variable, int _bits)
Definition 6502.c:5856
void cpu_math_and_const_16bit(Environment *_environment, char *_source, int _mask)
CPU 6502: emit code to mask with "and" a value of 16 bit
Definition 6502.c:3136
void cpu_move_8bit_indirect2_8bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6502.c:6980
void cpu_float_single_from_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6502.c:8859
void cpu_less_than_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _equal, int _signed)
Definition 6502.c:1040
void cpu_fill_indirect(Environment *_environment, char *_address, char *_size, char *_pattern, int _size_size)
Definition 6502.c:7243
void cpu_mem_move_indirect_direct_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6502.c:6365
void cpu_compare_and_branch_char_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6502: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6502.c:905
void cpu_less_than_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _bits)
Definition 6502.c:4042
void cpu_float_fast_sin(Environment *_environment, char *_angle, char *_result)
Definition 6502.c:9123
void cpu_math_mul_nbit_to_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6502.c:2459
void cpu_label(Environment *_environment, char *_label)
Definition 6502.c:148
void cpu_dec(Environment *_environment, char *_variable)
Definition 6502.c:5803
void cpu_and_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5351
void cpu_float_fast_log(Environment *_environment, char *_value, char *_result)
Definition 6502.c:9155
void cpu_move_nbit(Environment *_environment, int _n, char *_source, char *_destination)
CPU cpu6502: emit code to store n bit
Definition 6502.c:4617
void cpu_address_table_call(Environment *_environment, char *_table, char *_value, char *_address)
Definition 6502.c:9328
void cpu_float_single_from_int_array_to_double(Environment *_environment, int _value[], double *_result)
Definition 6502.c:8709
void cpu_logical_not_8bit(Environment *_environment, char *_value, char *_result)
Definition 6502.c:5654
void emit_segment_if_enough_space(Environment *_environment, int _space)
Definition 6502.c:7845
void cpu_pokew_const(Environment *_environment, char *_address, int _source)
Definition 6502.c:246
void cpu_logical_and_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5300
void cpu_or_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6502.c:5429
void cpu_math_div2_const_32bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6502: emit code to halves for several times a 32 bit value
Definition 6502.c:4406
void cpu_halt(Environment *_environment)
Definition 6502.c:5142
void cpu_end(Environment *_environment)
Definition 6502.c:5155
void cpu_float_fast_from_double_to_int_array(Environment *_environment, double _value, int _result[])
Definition 6502.c:8359
void cpu_compare_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6502.c:6397
void cpu_greater_than_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6502.c:1103
void cpu_complement2_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:7750
void cpu_dsinit(Environment *_environment)
Definition 6502.c:7653
void cpu_xor_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5483
void cpu_protothread_unregister(Environment *_environment, char *_index)
Definition 6502.c:7957
void cpu_decrypt(Environment *_environment, char *_data, char *_data_size, char *_key, char *_key_size, char *_output, char *_result)
Definition 6502.c:9595
void cpu_complement2_32bit(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:7772
void cpu_protothread_register_at(Environment *_environment, char *_index, char *_label)
Definition 6502.c:7928
void cpu_blit_free_register(Environment *_environment, int _register)
Definition 6502.c:8261
void cpu_lowercase(Environment *_environment, char *_source, char *_size, char *_result)
Definition 6502.c:7078
void cpu_float_single_to_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6502.c:8883
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6502: emit code to move 16 bit
Definition 6502.c:1730
void cpu_move_8bit_with_offset2(Environment *_environment, char *_source, char *_value, char *_offset)
Definition 6502.c:6671
void cpu_out(Environment *_environment, char *_port, char *_value)
Definition 6502.c:8144
void cpu_move_16bit_unsigned_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9441
void cpu_blit_finalize(Environment *_environment)
Definition 6502.c:8209
void cpu_encrypt(Environment *_environment, char *_data, char *_data_size, char *_key, char *_key_size, char *_output)
Definition 6502.c:9571
void cpu_bneq(Environment *_environment, char *_label)
CPU 6502: emit code to make long conditional jump
Definition 6502.c:112
void cpu_compare_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive, int _bits)
CPU 6502: emit code to compare two 32 bit values
Definition 6502.c:3677
void cpu_move_16bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6502.c:6722
void cpu_float_fast_cmp(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6502.c:9007
void cpu_math_double_8bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6502: emit code to double a 8 bit value
Definition 6502.c:1192
void cpu_float_fast_mul(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6502.c:9041
void cpu_bits_to_string(Environment *_environment, char *_number, char *_string, char *_string_size, int _bits, char *_zero, char *_one)
Definition 6502.c:7471
void cpu_dsalloc(Environment *_environment, char *_size, char *_index)
Definition 6502.c:7576
void cpu_less_than_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _bits)
Definition 6502.c:3982
void cpu_not_32bit(Environment *_environment, char *_value, char *_result)
Definition 6502.c:5699
void cpu_float_single_from_double_to_int_array(Environment *_environment, double _value, int _result[])
Definition 6502.c:8365
void cpu_float_single_to_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6502.c:8907
void cpu_greater_than_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6502.c:6582
void cpu_hex_to_string(Environment *_environment, char *_number, char *_string, char *_size, int _separator)
Definition 6502.c:7538
void cpu_or_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5415
void cpu_store_8bit_with_offset2(Environment *_environment, char *_destination, char *_offset, int _value)
Definition 6502.c:7723
void cpu_move_8bit_indirect2_16bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6502.c:6996
void cpu_math_add_32bit_const(Environment *_environment, char *_source, int _destination, char *_other)
Definition 6502.c:4201
void cpu_move_8bit_indirect_with_offset(Environment *_environment, char *_source, char *_value, int _offset)
Definition 6502.c:6636
void cpu_sqroot(Environment *_environment, char *_number, char *_result)
Definition 6502.c:7829
void cpu_number_to_string(Environment *_environment, char *_number, char *_string, char *_string_size, int _bits, int _signed)
Definition 6502.c:7436
void cpu_greater_than_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6502: emit code to compare two 8 bit values
Definition 6502.c:4103
void cpu_peekd(Environment *_environment, char *_address, char *_target)
Definition 6502.c:265
void cpu_in_direct(Environment *_environment, char *_port, char *_value)
Definition 6502.c:8156
void cpu_call_indirect(Environment *_environment, char *_value)
Definition 6502.c:4707
void cpu_call(Environment *_environment, char *_label)
Definition 6502.c:4697
void cpu_random_8bit(Environment *_environment, char *_entropy, char *_result)
Definition 6502.c:5201
void cpu_xor_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6502.c:5497
void cpu_move_16bit_signed_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9435
void cpu_mem_move_direct(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6502.c:5951
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6502: emit code to store 8 bit
Definition 6502.c:706
void cpu_swap_8bit(Environment *_environment, char *_left, char *_right)
Definition 6502.c:5591
void cpu_float_fast_to_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6502.c:8879
void cpu_mem_move_direct2(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6502.c:6061
void cpu_init(Environment *_environment)
Definition 6502.c:47
void cpu_dstring_vars(Environment *_environment)
Definition 6502.c:7859
void cpu_protothread_loop(Environment *_environment)
Definition 6502.c:7920
void cpu_float_single_div(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6502.c:9086
void cpu_hex_to_bin(Environment *_environment, char *_value_address, char *_value_size, char *_variable_address, char *_variable_size, char *_result)
Definition 6502.c:9621
void cpu_out_direct(Environment *_environment, char *_port, char *_value)
Definition 6502.c:8152
void cpu_greater_than_32bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6502.c:4118
void cpu_protothread_current(Environment *_environment, char *_current)
Definition 6502.c:8013
void cpu_float_fast_to_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6502.c:8903
void cpu_mem_move_16bit(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6502.c:5923
void cpu_compare_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6502: emit code to compare two 32 bit values
Definition 6502.c:3596
void cpu_set_asmio(Environment *_environment, int _asmio, int _value)
Definition 6502.c:4818
void cpu_jump(Environment *_environment, char *_label)
Definition 6502.c:4681
void cpu_move_16bit_unsigned_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9483
int cpu_blit_alloc_register(Environment *_environment)
Definition 6502.c:8225
void cpu_move_32bit_signed_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9516
void cpu_mem_move_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6502.c:6124
void cpu_fill_blocks(Environment *_environment, char *_address, char *_blocks, char *_pattern)
CPU 6502: emit code to fill up a memory area
Definition 6502.c:353
void cpu_bvneq(Environment *_environment, char *_value, char *_label)
Definition 6502.c:137
void cpu_float_single_mul(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6502.c:9045
void cpu_float_fast_exp(Environment *_environment, char *_value, char *_result)
Definition 6502.c:9187
void cpu_move_16bit_signed_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9429
void cpu_compare_and_branch_16bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6502.c:1850
void cpu_fill_size_value(Environment *_environment, char *_address, int _bytes, int _pattern)
CPU 6502: emit code to fill up a memory area
Definition 6502.c:512
void cpu_call_addr(Environment *_environment, int _address)
Definition 6502.c:4691
void cpu_math_div_16bit_to_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _signed)
Definition 6502.c:2768
void cpu_poke(Environment *_environment, char *_address, char *_source)
Definition 6502.c:174
void cpu_bit_check(Environment *_environment, char *_value, int _position, char *_result, int _bitwidth)
Definition 6502.c:7326
void cpu_protothread_register(Environment *_environment, char *_label, char *_index)
Definition 6502.c:7942
void cpu_move_32bit_signed_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9506
void cpu_float_single_to_string(Environment *_environment, char *_x, char *_string, char *_string_size)
Definition 6502.c:8778
void cpu_math_div_nbit_to_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _bits)
Definition 6502.c:3554
void cpu_float_single_tan(Environment *_environment, char *_angle, char *_result)
Definition 6502.c:9255
void cpu_nop(Environment *_environment)
Definition 6502.c:53
void cpu_random_32bit(Environment *_environment, char *_entropy, char *_result)
Definition 6502.c:5241
void cpu_move_16bit_indirect2_8bit(Environment *_environment, char *_value, char *_index, char *_source)
Definition 6502.c:6741
void cpu_move_32bit_unsigned_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9562
void cpu_less_than_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6502.c:995
void cpu_greater_than_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _bits)
Definition 6502.c:4129
void cpu_prepare_for_compare_and_branch_8bit(Environment *_environment, char *_source)
Definition 6502.c:807
void cpu_less_than_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6502: emit code to compare two 8 bit values
Definition 6502.c:1920
void cpu_mem_move_direct2_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6502.c:5998
void cpu_math_and_const_8bit(Environment *_environment, char *_source, int _mask)
CPU 6502: emit code to mask with "and" a value of 8 bit
Definition 6502.c:1707
void cpu_move_32bit_unsigned_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9553
void cpu_msc1_uncompress_direct_direct(Environment *_environment, char *_input, char *_output)
Definition 6502.c:8052
void cpu_inc_32bit(Environment *_environment, char *_variable)
Definition 6502.c:5767
void cpu_move_8bit_signed_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9342
void cpu_mem_move_direct_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6502.c:6171
void cpu_float_fast_sub(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6502.c:8929
void cpu_xor_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5545
void cpu_return(Environment *_environment)
Definition 6502.c:5121
void cpu_move_8bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6502.c:6687
void cpu_inc_nbit(Environment *_environment, char *_variable, int _bits)
Definition 6502.c:5786
void cpu_pop(Environment *_environment)
Definition 6502.c:5131
void cpu_math_sub_16bit_with_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
Definition 6502.c:2986
void cpu_random_16bit(Environment *_environment, char *_entropy, char *_result)
Definition 6502.c:5220
void cpu_ei(Environment *_environment)
Definition 6502.c:5732
int cpu_register_decode(Environment *_environment, char *_register)
Definition 6502.c:4761
void cpu_or_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5460
void cpu_math_div2_const_16bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6502: emit code to halves for several times a 16 bit value
Definition 6502.c:3040
void cpu_convert_string_into_8bit(Environment *_environment, char *_string, char *_len, char *_value)
Definition 6502.c:7142
void cpu_inc_16bit(Environment *_environment, char *_variable)
Definition 6502.c:5752
void cpu_logical_or_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5391
void cpu_compare_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive, int _bits)
Definition 6502.c:3634
void cpu_address_table_lookup(Environment *_environment, char *_table, int _count)
Definition 6502.c:9292
void cpu_ztoa(Environment *_environment)
Definition 6502.c:58
void cpu_random(Environment *_environment, char *_entropy)
Definition 6502.c:5166
void cpu_move_32bit_unsigned_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9522
void cpu_compare_and_branch_8bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6502.c:819
void cpu_execute_compare_and_branch_8bit_const(Environment *_environment, int _destination, char *_label, int _positive)
CPU 6502: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6502.c:877
void cpu_ctoa(Environment *_environment)
Definition 6502.c:75
void cpu_float_single_from_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6502.c:8821
void cpu_math_sub_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6502.c:4350
void cpu_float_single_cmp(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6502.c:9011
void cpu_move_8bit_signed_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9382
void cpu_math_div2_const_nbit(Environment *_environment, char *_source, int _steps, int _bits, char *_remainder)
Definition 6502.c:4456
void cpu_store_8bit_with_offset(Environment *_environment, char *_destination, int _value, int _offset)
Definition 6502.c:7711
void cpu_busy_wait(Environment *_environment, char *_timing)
Definition 6502.c:5285
void cpu_greater_than_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6502.c:6544
void cpu_store_32bit(Environment *_environment, char *_destination, int _value)
CPU 6502: emit code to store 32 bit
Definition 6502.c:3186
void cpu_peekw(Environment *_environment, char *_address, char *_target)
Definition 6502.c:208
void cpu_flip(Environment *_environment, char *_source, char *_size, char *_destination)
Definition 6502.c:7303
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6502: emit code to move 8 bit
Definition 6502.c:688
void cpu_beq(Environment *_environment, char *_label)
CPU 6309: emit code to make long conditional jump
Definition 6502.c:92
void cpu_compare_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6502: emit code to compare two 16 bit values
Definition 6502.c:1785
void cpu_peek(Environment *_environment, char *_address, char *_target)
Definition 6502.c:158
void cpu_float_fast_add(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6502.c:8968
void cpu_convert_string_into_16bit(Environment *_environment, char *_string, char *_len, char *_value)
Definition 6502.c:7163
void cpu_float_single_sin(Environment *_environment, char *_angle, char *_result)
Definition 6502.c:9127
void cpu_not_8bit(Environment *_environment, char *_value, char *_result)
Definition 6502.c:5668
void cpu_math_div_8bit_to_8bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6502.c:1341
void cpu_dsdescriptor(Environment *_environment, char *_index, char *_address, char *_size)
Definition 6502.c:7662
void cpu_math_add_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6502.c:4223
void cpu_compare_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive)
CPU 6502: emit code to compare two 8 bit values
Definition 6502.c:786
void cpu_xor_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6502.c:5511
void cpu_xor_16bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6502.c:5528
void cpu_swap_16bit(Environment *_environment, char *_left, char *_right)
Definition 6502.c:5608
void cpu_compare_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6502: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6502.c:848
void cpu_math_div_32bit_to_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _signed)
Definition 6502.c:3314
void cpu_greater_than_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _bits)
Definition 6502.c:4144
void cpu_float_fast_to_string(Environment *_environment, char *_x, char *_string, char *_string_size)
Definition 6502.c:8774
void cpu_less_than_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6502: emit code to compare two 32 bit values
Definition 6502.c:3783
void cpu_dsfill_value(Environment *_environment, char *_string, int _value)
Definition 6502.c:9651
void cpu_dsassign_string(Environment *_environment, char *_string, char *_copy)
Definition 6502.c:7696
void cpu_move_8bit_signed_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9353
void cpu_move_8bit_unsigned_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:9373
void cpu_compare_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6502.c:6434
void cpu_math_add_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _bits)
Definition 6502.c:4242
void cpu_math_add_8bit_const(Environment *_environment, char *_source, int _destination, char *_other)
CPU 6502: emit code to add two 8 bit values
Definition 6502.c:1147
void cpu_flip_8bit(Environment *_environment, char *_source, char *_destination)
Definition 6502.c:7285
void cpu_blit_initialize(Environment *_environment)
Definition 6502.c:8202
void cpu_less_than_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6502.c:1996
@ REGISTER_YX
Definition 6502.h:73
@ REGISTER_XY
Definition 6502.h:72
@ REGISTER_CARRY
Definition 6502.h:76
@ REGISTER_ZERO
Definition 6502.h:77
@ REGISTER_AXY
Definition 6502.h:74
#define REGISTER_PAGE_ZERO2
Definition 6502.h:58
enum _CPU6502Register CPU6502Register
#define IS_PAGE_ZERO2(x)
Definition 6502.h:61
enum _CPU6502Stack CPU6502Stack
#define IS_PAGE_ZERO(x)
Definition 6502.h:60
#define REGISTER_PAGE_ZERO
Definition 6502.h:57
unsigned char src_hw_6502_bits_to_string_asm[]
unsigned char src_hw_6502_cpu_bit_check_extended_asm[]
unsigned char src_hw_6502_cpu_bit_inplace_asm[]
unsigned char src_hw_6502_cpu_convert_string_into_16bit_asm[]
unsigned char src_hw_6502_cpu_fill_asm[]
unsigned char src_hw_6502_cpu_fill_blocks_asm[]
unsigned char src_hw_6502_cpu_flip_asm[]
unsigned char src_hw_6502_cpu_hex_to_string_asm[]
unsigned char src_hw_6502_cpu_lowercase_asm[]
unsigned char src_hw_6502_cpu_math_div2_const_8bit_asm[]
unsigned char src_hw_6502_cpu_math_div_16bit_to_16bit_asm[]
unsigned char src_hw_6502_cpu_math_div_32bit_to_16bit_asm[]
unsigned char src_hw_6502_cpu_math_div_8bit_to_8bit_asm[]
unsigned char src_hw_6502_cpu_math_mul2_const_8bit_asm[]
unsigned char src_hw_6502_cpu_math_mul_16bit_to_32bit_asm[]
unsigned char src_hw_6502_cpu_math_mul_8bit_to_16bit_asm[]
unsigned char src_hw_6502_cpu_mem_move_asm[]
unsigned char src_hw_6502_cpu_random_asm[]
unsigned char src_hw_6502_cpu_string_sub_asm[]
unsigned char src_hw_6502_cpu_swap_asm[]
unsigned char src_hw_6502_cpu_uppercase_asm[]
unsigned char src_hw_6502_decrypt_asm[]
Definition 6502_decrypt.c:1
unsigned char src_hw_6502_dstring_asm[]
Definition 6502_dstring.c:1
unsigned char src_hw_6502_duff_asm[]
Definition 6502_duff.c:1
unsigned char src_hw_6502_encrypt_asm[]
Definition 6502_encrypt.c:1
unsigned char src_hw_6502_fp_routines_asm[]
unsigned char src_hw_6502_hex2bin_asm[]
Definition 6502_hex2bin.c:1
unsigned char src_hw_6502_msc1_asm[]
Definition 6502_msc1.c:1
unsigned char src_hw_6502_number_to_string_asm[]
unsigned char src_hw_6502_protothread_asm[]
unsigned char src_hw_6502_sqr_asm[]
Definition 6502_sqr.c:1
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
int offset
Definition _optimizer.c:681
#define DSTRING_DEFAULT_SPACE
Definition atari.h:152
#define DSTRING_DEFAULT_COUNT
Definition atari.h:151
Variable * decrypt(Environment *_environment, char *_data, char *_key, char *_var)
Emit code for DECRYPT.
Definition decrypt.c:81
Variable * encrypt(Environment *_environment, char *_data, char *_key)
Emit code for ENCRYPT.
Definition encrypt.c:79
Variable * sign(Environment *_environment, char *_value)
Return the sign of a variable.
Definition sgn.c:85
int usedMemory
Definition ugbc.h:2167
char * name
Definition ugbc.h:2164
int freeRegisters
Definition ugbc.h:2166
char * realName
Definition ugbc.h:2165
int cpu_math_div_nbit_to_nbit_const[32]
Definition ugbc.h:2087
int cpu_math_div_nbit_to_nbit[32]
Definition ugbc.h:2086
int cpu_math_mul_nbit_to_nbit[32]
Definition ugbc.h:2085
int space
Definition ugbc.h:1970
int count
Definition ugbc.h:1969
MemoryArea * memoryAreas
Definition ugbc.h:2689
int bitmaskNeeded
Definition ugbc.h:2659
DString dstring
Definition ugbc.h:2405
Blit blit
Definition ugbc.h:2474
int stackSize
Definition ugbc.h:3294
ProtothreadConfig protothreadConfig
Definition ugbc.h:2430
int emptyProcedure
Definition ugbc.h:2932
CpuOptimization cpuOptimization
Definition ugbc.h:3267
int size
Definition ugbc.h:752
struct _MemoryArea * next
Definition ugbc.h:760
#define no_embedded(s)
Definition ugbc.h:4380
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define CRITICAL_UNSETTABLE_CPU_REGISTER(v)
Definition ugbc.h:3625
#define embedded(s, e)
Definition ugbc.h:4385
#define deploy_with_vars(s, e, v)
Definition ugbc.h:4320
#define no_inline(s)
Definition ugbc.h:4376
#define done()
Definition ugbc.h:4389
#define CRITICAL_BLIT_ALLOC_REGISTER_EXHAUSTED()
Definition ugbc.h:3610
#define outline2(s, a, b)
Definition ugbc.h:4254
struct _Environment Environment
Structure of compilation environment.
struct _MemoryArea MemoryArea
#define CRITICAL_BLIT_INVALID_FREE_REGISTER(s, r)
Definition ugbc.h:3612
#define CRITICAL_BLIT_ALLOC_MEMORY_EXHAUSTED()
Definition ugbc.h:3611
#define CRITICAL_UNKNOWN_CPU_REGISTER()
Definition ugbc.h:3624
#define deploy_preferred(s, e)
Definition ugbc.h:4299
#define outhead0(s)
Definition ugbc.h:4246
#define outline0(s)
Definition ugbc.h:4252
#define outhead2(s, a, b)
Definition ugbc.h:4248
#define outline1(s, a)
Definition ugbc.h:4253
#define deploy_embedded(s, e)
Definition ugbc.h:4339
#define deploy(s, e)
Definition ugbc.h:4288
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247