ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
6309.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#include <time.h>
37#include <math.h>
38
39/****************************************************************************
40 * CODE SECTION
41 ****************************************************************************/
42
43#if defined(__d32b__) || defined(__d64b__) || defined(__cocob__) || defined(__coco3b__)
44
45/* output code that is the best "JUMP" version between "small" and "long" branch.
46 LBRA and LBSR are transformed into JMP and JSR respectively. */
47#define B(code, label) \
48do { /* x-y+128<0 or 127-x+y<0 */ \
49 outline2("IF (((128+%s-(*+2))|(127-%s+(*+2)))&0x8000)",(label),(label)); \
50 if(!strcmp(#code,"RA")) { \
51 outline1("JMP %s", (label)); \
52 } else if(!strcmp(#code,"SR")) { \
53 outline1("JSR %s", (label)); \
54 } else { \
55 outline2("LB%s %s", #code, (label)); \
56 } \
57 outline0("ELSE"); \
58 outline2("B%s %s", #code, (label)); \
59 outline0("ENDIF"); \
60} while(0)
61
62void cpu_init( Environment * _environment ) {
63
64 _environment->stackSize = 0xffff;
65 _environment->stackStartAddress = 0x0000;
66
67}
68
69/* Helper for 8/16 bits comparison */
70static void cpu_compare( Environment * _environment, char *_source, char *_destination, char *_other, int _positive, int _bits) {
71 char REG = _bits==16 ? 'X' : 'A';
72
74
75 outline0("CLRB");
76 outline2("LD%c %s", REG, _source);
77 outline2("CMP%c %s", REG, _destination);
78
79 if(_positive) {
80 outline1("BNE %s", label);
81 outline0("DECB");
82 } else {
83 outline1("BEQ %s", label);
84 outline0("DECB");
85 }
86
87 outhead1("%s", label );
88 outline1("STB %s", _other ? _other : _destination );
89}
90
91/* Helper for 8/16 bits comparison */
92static void cpu_compare_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive, int _bits) {
93 char REG = _bits==16 ? 'X' : 'A';
94
96
97 outline0("CLRB");
98 outline2("LD%c %s", REG, _source);
99 if ( _destination ) {
100 if ( _bits==16 ) {
101 outline2("CMP%c #$%4.4x", REG, _destination);
102 } else {
103 outline2("CMP%c #$%2.2x", REG, _destination);
104 }
105 }
106
107 if(_positive) {
108 outline1("BNE %s", label);
109 outline0("DECB");
110 } else {
111 outline1("BEQ %s", label);
112 outline0("DECB");
113 }
114
115 outhead1("%s", label );
116 outline1("STB %s", _other );
117}
118
119static void cpu_less_than( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed, int _bits) {
120 char REG = _bits==16 ? 'X' : 'A';
121
123
124 outline0("CLRB");
125 outline2("LD%c %s", REG, _source);
126 outline2("CMP%c %s", REG, _destination);
127
128 if ( _signed ) {
129 if ( _equal ) {
130 outline1("BGT %s", label);
131 } else {
132 outline1("BGE %s", label);
133 }
134 } else {
135 if ( _equal ) {
136 outline1("BHI %s", label);
137 } else {
138 outline1("BHS %s", label);
139 }
140 }
141
142 outline0("DECB");
143 outhead1("%s", label );
144 outline1("STB %s", _other ? _other : _destination);
145}
146
147static void cpu_less_than_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed, int _bits) {
148 char REG = _bits==16 ? 'X' : 'A';
149
151
152 outline0("CLRB");
153 outline2("LD%c %s", REG, _source);
154 outline2("CMP%c #$%4.4x", REG, _destination);
155
156 if ( _signed ) {
157 if ( _equal ) {
158 outline1("BGT %s", label);
159 } else {
160 outline1("BGE %s", label);
161 }
162 } else {
163 if ( _equal ) {
164 outline1("BHI %s", label);
165 } else {
166 outline1("BHS %s", label);
167 }
168 }
169
170 outline0("DECB");
171 outhead1("%s", label );
172 outline1("STB %s", _other );
173}
174
175static void cpu_less_than_and_branch_const( Environment * _environment, char *_source, int _destination, char *_label, int _equal, int _signed, int _bits) {
176 char REG = _bits==16 ? 'X' : 'A';
177
179
180 outline0("CLRB");
181 outline2("LD%c %s", REG, _source);
182 outline2("CMP%c #$%4.4x", REG, _destination);
183
184 if ( _signed ) {
185 if ( _equal ) {
186 outline1("BGT %s", label);
187 } else {
188 outline1("BGE %s", label);
189 }
190 } else {
191 if ( _equal ) {
192 outline1("BHI %s", label);
193 } else {
194 outline1("BHS %s", label);
195 }
196 }
197
198 outline1("JMP %s", _label);
199 outhead1("%s", label );
200}
201
202static void cpu_greater_than( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed, int _bits ) {
203 char REG = _bits==16 ? 'X' : 'A';
204
206
207 outline0("LDB #$FF");
208 outline2("LD%c %s", REG, _source);
209 outline2("CMP%c %s", REG, _destination);
210 if ( _signed ) {
211 if ( _equal ) {
212 outline1("BGE %s", label);
213 } else {
214 outline1("BGT %s", label);
215 }
216 } else {
217 if ( _equal ) {
218 outline1("BHS %s", label);
219 } else {
220 outline1("BHI %s", label);
221 }
222 }
223
224 outline0("INCB");
225 outhead1("%s", label );
226 outline1("STB %s", _other ? _other : _destination );
227}
228
229static void cpu_greater_than_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed, int _bits ) {
230 char REG = _bits==16 ? 'X' : 'A';
231
233
234 outline0("LDB #$FF");
235 outline2("LD%c %s", REG, _source);
236 outline2("CMP%c #$%4.4x", REG, _destination);
237 if ( _signed ) {
238 if ( _equal ) {
239 outline1("BGE %s", label);
240 } else {
241 outline1("BGT %s", label);
242 }
243 } else {
244 if ( _equal ) {
245 outline1("BHS %s", label);
246 } else {
247 outline1("BHI %s", label);
248 }
249 }
250
251 outline0("INCB");
252 outhead1("%s", label );
253 outline1("STB %s", _other );
254}
255
256void cpu_nop( Environment * _environment ) {
257
258 outline0("NOP");
259
260}
261
262void cpu_ztoa( Environment * _environment ) {
263
265
266 inline( cpu_ztoa )
267
268 outline1("BEQ %syes", label );
269 outline0("LDA #0");
270 outline1("JMP %s", label );
271 outhead1("%syes", label );
272 outline0("LDA #$ff");
273 outhead1("%s", label );
274
276
277}
278
279void cpu_ctoa( Environment * _environment ) {
280
282
283 inline( cpu_ctoa )
284
285 outline0("LDA #0");
286 outline0("ROLA");
287 outline0("EORA #$FF");
288 outline0("ADDA #1");
289
291
292}
293
308void cpu_beq( Environment * _environment, char * _label ) {
309
310 inline( cpu_beq )
311
312 B(EQ, _label);
313
315
316}
317
324void cpu_bneq( Environment * _environment, char * _label ) {
325
326 inline( cpu_bneq )
327
328 B(NE, _label);
329
331
332}
333
334void cpu_bveq( Environment * _environment, char * _value, char * _label ) {
335
336 inline( cpu_bveq )
337
338 outline1("LDB %s", _value);
339 B(EQ, _label);
340
342
343}
344
345void cpu_bvneq( Environment * _environment, char * _value, char * _label ) {
346
347 inline( cpu_bveq )
348
349 outline1("LDB %s", _value);
350 B(NE, _label);
351
353
354}
355
356void cpu_label( Environment * _environment, char * _label ) {
357
358 inline( cpu_label )
359
360 outhead1("%s", _label);
361
363
364}
365
366void cpu_peek( Environment * _environment, char * _address, char * _target ) {
367
368 inline( cpu_peek )
369
370 outline1("LDB [%s]", _address);
371 outline1("STB %s", _target);
372
374
375}
376
377void cpu_poke( Environment * _environment, char * _address, char * _source ) {
378
379 inline( cpu_poke )
380
381 outline1("LDB %s", _source );
382 outline1("STB [%s]", _address);
383
385
386}
387
388void cpu_poke_const( Environment * _environment, char * _address, int _source ) {
389
390 // inline( cpu_poke )
391
392 outline1("LDB #$%2.2x", (unsigned char)(_source&0xff) );
393 outline1("STB [%s]", _address);
394
395 // no_embedded( cpu_poke )
396
397}
398
399void cpu_peekw( Environment * _environment, char * _address, char * _target ) {
400
401 inline( cpu_peek )
402
403 outline1("LDD [%s]", _address);
404 outline1("STD %s", _target);
405
407
408}
409
410void cpu_pokew( Environment * _environment, char * _address, char * _source ) {
411
412 inline( cpu_poke )
413
414 outline1("LDD %s", _source );
415 outline1("STD [%s]", _address);
416
418
419}
420
421void cpu_pokew_const( Environment * _environment, char * _address, int _source ) {
422
423 // inline( cpu_poke )
424
425 outline1("LDD #$%4.4x", (unsigned int)(_source&0xffff) );
426 outline1("STD [%s]", _address);
427
428 // no_embedded( cpu_poke )
429
430}
431
432void cpu_peekd( Environment * _environment, char * _address, char * _target ) {
433
434 inline( cpu_peek )
435
436 outline1("LDD [%s]", _address);
437 outline1("STD %s", _target);
438 outline1("LDD [%s]", address_displacement( _environment, _address, "2" ) );
439 outline1("STD %s", address_displacement( _environment, _target, "2" ) );
440
442
443}
444
445void cpu_poked( Environment * _environment, char * _address, char * _source ) {
446
447 inline( cpu_poke )
448
449 outline1("LDD %s", _source );
450 outline1("STD [%s]", _address);
451 outline1("LDD %s", address_displacement( _environment, _source, "2" ) );
452 outline1("STD [%s]", address_displacement( _environment, _address, "2" ) );
453
455
456}
457
458void cpu_poked_const( Environment * _environment, char * _address, int _source ) {
459
460 // inline( cpu_poke )
461
462 outline1("LDD #$%4.4x", (unsigned int) (( _source >> 16 ) & 0xffff) );
463 outline1("STD [%s]", _address);
464 outline1("LDD #$%4.4x", (unsigned int) (( _source ) & 0xffff) );
465 outline1("STD [%s]", address_displacement( _environment, _address, "2" ) );
466
467 // no_embedded( cpu_poke )
468
469}
470
484void cpu_fill_blocks( Environment * _environment, char * _address, char * _blocks, char * _pattern ) {
485
486 inline( cpu_fill_blocks )
487
489
490 outline1("LDY %s", _blocks);
491 outline0("TFR Y,D");
492 outline0("LEAY D,Y");
493 outline1("LDA %s", _pattern );
494 outline1("LDX %s", _address);
495 outhead1("%s", label);
496 outline0("LDB #$7f");
497 outhead1("%sinner", label);
498 outline0("STA B,X");
499 outline0("DECB");
500 outline0("CMPB #$ff");
501 outline1("BNE %sinner", label);
502 outline0("LEAX 127,X");
503 outline0("LEAX 1,X");
504 outline0("LEAY -1,Y");
505 outline0("CMPY #$0");
506 outline1("BNE %s", label);
507
508 embedded( cpu_fill_blocks, src_hw_6309_cpu_fill_blocks_asm );
509
510 outline1("LDY %s", _blocks);
511 outline0("TFR Y,D");
512 outline0("LEAY D,Y");
513 outline1("LDA %s", _pattern );
514 outline1("LDX %s", _address);
515 outline0("JSR CPUFILLBLOCKS");
516
517 done( )
518
519}
520
534void cpu_fill( Environment * _environment, char * _address, char * _bytes, int _bytes_width, char * _pattern ) {
535
537
538 embedded( cpu_fill, src_hw_6309_cpu_fill_asm );
539
540 if ( _bytes_width == 8 ) {
541 outline1("LDB %s", _bytes);
542 outline0("CLRA");
543 outline0("TFR D, Y");
544 outline0("JSR CPUFILL8");
545 } else {
546 outline1("LDY %s", _bytes);
547 outline0("JSR CPUFILL16");
548 }
549
550 if ( _pattern ) {
551 outline1("LDA %s", _pattern );
552 } else {
553 outline0("LDA #0");
554 }
555
556 outline1("LDX %s", _address);
557
558 done( )
559
560}
561
575void cpu_fill_size( Environment * _environment, char * _address, int _bytes, char * _pattern ) {
576
578
579 embedded( cpu_fill, src_hw_6309_cpu_fill_asm );
580
581 if ( _pattern ) {
582 outline1("LDA %s", _pattern );
583 } else {
584 outline0("LDX #0");
585 }
586 outline1("LDX %s", _address);
587 outline1("LDY #$%4.4x", _bytes );
588 if ( _bytes < 256 ) {
589 outline0("JSR CPUFILL8");
590 } else {
591 outline0("JSR CPUFILL16");
592 }
593
594 done( )
595
596}
597
611void cpu_fill_size_value( Environment * _environment, char * _address, int _bytes, int _pattern ) {
612
614
615 embedded( cpu_fill, src_hw_6309_cpu_fill_asm );
616
617 outline1("LDA #$%2.2x", _pattern );
618 outline1("LDX %s", _address);
619 outline1("LDY #$%4.4x", _bytes );
620 if ( _bytes < 256 ) {
621 outline0("JSR CPUFILL8");
622 } else {
623 outline0("JSR CPUFILL16");
624 }
625
626 done( )
627
628}
629
643void cpu_fill_direct( Environment * _environment, char * _address, char * _bytes, char * _pattern ) {
644
646
647 embedded( cpu_fill, src_hw_6309_cpu_fill_asm );
648
649 if ( _pattern ) {
650 outline1("LDA %s", _pattern );
651 } else {
652 outline0("LDA #0");
653 }
654 outline1("LDX #%s", _address);
655 outline1("LDY %s", _bytes);
656 outline0("JSR CPUFILL16");
657
658 done( )
659
660}
661
675void cpu_fill_direct_size( Environment * _environment, char * _address, int _bytes, char * _pattern ) {
676
678
679 embedded( cpu_fill, src_hw_6309_cpu_fill_asm );
680
681 if ( _pattern ) {
682 outline1("LDA %s", _pattern );
683 } else {
684 outline0("LDA #0");
685 }
686 outline1("LDX #%s", _address);
687 outline1("LDY #$%4.4x", _bytes);
688
689 if ( _bytes < 256 ) {
690 outline0("JSR CPUFILL8");
691 } else {
692 outline0("JSR CPUFILL16");
693 }
694
695 done( )
696
697}
698
712void cpu_fill_direct_size_value( Environment * _environment, char * _address, int _bytes, int _pattern ) {
713
715
716 embedded( cpu_fill, src_hw_6309_cpu_fill_asm );
717
718 outline1("LDA #$%2.2x", _pattern );
719 outline1("LDX #%s", _address);
720 outline1("LDY #$%4.4x", _bytes);
721
722 if ( _bytes < 256 ) {
723 outline0("JSR CPUFILL8");
724 } else {
725 outline0("JSR CPUFILL16");
726 }
727
728 done( )
729
730}
731
732/*****************************************************************************
733 * 8 BIT MANIPULATION
734 ****************************************************************************/
735
743void cpu_move_8bit( Environment * _environment, char *_source, char *_destination ) {
744
745 inline( cpu_move_8bit )
746
747 outline1("LDB %s", _source);
748 outline1("STB %s", _destination);
749
751
752}
753
761void cpu_store_8bit( Environment * _environment, char *_destination, int _value ) {
762
763 inline( cpu_store_8bit )
764
765 if(_value) {
766 outline1("LDB #$%2.2x" , (unsigned char)(_value & 0xff) );
767 outline1("STB %s", _destination );
768 } else {
769 // make A=0 as much as possible
770 outline0("CLRA");
771 outline1("STA %s", _destination );
772 }
773
775
776}
777
785void cpu_store_char( Environment * _environment, char *_destination, int _value ) {
786
787 inline( cpu_store_char )
788
789 if(_value) {
790 outline1("LDB #'%c'" , _value );
791 outline1("STB %s", _destination );
792 } else {
793 // make A=0 as much as possible
794 outline0("CLRA");
795 outline1("STA %s", _destination );
796 }
797
799
800}
801
811void cpu_compare_8bit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive ) {
812
813 inline( cpu_compare_8bit )
814
815 cpu_compare(_environment,_source, _destination, _other, _positive, 8);
816
818
819}
820
821
831void cpu_compare_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive ) {
832
833 inline( cpu_compare_8bit )
834
835 cpu_compare_const(_environment,_source, _destination, _other, _positive, 8);
836
838
839}
840
841void cpu_prepare_for_compare_and_branch_8bit( Environment * _environment, char *_source ) {
842
844
845 outline1("LDB %s", _source);
846
848
849}
850
851void cpu_compare_and_branch_8bit( Environment * _environment, char *_source, char * _destination, char *_label, int _positive ) {
852
854
855 outline1("LDB %s", _source);
856 outline1("CMPB %s", _destination);
857 if ( _positive ) {
858 B(EQ, _label);
859 } else {
860 B(NE, _label);
861 }
862
864
865}
866
876void cpu_compare_and_branch_8bit_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
877
879
880 outline1("LDB %s", _source);
881 outline1("CMPB #$%2.2x", _destination);
882 if ( _positive ) {
883 B(EQ, _label);
884 } else {
885 B(NE, _label);
886 }
887
889
890}
891
901void cpu_execute_compare_and_branch_8bit_const( Environment * _environment, int _destination, char *_label, int _positive ) {
902
904
905 outline1("CMPB #$%2.2x", _destination);
906 if ( _positive ) {
907 B(EQ, _label);
908 } else {
909 B(NE, _label);
910 }
911
913
914}
915
925void cpu_compare_and_branch_char_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
926
928
929 outline1("LDB %s", _source);
930 outline1("CMPB #'%c'", _destination);
931 if ( _positive ) {
932 B(EQ, _label);
933 } else {
934 B(NE, _label);
935 }
936
938
939}
940
950void cpu_less_than_8bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
951
952 inline( cpu_less_than_8bit )
953
954 cpu_less_than(_environment, _source, _destination, _other, _equal, _signed, 8);
955
957
958}
959
960void cpu_less_than_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
961
963
964 cpu_less_than_const(_environment, _source, _destination, _other, _equal, _signed, 8);
965
967
968}
969
970void cpu_less_than_and_branch_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
971
973
974 cpu_less_than_and_branch_const(_environment, _source, _destination, _other, _equal, _signed, 8);
975
977
978}
979
989void cpu_greater_than_8bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
990
991 inline( cpu_greater_than_8bit )
992
993 cpu_greater_than(_environment, _source, _destination, _other, _equal, _signed, 8);
994
996
997}
998
999void cpu_greater_than_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
1000
1001 inline( cpu_greater_than_8bit )
1002
1003 cpu_greater_than_const(_environment, _source, _destination, _other, _equal, _signed, 8);
1004
1006
1007}
1008
1017void cpu_math_add_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
1018
1019 inline( cpu_math_add_8bit )
1020
1021 outline1("LDB %s", _source);
1022 outline1("ADDB %s", _destination);
1023 outline1("STB %s", _other ? _other : _destination);
1024
1026
1027}
1028
1029void cpu_math_add_8bit_const( Environment * _environment, char *_source, int _destination, char *_other ) {
1030
1031 inline( cpu_math_add_8bit )
1032
1033 outline1("LDB %s", _source);
1034 outline1("ADDB #$%2.2x", ( _destination & 0xff ) );
1035 outline1("STB %s", _other );
1036
1038
1039}
1040
1049void cpu_math_sub_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
1050
1051 inline( cpu_math_sub_8bit )
1052
1053 outline1("LDB %s", _source);
1054 outline1("SUBB %s", _destination);
1055 outline1("STB %s", _other ? _other : _destination);
1056
1058
1059}
1060
1068void cpu_math_double_8bit( Environment * _environment, char *_source, char *_other, int _signed ) {
1069
1070 inline( cpu_math_sub_8bit )
1071
1072 outline1("LDB %s", _source);
1073 outline0("ASLB");
1074 outline1("STB %s", _other ? _other : _source);
1075
1077
1078}
1079
1088void cpu_math_mul_8bit_to_16bit( Environment * _environment, char *_source, char *_destination, char *_other, int _signed ) {
1089
1091
1093
1094 if ( _signed ) {
1095
1096 outline0("LDA #0" );
1097 outline0("STA <MATHPTR0" );
1098 outline1("LDA %s", _source );
1099 outline1("EORA %s", _destination );
1100 outline0("ANDA #$80" );
1101 outline1("BEQ %ssamesign", label );
1102 outline0("STA <MATHPTR0" );
1103 outhead1("%ssamesign", label );
1104
1105 outline1("LDA %s", _source );
1106 outline0("ANDA #$80" );
1107 outline1("BEQ %spositive1", label );
1108 outline1("LDA %s", _source );
1109 outline0("EORA #$FF" );
1110 outline0("ADDA #1" );
1111 outline1("JMP %spositive1b", label );
1112
1113 outhead1("%spositive1", label );
1114 outline1("LDA %s", _source );
1115 outhead1("%spositive1b", label );
1116 outline1("LDB %s", _destination );
1117 outline0("ANDB #$80" );
1118 outline1("BEQ %spositive2", label );
1119 outline1("LDB %s", _destination );
1120 outline0("EORB #$FF" );
1121 outline0("ADDB #1" );
1122 outline1("JMP %spositive2b", label );
1123
1124 outhead1("%spositive2", label );
1125 outline1("LDB %s", _destination );
1126 outhead1("%spositive2b", label );
1127 } else {
1128 outline1("LDA %s", _source );
1129 outline1("LDB %s", _destination );
1130 }
1131
1132 outline0("MUL" );
1133
1134 outline1("STD %s", _other );
1135
1136 if ( _signed ) {
1137 outline0("LDA <MATHPTR0" );
1138 outline0("CMPA #0" );
1139 outline1("BEQ %sdone", label );
1140 outline1("LDD %s", _other );
1141 outline0("EORA #$FF" );
1142 outline0("EORB #$FF" );
1143 outline0("ADDD #1" );
1144 outline1("STD %s", _other );
1145 outhead1("%sdone", label );
1146 }
1147
1148 embedded( cpu_math_mul_8bit_to_16bit, src_hw_6309_cpu_math_mul_8bit_to_16bit_asm );
1149
1150 outline1("LDB %s", _source );
1151 outline1("LDA %s", _destination );
1152 if ( _signed ) {
1153 outline0("JSR CPUMATHMUL8BITTO16BIT_SIGNED" );
1154 } else {
1155 outline0("MUL" );
1156 }
1157 outline1("STD %s", _other );
1158
1159 done( )
1160
1161}
1162
1163void cpu_math_div_8bit_to_8bit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _signed ) {
1164
1166
1168 outline0("LDX #$0");
1169 outline1("LDA %s", _destination);
1170 if ( _signed ) {
1171 outline0("ANDA #$80");
1172 outline0("CMPA #$0");
1173 outline1("BEQ %spos1", label);
1174 outline0("LDX #$1");
1175 outline1("LDA %s", _destination);
1176 outline0("EORA #$FF");
1177 outline0("ADDA #$1");
1178 outline0("STA <TMPPTR");
1179 outline1("JMP %sdone1", label);
1180 outhead1("%spos1", label );
1181 outline0("STA <TMPPTR");
1182 outline1("JMP %sdone1", label);
1183 outhead1("%sdone1", label );
1184 } else {
1185 outline0("STA <TMPPTR");
1186 }
1187 outline1("LDA %s", _source);
1188 if ( _signed ) {
1189 outline0("ANDA #$80");
1190 outline0("CMPA #$0");
1191 outline1("BEQ %spos2", label);
1192 outline0("LDX #$1");
1193 outline1("LDA %s", _source);
1194 outline0("EORA #$FF");
1195 outline0("ADDA #$1");
1196 outline0("STA <TMPPTR+1");
1197 outline1("JMP %sdone2", label);
1198 outhead1("%spos2", label );
1199 outline0("STA <TMPPTR+1");
1200 outline1("JMP %sdone2", label);
1201 outhead1("%sdone2", label );
1202 } else {
1203 outline0("STA <TMPPTR+1");
1204 }
1205 outhead1("%spos", label );
1206 outline0("LDA #$8");
1207 outline1("STA %s", _other_remainder);
1208 outline0("LDA #$0" );
1209 outline0("LDB <TMPPTR+1" );
1210 outhead1("%sdivide", label );
1211 outline0("LSLD" );
1212 outline0("CMPA <TMPPTR");
1213 outline1("BCS %schkcnt", label );
1214 outline0("SUBA <TMPPTR" );
1215 outline0("INCB" );
1216 outhead1("%schkcnt", label );
1217 outline1("DEC %s", _other_remainder );
1218 outline1("BNE %sdivide", label );
1219 outline1("STB %s", _other );
1220 outline0("CMPX #$1");
1221 outline1("BNE %sdone", label);
1222 outline0("ADDA 1" );
1223 outhead1("%sdone", label );
1224 outline1("STA %s", _other_remainder );
1225
1226 embedded( cpu_math_div_8bit_to_8bit, src_hw_6309_cpu_math_div_8bit_to_8bit_asm );
1227
1228 outline1("LDB %s", _source);
1229 outline1("LDA %s", _destination);
1230 if ( _signed ) {
1231 outline0("JSR CPUMATHDIV8BITTO8BIT_SIGNED");
1232 } else {
1233 outline0("JSR CPUMATHDIV8BITTO8BIT");
1234 }
1235 outline1("STA %s", _other_remainder);
1236 outline1("STB %s", _other);
1237
1238 done( )
1239
1240}
1241
1242void cpu_math_div_8bit_to_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _signed ) {
1243
1245
1247 outline0("LDX #$0");
1248 outline1("LDA #$%2.2x", (unsigned char)((_destination) & 0xff) );
1249 if ( _signed ) {
1250 outline0("ANDA #$80");
1251 outline0("CMPA #$0");
1252 outline1("BEQ %spos1", label);
1253 outline0("LDX #$1");
1254 outline1("LDA #%2.2x", (unsigned char)((_destination) & 0xff));
1255 outline0("EORA #$FF");
1256 outline0("ADDA #$1");
1257 outline0("STA <TMPPTR");
1258 outline1("JMP %sdone1", label);
1259 outhead1("%spos1", label );
1260 outline0("STA <TMPPTR");
1261 outline1("JMP %sdone1", label);
1262 outhead1("%sdone1", label );
1263 } else {
1264 outline0("STA <TMPPTR");
1265 }
1266 outline1("LDA %s", _source);
1267 if ( _signed ) {
1268 outline0("ANDA #$80");
1269 outline0("CMPA #$0");
1270 outline1("BEQ %spos2", label);
1271 outline0("LDX #$1");
1272 outline1("LDA %s", _source);
1273 outline0("EORA #$FF");
1274 outline0("ADDA #$1");
1275 outline0("STA <TMPPTR+1");
1276 outline1("JMP %sdone2", label);
1277 outhead1("%spos2", label );
1278 outline0("STA <TMPPTR+1");
1279 outline1("JMP %sdone2", label);
1280 outhead1("%sdone2", label );
1281 } else {
1282 outline0("STA <TMPPTR+1");
1283 }
1284 outhead1("%spos", label );
1285 outline0("LDA #$8");
1286 outline1("STA %s", _other_remainder);
1287 outline0("LDA #$0" );
1288 outline0("LDB <TMPPTR+1" );
1289 outhead1("%sdivide", label );
1290 outline0("ASLB" );
1291 outline0("ROLA" );
1292 outline0("CMPA <TMPPTR");
1293 outline1("BCS %schkcnt", label );
1294 outline0("SUBA <TMPPTR" );
1295 outline0("INCB" );
1296 outhead1("%schkcnt", label );
1297 outline1("DEC %s", _other_remainder );
1298 outline1("BNE %sdivide", label );
1299 outline1("STB %s", _other );
1300 outline0("CMPX #$1");
1301 outline1("BNE %sdone", label);
1302 outline0("ADDA 1" );
1303 outhead1("%sdone", label );
1304 outline1("STA %s", _other_remainder );
1305
1306 embedded( cpu_math_div_8bit_to_8bit, src_hw_6309_cpu_math_div_8bit_to_8bit_asm );
1307
1308 outline1("LDB %s", _source);
1309 outline1("LDA #$%2.2x", (unsigned char)((_destination) & 0xff));
1310 if ( _signed ) {
1311 outline0("JSR CPUMATHDIV8BITTO8BIT_SIGNED");
1312 } else {
1313 outline0("JSR CPUMATHDIV8BITTO8BIT");
1314 }
1315 outline1("STA %s", _other_remainder);
1316 outline1("STB %s", _other);
1317
1318 done( )
1319
1320}
1321
1329void cpu_math_div2_const_8bit( Environment * _environment, char *_source, int _steps, int _signed, char * _remainder ) {
1330
1331 inline( cpu_math_div2_const_8bit )
1332
1334
1335 if ( _remainder ) {
1336 outline1("LDA %s", _source);
1337 outline0("ANDA #$01");
1338 outline1("STA %s", _remainder);
1339 }
1340 if ( _signed ) {
1341 outline0("LDA #0");
1342 outline0("STA <MATHPTR0");
1343 outline1("LDA %s", _source);
1344 outline0("ANDA #$80");
1345 outline1("BEQ %spos", label);
1346 outline0("EORA #$FF");
1347 outline0("ADDA #1");
1348 outline0("LDA #1");
1349 outline0("STA <MATHPTR0");
1350 outhead1("%spos", label);
1351 }
1352 outline1("LDA %s", _source);
1353 outline1("LDB #$%2.2x", (unsigned char)(_steps & 0xff));
1354 outline0("CMPB #0");
1355 outline1("BEQ %sdone", label);
1356 outhead1("%sloop", label);
1357 outline0("ASRA");
1358 outline0("DECB");
1359 outline0("CMPB #0");
1360 outline1("BNE %sloop", label);
1361 outhead1("%sdone", label);
1362 if ( _signed ) {
1363 outline0("LDA <MATHPTR0");
1364 outline1("BEQ %spos2", label);
1365 outline0("EORA #$FF");
1366 outline0("ADDA #1");
1367 outhead1("%spos2", label);
1368 }
1369 outline1("STA %s", _source);
1370
1371 embedded( cpu_math_div2_const_8bit, src_hw_6309_cpu_math_div2_const_8bit_asm );
1372
1373 if ( _remainder ) {
1374 outline1("LDA %s", _source);
1375 outline0("ANDA #$01");
1376 outline1("STA %s", _remainder);
1377 }
1378 outline1("LDB %s", _source);
1379 outline1("LDA #$%2.2x", _steps);
1380 if ( _signed ) {
1381 outline0("JSR CPUMATHDIV28BIT_SIGNED");
1382 } else {
1383 outline0("JSR CPUMATHDIV28BIT");
1384 }
1385 outline1("STB %s", _source);
1386
1387 done( )
1388}
1389
1397void cpu_math_mul2_const_8bit( Environment * _environment, char *_source, int _steps, int _signed ) {
1398 int i;
1399
1400 inline( cpu_math_mul2_const_8bit )
1401
1402 outline1("LDB %s", _source );
1403 if ( ! _environment->cpuOptimization.cpu_math_mul2_const_8bit_generated[_steps] ) {
1404
1405 _environment->cpuOptimization.cpu_math_mul2_const_8bit_generated[_steps] = 1;
1406
1408
1409 outline1("BRA %s", label);
1410 outhead1("cpu_math_mul2_const_8bit_%d", _steps);
1411 for(i=0; i<_steps; ++i) {
1412 outline0("LSLB" );
1413 }
1414 outline0("RTS" );
1415 outhead1("%s", label);
1416
1417 }
1418 outline1("JSR cpu_math_mul2_const_8bit_%d", _steps );
1419 outline1("STB %s", _source );
1420
1422
1423}
1424
1432void cpu_math_complement_const_8bit( Environment * _environment, char *_source, int _value ) {
1433
1435
1436 outline1("LDB #$%2.2x", (unsigned char)(_value & 0xff));
1437 outline1("SUBB %s", _source);
1438 outline1("STB %s", _source);
1439
1441
1442}
1443
1451void cpu_math_and_const_8bit( Environment * _environment, char *_source, int _mask ) {
1452
1453 inline( cpu_math_and_const_8bit )
1454
1455 outline1("LDB %s", _source);
1456 outline1("ANDB #$%2.2x", _mask);
1457 outline1("STB %s", _source);
1458
1460
1461}
1462
1463/*****************************************************************************
1464 * 16 BIT MANIPULATION
1465 ****************************************************************************/
1466
1474void cpu_move_16bit( Environment * _environment, char *_source, char *_destination ) {
1475
1476 inline( cpu_move_16bit )
1477
1478 outline1("LDD %s", _source);
1479 outline1("STD %s", _destination);
1480
1482
1483}
1484
1485void cpu_addressof_16bit( Environment * _environment, char *_source, char *_destination ) {
1486
1487 inline( cpu_addressof_16bit )
1488
1489 outline1("LDD #%s", _source);
1490 outline1("STD %s", _destination);
1491
1493
1494}
1495
1503void cpu_store_16bit( Environment * _environment, char *_destination, int _value ) {
1504
1505 inline( cpu_store_16bit )
1506
1507 outline1("LDD #$%4.4x", (unsigned int)( _value & 0xffff ) );
1508 outline1("STD %s", _destination );
1509
1511
1512}
1513
1523void cpu_compare_16bit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive ) {
1524
1525 inline( cpu_compare_16bit )
1526
1527 cpu_compare( _environment, _source, _destination, _other, _positive, 16 );
1528
1530
1531}
1532
1542void cpu_compare_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive ) {
1543
1544 inline( cpu_compare_16bit )
1545
1546 cpu_compare_const( _environment, _source, _destination, _other, _positive, 16 );
1547
1549
1550}
1551
1552void cpu_compare_and_branch_16bit( Environment * _environment, char *_source, char *_destination, char *_label, int _positive ) {
1553
1555
1556 outline1("LDX %s", _source);
1557 outline1("CMPX %s", _destination);
1558 if ( _positive ) {
1559 B(EQ, _label);
1560 } else {
1561 B(NE, _label);
1562 }
1563
1565
1566}
1567
1568
1578void cpu_compare_and_branch_16bit_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
1579
1581
1582 outline1("LDX %s", _source);
1583 outline1("CMPX #$%4.4x", _destination);
1584 if ( _positive ) {
1585 B(EQ, _label);
1586 } else {
1587 B(NE, _label);
1588 }
1589
1591
1592}
1593
1603void cpu_less_than_16bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
1604
1605 inline( cpu_less_than_16bit )
1606
1607 cpu_less_than( _environment, _source, _destination, _other, _equal, _signed, 16 );
1608
1610
1611}
1612
1613void cpu_less_than_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
1614
1616
1617 cpu_less_than_const( _environment, _source, _destination, _other, _equal, _signed, 16 );
1618
1620
1621}
1622
1632void cpu_greater_than_16bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
1633
1634 inline( cpu_greater_than_16bit )
1635
1636 cpu_greater_than( _environment, _source, _destination, _other, _equal, _signed, 16 );
1637
1639
1640}
1641
1642void cpu_greater_than_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
1643
1644 inline( cpu_greater_than_16bit )
1645
1646 cpu_greater_than_const( _environment, _source, _destination, _other, _equal, _signed, 16 );
1647
1649
1650}
1651
1652
1661void cpu_math_add_16bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
1662
1663 inline( cpu_math_add_16bit )
1664
1665 // this way has more affinity with peephole optimizations
1666 outline1("LDD %s", _destination);
1667 outline1("ADDD %s", _source);
1668 outline1("STD %s", _other ? _other : _destination);
1669
1671
1672}
1673
1674void cpu_math_add_16bit_const( Environment * _environment, char *_source, int _destination, char *_other ) {
1675
1676 inline( cpu_math_add_16bit_const )
1677
1678 // this way has more affinity with peephole optimizations
1679 outline1("LDD #$%4.4x", ( _destination & 0xffff ) );
1680 outline1("ADDD %s", _source);
1681 outline1("STD %s", _other );
1682
1684
1685}
1686
1687
1696void cpu_math_add_16bit_with_16bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
1697
1699
1700 outline1("LDD %s", _source);
1701 outline1("ADDD #%s", _destination);
1702 outline1("STD %s", _other ? _other : _destination);
1703
1705
1706}
1707
1708void cpu_math_add_16bit_with_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
1709
1711
1712 outline1("LDX %s", _source);
1713 outline1("LDB %s", _destination);
1714 outline0("ABX");
1715 outline1("STX %s", _other ? _other : _destination );
1716
1718
1719}
1720
1728void cpu_math_double_16bit( Environment * _environment, char *_source, char *_other, int _signed ) {
1729
1730 inline( cpu_math_double_16bit )
1731
1732 outline1("LDD %s", _source);
1733 outline0("LSLD");
1734 if ( _other ) {
1735 outline1("STD %s", _other);
1736 } else {
1737 outline1("STD %s", _source);
1738 }
1739
1741
1742}
1743
1752void cpu_math_mul_16bit_to_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _signed ) {
1753
1755
1757
1758 if ( _signed ) {
1759 outline0("LDA #0" );
1760 outline0("STA <TMPPTR" );
1761 outline1("LDA %s", _source );
1762 outline1("EORA %s", _destination );
1763 outline0("ANDA #$80" );
1764 outline1("BEQ %ssamesign", label );
1765 outline0("STA <TMPPTR" );
1766 outhead1("%ssamesign", label );
1767
1768 outline1("LDA %s", _source );
1769 outline0("ANDA #$80" );
1770 outline1("BEQ %spos1", label );
1771 outline1("LDA %s", address_displacement(_environment, _source, "1") );
1772 outline0("EORA #$FF" );
1773 outline0("STA <MATHPTR1" );
1774 outline1("LDA %s", _source );
1775 outline0("EORA #$FF" );
1776 outline0("STA <MATHPTR0" );
1777 outline0("LDX <MATHPTR0" );
1778 outline0("LEAX 1,X" );
1779 outline0("STX <MATHPTR0" );
1780 outline1("JMP %sdone1", label );
1781 outhead1("%spos1", label );
1782 outline1("LDX %s", _source );
1783 outline0("STX <MATHPTR0" );
1784 outhead1("%sdone1", label );
1785
1786 outline1("LDA %s", _destination );
1787 outline0("ANDA #$80" );
1788 outline1("BEQ %spos2", label );
1789 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
1790 outline0("EORA #$FF" );
1791 outline0("STA <MATHPTR3" );
1792 outline1("LDA %s", _destination );
1793 outline0("EORA #$FF" );
1794 outline0("STA <MATHPTR2" );
1795 outline0("LDX <MATHPTR2" );
1796 outline0("LEAX 1,X" );
1797 outline0("STX <MATHPTR2" );
1798 outline1("JMP %sdone2", label );
1799 outhead1("%spos2", label );
1800 outline1("LDX %s", _destination );
1801 outline0("STX <MATHPTR2" );
1802 outhead1("%sdone2", label );
1803 } else {
1804 outline1("LDD %s", _source );
1805 outline0("STD <MATHPTR0" );
1806 outline1("LDD %s", _destination );
1807 outline0("STD <MATHPTR2" );
1808 }
1809 outline0("LDA <MATHPTR0" );
1810 outline0("LDB <MATHPTR2" );
1811 outline0("MUL");
1812 outline1("STD %s", _other );
1813
1814 outline0("LDA <MATHPTR1" );
1815 outline0("LDB <MATHPTR3" );
1816 outline0("MUL" );
1817 outline1("STD %s", address_displacement(_environment, _other, "2") );
1818
1819 outline0("LDA <MATHPTR1" );
1820 outline0("LDB <MATHPTR2" );
1821 outline0("MUL" );
1822 outline0("TFR D, X" );
1823
1824 outline0("LDA <MATHPTR0" );
1825 outline0("LDB <MATHPTR3" );
1826 outline0("MUL" );
1827 outline0("LEAX D, X" );
1828
1829 outline0("TFR X, D" );
1830
1831 outline1("ADDB %s", address_displacement(_environment, _other, "2") );
1832 outline1("STB %s", address_displacement(_environment, _other, "2") );
1833
1834 outline1("ADDA %s", address_displacement(_environment, _other, "1") );
1835 outline1("STA %s", address_displacement(_environment, _other, "1") );
1836
1837 if ( _signed ) {
1838 outline0("LDA <TMPPTR" );
1839 outline0("CMPA #0" );
1840 outline1("BEQ %sdonex", label );
1841 outline1("LDA %s", _other );
1842 outline0("EORA #$FF" );
1843 outline1("STA %s", _other );
1844 outline1("LDA %s", address_displacement(_environment, _other, "1") );
1845 outline0("EORA #$FF" );
1846 outline1("STA %s", address_displacement(_environment, _other, "1") );
1847 outline1("LDA %s", address_displacement(_environment, _other, "2") );
1848 outline0("EORA #$FF" );
1849 outline1("STA %s", address_displacement(_environment, _other, "2") );
1850 outline1("LDA %s", address_displacement(_environment, _other, "3") );
1851 outline0("EORA #$FF" );
1852 outline1("STA %s", address_displacement(_environment, _other, "3") );
1853 outline1("LDA %s", address_displacement(_environment, _other, "3") );
1854 outline0("ADDA #1" );
1855 outline1("STA %s", address_displacement(_environment, _other, "3") );
1856 outline1("LDA %s", address_displacement(_environment, _other, "2") );
1857 outline0("ADDA #0" );
1858 outline1("STA %s", address_displacement(_environment, _other, "2") );
1859 outline1("LDA %s", address_displacement(_environment, _other, "1") );
1860 outline0("ADDA #0" );
1861 outline1("STA %s", address_displacement(_environment, _other, "1") );
1862 outline1("LDA %s", _other );
1863 outline0("ADDA #0" );
1864 outline1("STA %s", _other );
1865 outhead1("%sdonex", label );
1866 }
1867
1868 embedded( cpu_math_mul_16bit_to_32bit, src_hw_6309_cpu_math_mul_16bit_to_32bit_asm );
1869
1870 outline1("LDD %s", _destination );
1871 outline1("LDX %s", _source );
1872
1873 if ( _signed ) {
1874 outline0("JSR CPUMATHMUL16BITTO32BIT_SIGNED" );
1875 } else {
1876 outline0("JSR CPUMATHMUL16BITTO32BIT" );
1877 }
1878
1879 outline1("STX %s", _other );
1880 outline1("STD %s", address_displacement(_environment, _other, "2") );
1881
1882 done( )
1883
1884}
1885
1886void cpu_math_mul_nbit_to_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _bits ) {
1887
1889
1890 int i;
1891
1892 char afterLabel[MAX_TEMPORARY_STORAGE]; sprintf( afterLabel, "%safter", label);
1893 char destination[MAX_TEMPORARY_STORAGE]; sprintf( destination, "CPUMATHMULNBITTONBIT%d_DESTINATION", (_bits>>3));
1894 char source[MAX_TEMPORARY_STORAGE]; sprintf( source, "CPUMATHMULNBITTONBIT%d_SOURCE", (_bits>>3));
1895 char other[MAX_TEMPORARY_STORAGE]; sprintf( other, "CPUMATHMULNBITTONBIT%d_OTHER", (_bits>>3));
1896
1897 // no_inline( cpu_math_mul_nbit_to_nbit )
1898
1899 // embedded( cpu_math_mul_nbit_to_nbit, src_hw_6502_cpu_math_mul_nbit_to_nbit_asm )
1900
1901 if ( ! _environment->cpuOptimization.cpu_math_mul_nbit_to_nbit[_bits>>3] ) {
1902
1903 outline1("JMP %s", afterLabel );
1904
1905 outhead2("CPUMATHMULNBITTONBIT%d_SOURCE rzb %d", _bits>>3, _bits>>3 );
1906 outhead2("CPUMATHMULNBITTONBIT%d_DESTINATION rzb %d", _bits>>3, _bits>>3 );
1907 outhead2("CPUMATHMULNBITTONBIT%d_OTHER rzb %d", _bits>>3, _bits>>3 );
1908
1909 outhead1("CPUMATHMULNBITTONBIT%d", _bits>>3);
1910 outline0("LDA #$00");
1911 for( i=0; i<(_bits>>3); ++i ) {
1912 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
1913 outline1("STA %s", address_displacement( _environment, other, offset ) );
1914 }
1915 outline1("LDB #$%2.2x", _bits );
1916
1917 outhead1("CPUMATHMULNBITTONBIT%dL1", _bits>>3);
1918
1919 // The process of multiplying binary numbers is similar and easier to do than
1920 // decimal multiplication as binary numbers consist of only two digits which
1921 // are 0 and 1. The method of multiplying binary numbers is given below. The
1922 // same set of rules also apply to binary numbers with a decimal point. Let
1923 // us take the example of multiplying (11101) and (1001).
1924 //
1925 // The decimal equivalent of (11101) is 29 and the decimal equivalent
1926 // of (1001) is 9. Now let us multiply these numbers.
1927
1928 // Step 1: Write down the multiplicand (11101) and the multiplier (1001)
1929 // one below the other in proper positions.
1930
1931 char multiplyByBit0Label[MAX_TEMPORARY_STORAGE]; sprintf( multiplyByBit0Label, "%sb%dbit0", label, _bits>>3 );
1932
1933 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", 0 );
1934
1935 outline1("LSR %s", address_displacement( _environment, destination, offset ) );
1936 for( i=1; i<(_bits>>3); ++i ) {
1937 sprintf( offset, "%d", i );
1938 outline1("ROR %s", address_displacement( _environment, destination, offset ) );
1939 }
1940 outline1("LBCC %s", multiplyByBit0Label );
1941
1942 // Step 2: Multiply the rightmost digit or the least significant bit (LSB)
1943 // of the multiplier (1) with all the digits of the multiplicand (11101).
1944
1945 outline0("ANDCC #$FE" );
1946 for( i=(_bits>>3)-1; i>-1; --i ) {
1947 sprintf( offset, "%d", i );
1948 outline1("LDA %s", address_displacement( _environment, source, offset ) );
1949 outline1("ADCA %s", address_displacement( _environment, other, offset ) );
1950 outline1("STA %s", address_displacement( _environment, other, offset ) );
1951 }
1952
1953 // Step 3: Add a place holder of '0' or 'X' before multiplying the next
1954 // higher order digit of the multiplier& with the multiplicand.
1955
1956 outhead1("%s", multiplyByBit0Label);
1957
1958 outline0("ANDCC #$FE" );
1959 sprintf( offset, "%d", (_bits>>3)-1 );
1960 outline1("ASL %s", address_displacement( _environment, source, offset ) );
1961 for( i=(_bits>>3)-2; i>-1; --i ) {
1962 sprintf( offset, "%d", i );
1963 outline1("ROL %s", address_displacement( _environment, source, offset ) );
1964 }
1965
1966 // Step 4: Repeat the same process for all the next higher-order digits
1967 // until we reach the most significant bit (MSB) which is the left-most
1968 // digit of the multiplicand with the multiplier.
1969
1970 outline0("DECB" );
1971 outline1("BEQ CPUMATHMULNBITTONBIT%dL1x", (_bits>>3) );
1972 outline1("JMP CPUMATHMULNBITTONBIT%dL1", (_bits>>3) );
1973 outhead1("CPUMATHMULNBITTONBIT%dL1x", (_bits>>3) );
1974
1975 outline0("RTS" );
1976
1977 // Step 5: The product obtained in each row is called the partial product.
1978 // Finally, add all the partial products. To add all the binary numbers
1979 // use the rules of binary addition.
1980
1981 // (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)
1982 outhead1("%s", afterLabel );
1983
1984 }
1985
1986 for( i=0; i<(_bits>>3); ++i ) {
1987 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
1988 outline1("LDA %s", address_displacement( _environment, _source, offset ) );
1989 outline1("STA %s", address_displacement( _environment, source, offset ) );
1990 outline1("LDA %s", address_displacement( _environment, _destination, offset ) );
1991 outline1("STA %s", address_displacement( _environment, destination, offset ) );
1992 }
1993 outline1("JSR CPUMATHMULNBITTONBIT%d", _bits >> 3 );
1994 for( i=0; i<(_bits>>3); ++i ) {
1995 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
1996 outline1("LDA %s", address_displacement( _environment, other, offset ) );
1997 if ( _other ) {
1998 outline1("STA %s", address_displacement( _environment, _other, offset ) );
1999 } else {
2000 outline1("STA %s", address_displacement( _environment, _destination, offset ) );
2001 }
2002 }
2003
2004 // done()
2005
2006}
2007
2008
2009void cpu_math_div_16bit_to_16bit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _signed ) {
2010
2012
2014
2015 if ( _signed ) {
2016
2017 outline1("LDA %s", _source );
2018 outline1("EORA %s", _destination );
2019 outline0("ANDA #$80" );
2020 outline0("PSHS A");
2021
2022 outline1("LDA %s", _source );
2023 outline0("ANDA #$80" );
2024 outline1("BEQ %ssecond", label );
2025 outline0("ANDCC #$FE" );
2026 outline1("LDA %s", _source );
2027 outline0("EORA #$ff" );
2028 outline0("STA <MATHPTR0" );
2029 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2030 outline0("EORA #$ff" );
2031 outline0("STA <MATHPTR1" );
2032 outline0("ANDCC #$FE" );
2033 outline0("LDD <MATHPTR0" );
2034 outline0("ADDD #1" );
2035 outline0("STD <MATHPTR0" );
2036 outline1("JMP %ssecond2", label );
2037 outhead1("%ssecond", label );
2038 outline1("LDD %s", _source );
2039 outline0("STD <MATHPTR0");
2040 outline1("JMP %ssecond2", label );
2041
2042 outhead1("%ssecond2", label );
2043 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2044 outline0("ANDA #$80" );
2045 outline1("BEQ %sthird", label );
2046 outline0("ANDCC #$FE" );
2047 outline1("LDA %s", _destination );
2048 outline0("EORA #$ff" );
2049 outline0("STA <MATHPTR2" );
2050 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2051 outline0("EORA #$ff" );
2052 outline0("STA <MATHPTR3" );
2053 outline0("ANDCC #$FE" );
2054 outline0("LDD <MATHPTR2" );
2055 outline0("ADDD #1" );
2056 outline0("STD <MATHPTR2" );
2057 outline1("JMP %sthird2", label );
2058 outhead1("%sthird", label );
2059 outline1("LDD %s", _destination );
2060 outline0("STD <MATHPTR2");
2061 outline1("JMP %sthird2", label );
2062
2063 outhead1("%sthird2", label );
2064
2065 outline0("LDX <MATHPTR0" );
2066 outline0("LDY <MATHPTR2" );
2067
2068 outhead1("%sDIVXY", label);
2069 outline0("PSHS Y,X,D,CC" );
2070 outline0("LDB #$10" );
2071 outline0("PSHS B" );
2072 outline0("CLRB" );
2073 outline0("CLRA" );
2074 outhead1("%sDIVLP", label);
2075 outline0("ASL 5,S" );
2076 outline0("ROL 4,S" );
2077 outline0("ROLB" );
2078 outline0("ROLA" );
2079 outline0("CMPD 6,S" );
2080 outline1("BLO %sDIVLT", label );
2081 outline0("SUBD 6,S" );
2082 outline0("INC 5,S" );
2083 outhead1("%sDIVLT", label);
2084 outline0("DEC ,S" );
2085 outline1("BNE %sDIVLP", label );
2086 outline0("STD 6,S" );
2087 outline0("LEAS 1,S" );
2088 outline0("PULS Y,X,D,CC" );
2089
2090 outline1("STX %s", _other );
2091 outline1("STY %s", _other_remainder );
2092
2093 outline0("PULS A");
2094 outline0("ANDA #$80");
2095 outline1("BEQ %sdone", label);
2096 outline1("LDA %s", _other );
2097 outline0("EORA #$ff" );
2098 outline1("STA %s", _other );
2099 outline1("LDA %s", address_displacement(_environment, _other, "1") );
2100 outline0("EORA #$ff" );
2101 outline1("STA %s", address_displacement(_environment, _other, "1") );
2102 outline0("ANDCC #$FE" );
2103 outline1("LDD %s", _other );
2104 outline0("ADDD #1" );
2105 outline1("STD %s", _other );
2106 outhead1("%sdone", label );
2107
2108 } else {
2109
2110 outline1("LDX %s", _source );
2111 outline1("LDY %s", _destination );
2112 outhead1("%sDIVXY", label);
2113 outline0("PSHS Y,X,D,CC" );
2114 outline0("LDB #$10" );
2115 outline0("PSHS B" );
2116 outline0("CLRB" );
2117 outline0("CLRA" );
2118 outhead1("%sDIVLP", label);
2119 outline0("ASL 5,S" );
2120 outline0("ROL 4,S" );
2121 outline0("ROLB" );
2122 outline0("ROLA" );
2123 outline0("CMPD 6,S" );
2124 outline1("BLO %sDIVLT", label );
2125 outline0("SUBD 6,S" );
2126 outline0("INC 5,S" );
2127 outhead1("%sDIVLT", label);
2128 outline0("DEC ,S" );
2129 outline1("BNE %sDIVLP", label );
2130 outline0("STD 6,S" );
2131 outline0("LEAS 1,S" );
2132 outline0("PULS Y,X,D,CC" );
2133 outline1("STX %s", _other );
2134 outline1("STY %s", _other_remainder );
2135 }
2136
2137 embedded( cpu_math_div_16bit_to_16bit, src_hw_6309_cpu_math_div_16bit_to_16bit_asm );
2138
2139 outline1("LDD %s", _source );
2140 outline1("LDX %s", _destination );
2141 if ( _signed ) {
2142 outline0("JSR CPUMATHDIV16BITTO16BIT_SIGNED" );
2143 } else {
2144 outline0("JSR CPUMATHDIV16BITTO16BIT" );
2145 }
2146 outline1("STX %s", _other_remainder );
2147 outline1("STD %s", _other );
2148
2149 done( )
2150
2151}
2152
2153void cpu_math_div_16bit_to_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _signed ) {
2154
2156
2158
2159 if ( _signed ) {
2160
2161 outline1("LDA %s", _source );
2162 outline1("EORA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2163 outline0("ANDA #$80" );
2164 outline0("PSHS A");
2165
2166 outline1("LDA %s", _source );
2167 outline0("ANDA #$80" );
2168 outline1("BEQ %ssecond", label );
2169 outline0("ANDCC #$FE" );
2170 outline1("LDA %s", _source );
2171 outline0("EORA #$ff" );
2172 outline0("STA <MATHPTR0" );
2173 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2174 outline0("EORA #$ff" );
2175 outline0("STA <MATHPTR1" );
2176 outline0("ANDCC #$FE" );
2177 outline0("LDD <MATHPTR0" );
2178 outline0("ADDD #1" );
2179 outline0("STD <MATHPTR0" );
2180 outline1("JMP %ssecond2", label );
2181 outhead1("%ssecond", label );
2182 outline1("LDD %s", _source );
2183 outline0("STD <MATHPTR0");
2184 outline1("JMP %ssecond2", label );
2185
2186 outhead1("%ssecond2", label );
2187 outline1("LDA #$%2.2x", (unsigned char)((_destination)&0xff) );
2188 outline0("ANDA #$80" );
2189 outline1("BEQ %sthird", label );
2190 outline0("ANDCC #$FE" );
2191 outline1("LDA %s", _destination );
2192 outline0("EORA #$ff" );
2193 outline0("STA <MATHPTR2" );
2194 outline1("LDA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2195 outline0("EORA #$ff" );
2196 outline0("STA <MATHPTR3" );
2197 outline0("ANDCC #$FE" );
2198 outline0("LDD <MATHPTR2" );
2199 outline0("ADDD #1" );
2200 outline0("STD <MATHPTR2" );
2201 outline1("JMP %sthird2", label );
2202 outhead1("%sthird", label );
2203 outline1("LDD #$%4.4x", _destination );
2204 outline0("STD <MATHPTR2");
2205 outline1("JMP %sthird2", label );
2206
2207 outhead1("%sthird2", label );
2208
2209 outline0("LDX <MATHPTR0" );
2210 outline0("LDY <MATHPTR2" );
2211
2212 outhead1("%sDIVXY", label);
2213 outline0("PSHS Y,X,D,CC" );
2214 outline0("LDB #$10" );
2215 outline0("PSHS B" );
2216 outline0("CLRB" );
2217 outline0("CLRA" );
2218 outhead1("%sDIVLP", label);
2219 outline0("ASL 5,S" );
2220 outline0("ROL 4,S" );
2221 outline0("ROLB" );
2222 outline0("ROLA" );
2223 outline0("CMPD 6,S" );
2224 outline1("BLO %sDIVLT", label );
2225 outline0("SUBD 6,S" );
2226 outline0("INC 5,S" );
2227 outhead1("%sDIVLT", label);
2228 outline0("DEC ,S" );
2229 outline1("BNE %sDIVLP", label );
2230 outline0("STD 6,S" );
2231 outline0("LEAS 1,S" );
2232 outline0("PULS Y,X,D,CC" );
2233
2234 outline1("STX %s", _other );
2235 outline1("STY %s", _other_remainder );
2236
2237 outline0("PULS A");
2238 outline0("ANDA #$80");
2239 outline1("BEQ %sdone", label);
2240 outline1("LDA %s", _other );
2241 outline0("EORA #$ff" );
2242 outline1("STA %s", _other );
2243 outline1("LDA %s", address_displacement(_environment, _other, "1") );
2244 outline0("EORA #$ff" );
2245 outline1("STA %s", address_displacement(_environment, _other, "1") );
2246 outline0("ANDCC #$FE" );
2247 outline1("LDD %s", _other );
2248 outline0("ADDD #1" );
2249 outline1("STD %s", _other );
2250 outhead1("%sdone", label );
2251
2252 } else {
2253
2254 outline1("LDX %s", _source );
2255 outline1("LDY #$%4.4x", _destination );
2256 outhead1("%sDIVXY", label);
2257 outline0("PSHS Y,X,D,CC" );
2258 outline0("LDB #$10" );
2259 outline0("PSHS B" );
2260 outline0("CLRB" );
2261 outline0("CLRA" );
2262 outhead1("%sDIVLP", label);
2263 outline0("ASL 5,S" );
2264 outline0("ROL 4,S" );
2265 outline0("ROLB" );
2266 outline0("ROLA" );
2267 outline0("CMPD 6,S" );
2268 outline1("BLO %sDIVLT", label );
2269 outline0("SUBD 6,S" );
2270 outline0("INC 5,S" );
2271 outhead1("%sDIVLT", label);
2272 outline0("DEC ,S" );
2273 outline1("BNE %sDIVLP", label );
2274 outline0("STD 6,S" );
2275 outline0("LEAS 1,S" );
2276 outline0("PULS Y,X,D,CC" );
2277 outline1("STX %s", _other );
2278 outline1("STY %s", _other_remainder );
2279 }
2280
2281 embedded( cpu_math_div_16bit_to_16bit, src_hw_6309_cpu_math_div_16bit_to_16bit_asm );
2282
2283 outline1("LDD %s", _source );
2284 outline1("LDX #$%4.4x", _destination );
2285 if ( _signed ) {
2286 outline0("JSR CPUMATHDIV16BITTO16BIT_SIGNED" );
2287 } else {
2288 outline0("JSR CPUMATHDIV16BITTO16BIT" );
2289 }
2290 outline1("STX %s", _other_remainder );
2291 outline1("STD %s", _other );
2292
2293 done( )
2294
2295}
2296
2305void cpu_math_sub_16bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
2306
2307 inline( cpu_math_sub_16bit )
2308
2309 outline1("LDD %s", _source );
2310 outline1("SUBD %s", _destination);
2311 outline1("STD %s", _other ? _other : _destination );
2312
2314
2315}
2316
2317void cpu_math_sub_16bit_with_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
2318
2320
2321 outline1("LDD %s", _source );
2322 outline1("SUBB %s", _destination);
2323 outline0("SBCA #0");
2324 outline1("STD %s", _other ? _other : _destination );
2325
2327
2328}
2329
2337void cpu_math_complement_const_16bit( Environment * _environment, char *_source, int _value ) {
2338
2340
2341 outline1("LDD #$%4.4x", _value);
2342 outline1("SUBD %s", _source );
2343 outline1("STD %s", _source);
2344
2346
2347}
2348
2356void cpu_math_div2_const_16bit( Environment * _environment, char *_source, int _steps, int _signed, char * _remainder ) {
2357
2359
2361
2362 if ( _signed ) {
2363
2364 if ( _remainder ) {
2365 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
2366 outline0("ANDA #$01");
2367 outline1("STA %s", address_displacement( _environment, _remainder, "1" ) );
2368 }
2369 outline1("LDA %s", _source);
2370 outline0("ANDA #$80");
2371 outline1("BEQ %spos", label );
2372
2373 outline1("LDD %s", _source );
2374 outline0("ANDCC #$FE" );
2375 outline0("EORA #$FF" );
2376 outline0("EORB #$FF" );
2377 outline0("ADDD #1" );
2378
2379 outline1("JMP %sdone", label );
2380
2381 outhead1("%spos", label );
2382 outline1("LDD %s", _source );
2383
2384 outhead1("%sdone", label );
2385
2386 outline1("LDX #$%4.4x", _steps );
2387 outhead1("%sloop", label );
2388 outline0("ANDCC #$FE" );
2389 outline0("ASRD" );
2390 outline0("LEAX -1, X");
2391 outline0("CMPX #0");
2392 outline1("BNE %sloop", label );
2393
2394 outline0("STD <MATHPTR0");
2395
2396 outline1("LDA %s", _source);
2397 outline0("ANDA #$80");
2398 outline1("BEQ %spos2", label );
2399
2400 outline0("LDD <MATHPTR0");
2401 outline0("ANDCC #$FE" );
2402 outline0("EORA #$FF" );
2403 outline0("EORB #$FF" );
2404 outline0("ADDD #1" );
2405
2406 outline1("JMP %sdone2", label );
2407
2408 outhead1("%spos2", label );
2409 outline0("LDD <MATHPTR0");
2410 outhead1("%sdone2", label );
2411 outline1("STD %s", _source );
2412
2413 } else {
2414
2415 if ( _remainder ) {
2416 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
2417 outline0("ANDA #$01");
2418 outline1("STA %s", address_displacement( _environment, _remainder, "1" ) );
2419 }
2420 outline1("LDD %s", _source );
2421 outline1("LDX #$%4.4x", _steps );
2422 outhead1("%sloop", label );
2423 outline0("ANDCC #$FE" );
2424 outline0("ASRA" );
2425 outline0("RORB" );
2426 outline0("LEAX -1, X");
2427 outline0("CMPX #0");
2428 outline1("BNE %sloop", label );
2429 outline1("STD %s", _source );
2430
2431 }
2432
2433 embedded( cpu_math_div2_const_16bit, src_hw_6309_cpu_math_div2_const_16bit_asm );
2434
2435 if ( _remainder ) {
2436 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
2437 outline0("ANDA #$01");
2438 outline1("STA %s", address_displacement( _environment, _remainder, "1" ) );
2439 }
2440 outline1("LDD %s", _source );
2441 outline1("LDX #$%4.4x", _steps );
2442
2443 if ( _signed ) {
2444 outline0("JSR CPUMATHDIV2CONST16BIT_SIGNED");
2445 } else {
2446 outline0("JSR CPUMATHDIV2CONST16BIT");
2447 }
2448 outline1("STD %s", _source );
2449
2450 done( )
2451
2452}
2453
2461void cpu_math_mul2_const_16bit( Environment * _environment, char *_source, int _steps, int _signed ) {
2462 int i;
2463
2465
2466 outline1("LDD %s", _source );
2467 if ( !_environment->cpuOptimization.cpu_math_mul2_const_16bit_generated[_steps] ) {
2468
2469 _environment->cpuOptimization.cpu_math_mul2_const_16bit_generated[_steps] = 1;
2470
2471 MAKE_LABEL;
2472
2473 outline1("BRA %s", label);
2474 outhead1("cpu_math_mul2_const_16bit_%d", _steps);
2475 for(i=0; i<_steps; ++i) {
2476 outline0("LSLD" );
2477 }
2478 outline0("RTS");
2479 outhead1("%s", label);
2480
2481 }
2482 outline1("JSR cpu_math_mul2_const_16bit_%d", _steps);
2483 outline1("STD %s", _source );
2484
2486
2487}
2488
2496void cpu_math_and_const_16bit( Environment * _environment, char *_source, int _mask ) {
2497
2498 inline( cpu_math_and_const_16bit )
2499
2500 outline1("LDD %s", _source );
2501 outline1("ANDA #$%2.2x", ( _mask >> 8 ) & 0xff );
2502 outline1("ANDB #$%2.2x", ( _mask & 0xff ) );
2503 outline1("STD %s", _source );
2504
2506
2507}
2508
2509/*****************************************************************************
2510 * 32 BIT MANIPULATION
2511 ****************************************************************************/
2512
2520void cpu_move_32bit( Environment * _environment, char *_source, char *_destination ) {
2521
2522 inline( cpu_move_32bit )
2523
2524 outline1("LDD %s", _source );
2525 outline1("STD %s", _destination );
2526 outline1("LDD %s", address_displacement(_environment, _source, "2") );
2527 outline1("STD %s", address_displacement(_environment, _destination, "2") );
2528
2530
2531}
2532
2540void cpu_store_32bit( Environment * _environment, char *_destination, int _value ) {
2541
2542 inline( cpu_store_32bit )
2543
2544 outline1("LDD #$%4.4x", ( _value >> 16 ) & 0xffff );
2545 outline1("STD %s", _destination );
2546 if((( _value >> 16 ) & 0xffff) != ( _value & 0xffff ))
2547 outline1("LDD #$%4.4x", ( _value & 0xffff ) );
2548 outline1("STD %s", address_displacement(_environment, _destination, "2") );
2549
2551
2552}
2553
2554void cpu_math_div_32bit_to_16bit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _signed ) {
2555
2557
2558 outline1("LDQ %s", _source );
2559 outline1("DIVQ %s", _destination );
2560
2561 if ( _other_remainder ) {
2562 outline1("STD %s", _other_remainder );
2563 }
2564
2565 outline1("STW %s", _other );
2566
2568
2569}
2570
2571void cpu_math_div_nbit_to_nbit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _bits ) {
2572
2574
2575 int i;
2576
2578
2579 char afterLabel[MAX_TEMPORARY_STORAGE]; sprintf( afterLabel, "%safter", label );
2580 char skipLabel[MAX_TEMPORARY_STORAGE]; sprintf( skipLabel, "%sskip", label );
2581 char skip2Label[MAX_TEMPORARY_STORAGE]; sprintf( skip2Label, "%sskipb", label );
2582 char skip3Label[MAX_TEMPORARY_STORAGE]; sprintf( skip3Label, "%sskipc", label );
2583 char skip4Label[MAX_TEMPORARY_STORAGE]; sprintf( skip4Label, "%sskipd", label );
2584 char quotient[MAX_TEMPORARY_STORAGE]; sprintf( quotient, "CPUMATHDIVNBITTONBIT%d_QUOTIENT", _bits >> 3 );
2585 char divisor[MAX_TEMPORARY_STORAGE]; sprintf( divisor, "CPUMATHDIVNBITTONBIT%d_DIVISOR", _bits >> 3 );
2586 char dividend[MAX_TEMPORARY_STORAGE]; sprintf( dividend, "CPUMATHDIVNBITTONBIT%d_DIVIDEND", _bits >> 3 );
2587 char result1[MAX_TEMPORARY_STORAGE]; sprintf( result1, "CPUMATHDIVNBITTONBIT%d_RESULT1", _bits >> 3 );
2588 char result2[MAX_TEMPORARY_STORAGE]; sprintf( result2, "CPUMATHDIVNBITTONBIT%d_RESULT2", _bits >> 3 );
2589 char k[MAX_TEMPORARY_STORAGE]; sprintf( k, "CPUMATHDIVNBITTONBIT%d_K", _bits >> 3 );
2590
2591 if ( ! _environment->cpuOptimization.cpu_math_div_nbit_to_nbit[_bits>>3] ) {
2592
2593 cpu_jump( _environment, afterLabel );
2594
2595 outhead2("%s rzb %d", quotient, _bits>>3 );
2596 outhead2("%s rzb %d", divisor, _bits>>3 );
2597 outhead2("%s rzb %d", dividend, _bits>>3 );
2598 outhead1("%s fcb 0", k );
2599 outhead1("%s fcb 0", result1 );
2600 outhead1("%s fcb 0", result2 );
2601
2602 // public static long div(long dividend, long divisor) {
2603 // long quotient = 0;
2604
2605 outhead1("CPUMATHDIVNBITTONBIT%d", _bits>>3);
2606 outline0("LDA #$00");
2607 for( i=0; i<(_bits>>3); ++i ) {
2608 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2609 outline1("STA %s", address_displacement( _environment, quotient, offset ) );
2610 }
2611
2612 // int k = 0;
2613 cpu_store_8bit( _environment, k, 0 );
2614
2615 // while (divisor <= dividend && divisor > 0) {
2616
2617 cpu_label( _environment, label );
2618 cpu_less_than_nbit( _environment, divisor, dividend, result1, 1, _bits );
2619 cpu_greater_than_nbit_const( _environment, divisor, 0, result2, 0, _bits );
2620 cpu_and_8bit( _environment, result1, result2, result1 );
2621 cpu_compare_and_branch_8bit_const( _environment, result1, 0, skipLabel, 1 );
2622
2623 // divisor <<= 1;
2624
2625 cpu_math_mul2_const_nbit( _environment, divisor, 1, _bits );
2626
2627 // k++;
2628
2629 cpu_inc( _environment, k );
2630
2631 // }
2632
2633 cpu_jump( _environment, label );
2634
2635 cpu_label( _environment, skipLabel );
2636
2637 // while (k-- > 0) {
2638
2639 cpu_greater_than_8bit_const( _environment, k, 0, result1, 0, 1 );
2640 cpu_dec( _environment, k );
2641 cpu_compare_and_branch_8bit_const( _environment, result1, 0, skip2Label, 1 );
2642
2643 // divisor >>= 1;
2644
2645 cpu_math_div2_const_nbit( _environment, divisor, 1, _bits, NULL );
2646
2647 // if (divisor <= dividend) {
2648 cpu_less_than_nbit( _environment, divisor, dividend, result1, 1, _bits );
2649 cpu_compare_and_branch_8bit_const( _environment, result1, 0, skip3Label, 1 );
2650
2651 // dividend -= divisor;
2652
2653 cpu_math_sub_nbit( _environment, dividend, divisor, dividend, _bits );
2654
2655 // quotient = (quotient << 1) + 1;
2656 cpu_math_mul2_const_nbit( _environment, quotient, 1, _bits );
2657 cpu_inc_nbit( _environment, quotient, _bits );
2658
2659 // }
2660 cpu_jump( _environment, skip4Label );
2661 cpu_label( _environment, skip3Label );
2662 // else quotient <<= 1;
2663 cpu_math_mul2_const_nbit( _environment, quotient, 1, _bits );
2664 cpu_label( _environment, skip4Label );
2665 cpu_jump( _environment, skipLabel );
2666
2667 // }
2668 cpu_label( _environment, skip2Label );
2669 // return quotient;
2670 cpu_return( _environment );
2671
2672 cpu_label( _environment, afterLabel );
2673
2674 }
2675
2676 for( i=0; i<(_bits>>3); ++i ) {
2677 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2678 outline1("LDA %s", address_displacement( _environment, _source, offset ) );
2679 outline1("STA %s", address_displacement( _environment, dividend, offset ) );
2680 outline1("LDA %s", address_displacement( _environment, _destination, offset ) );
2681 outline1("STA %s", address_displacement( _environment, divisor, offset ) );
2682 }
2683 outline1("JSR CPUMATHDIVNBITTONBIT%d", _bits>>3);
2684
2685 for( i=0; i<(_bits>>3); ++i ) {
2686 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2687 if ( _other ) {
2688 outline1("LDA %s", address_displacement( _environment, quotient, offset ) );
2689 outline1("STA %s", address_displacement( _environment, _other, offset ) );
2690 } else {
2691 outline1("LDA %s", address_displacement( _environment, quotient, offset ) );
2692 outline1("STA %s", address_displacement( _environment, _destination, offset ) );
2693 }
2694 }
2695
2696 // }
2698
2699}
2700
2701void cpu_math_div_nbit_to_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _bits ) {
2702
2704
2705 int i;
2706
2708
2709 char afterLabel[MAX_TEMPORARY_STORAGE]; sprintf( afterLabel, "%safter", label );
2710 char data[MAX_TEMPORARY_STORAGE]; sprintf( data, "CPUMATHDIVNBITTONBITCONST%d_DATA", _bits >> 3 );
2711
2712 if ( ! _environment->cpuOptimization.cpu_math_div_nbit_to_nbit_const[_bits>>3] ) {
2713
2714 cpu_jump( _environment, afterLabel );
2715
2716 outhead2("%s: rzb %d", data, _bits>>3 );
2717
2718 cpu_label( _environment, afterLabel );
2719
2720 }
2721
2722 for( i=0; i<(_bits>>3); ++i ) {
2723 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2724 outline1("LDA #$%2.2x", (unsigned char)( (_destination >> (i*8)) & 0xff ) );
2725 outline1("STA %s", address_displacement( _environment, data, offset ) );
2726 }
2727 cpu_math_div_nbit_to_nbit( _environment, _source, data, _other, _other_remainder, _bits );
2728
2729 // }
2731
2732}
2733
2734void cpu_math_div_32bit_to_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _signed ) {
2735
2737
2739
2740 char dividendLabel[MAX_TEMPORARY_STORAGE];
2741 sprintf(dividendLabel, "%sdiv", label );
2742
2743 outline1("BRA %s", label );
2744 outhead1("%s", dividendLabel );
2745 outline1("fdb $%4.4x", _destination );
2746 outhead1("%s", label );
2747 outline1("LDQ %s", _source );
2748 outline1("DIVQ %s", dividendLabel );
2749
2750 if ( _other_remainder ) {
2751 outline1("STD %s", _other_remainder );
2752 }
2753
2754 outline1("STW %s", _other );
2755
2757
2758}
2759
2769void cpu_compare_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive ) {
2770
2771 inline( cpu_compare_32bit )
2772
2774
2775 char sourceEffective[MAX_TEMPORARY_STORAGE]; sprintf(sourceEffective, "%s", address_displacement(_environment, _source, "2") );
2776 char destinationEffective[MAX_TEMPORARY_STORAGE]; sprintf(destinationEffective, "%s", address_displacement(_environment, _source, "2") );
2777
2778 if ( _positive ) {
2779
2780 cpu_compare_16bit( _environment, _source, _destination, _other, _positive );
2781
2782 outline1("LDB %s", _other );
2783 outline1("BEQ %sdone", label );
2784
2785 cpu_compare_16bit( _environment, sourceEffective, destinationEffective, _other, _positive );
2786
2787 } else {
2788
2789 cpu_compare_16bit( _environment, _source, _destination, _other, _positive );
2790
2791 outline1("LDB %s", _other );
2792 outline1("BNE %sdone", label );
2793
2794 cpu_compare_16bit( _environment, sourceEffective, destinationEffective, _other, _positive );
2795
2796 }
2797
2798 outhead1("%sdone", label );
2799
2801
2802}
2803
2804void cpu_compare_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive, int _bits ) {
2805
2807
2808 inline( cpu_compare_nbit )
2809
2810 for( int i=0; i<(_bits>>3); ++i ) {
2811 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2812 outline1("LDA %s", address_displacement(_environment, _source, offset));
2813 outline1("CMPA %s", address_displacement(_environment, _destination, offset));
2814 outline2("LBNE %s", label, i);
2815 }
2816 outline1("LDA #$%2.2x", 0xff*_positive);
2817 if ( _other ) {
2818 outline1("STA %s", _other);
2819 } else {
2820 outline1("STA %s", _destination);
2821 }
2822 outline1("JMP %s_2", label);
2823 outhead1("%s", label);
2824 outline1("LDA #$%2.2x", 0xff*(1-_positive));
2825 if ( _other ) {
2826 outline1("STA %s", _other);
2827 } else {
2828 outline1("STA %s", _destination);
2829 }
2830 outhead1("%s_2", label);
2831
2833
2834}
2835
2836void cpu_compare_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive, int _bits ) {
2837
2839
2840 int i;
2841
2842 inline( cpu_compare_nbit )
2843
2844 for( i=0; i<(_bits>>3); ++i ) {
2845 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2846 outline1("LDA %s", address_displacement(_environment, _source, offset));
2847 outline1("CMPA #$%2.2x", (unsigned char) ( ( _destination >> (i*8) ) & 0xff ) );
2848 outline1("LBNE %s", label);
2849 }
2850 outline1("LDA #$%2.2x", 0xff*_positive);
2851 outline1("STA %s", _other);
2852 outline1("JMP %s_2", label);
2853 outhead1("%s", label);
2854 outline1("LDA #$%2.2x", 0xff*(1-_positive));
2855 outline1("STA %s", _other);
2856 outhead1("%s_2", label);
2857
2859
2860}
2861
2871void cpu_compare_32bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive ) {
2872
2873 inline( cpu_compare_32bit )
2874
2876
2877 char sourceEffective[MAX_TEMPORARY_STORAGE]; sprintf(sourceEffective, "%s", address_displacement(_environment, _source, "2") );
2878
2879 if ( _positive ) {
2880
2881 cpu_compare_16bit_const( _environment, _source, ((_destination>>16)&0xffff), _other, _positive );
2882
2883 outline1("LDB %s", _other );
2884 outline1("BEQ %sdone", label );
2885
2886 cpu_compare_16bit_const( _environment, sourceEffective, (_destination & 0xffff ), _other, _positive );
2887
2888 } else {
2889
2890 cpu_compare_16bit_const( _environment, _source, ((_destination>>16)&0xffff), _other, _positive );
2891
2892 outline1("LDB %s", _other );
2893 outline1("BNE %sdone", label );
2894
2895 cpu_compare_16bit_const( _environment, sourceEffective, (_destination&0xffff), _other, _positive );
2896
2897 }
2898
2899 outhead1("%sdone", label );
2900
2902
2903}
2904
2914void cpu_compare_and_branch_32bit_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
2915
2917
2919
2920 outline1("LDX %s", _source);
2921 outline1("CMPX #$%4.4x", ( ( _destination >> 16 ) & 0xffff ) );
2922 if ( _positive ) {
2923 B(NE, label);
2924 } else {
2925 B(EQ, label);
2926 }
2927 outline1("LDX %s", address_displacement(_environment, _source, "2"));
2928 outline1("CMPX #$%4.4x", ( _destination & 0xffff ) );
2929 if ( _positive ) {
2930 B(EQ, _label);
2931 } else {
2932 B(NE, _label);
2933 }
2934 outhead1("%s", label);
2935
2937
2938}
2939
2949void cpu_less_than_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
2950
2951 inline( cpu_less_than_32bit )
2952
2954
2955 outline0("CLRA");
2956 outline1("LDX %s", _source);
2957 outline1("CMPX %s", _destination);
2958 outline1("BNE %shigh", label);
2959 outline1("LDX %s", address_displacement(_environment, _source, "2"));
2960 outline1("CMPX %s", address_displacement(_environment, _destination, "2"));
2961 outhead1("%shigh", label );
2962
2963 if ( _signed ) {
2964 if ( _equal ) {
2965 outline1("BGT %sdone", label);
2966 } else {
2967 outline1("BGE %sdone", label);
2968 }
2969 } else {
2970 if ( _equal ) {
2971 outline1("BHI %sdone", label);
2972 } else {
2973 outline1("BHS %sdone", label);
2974 }
2975 }
2976 outline0("DECA");
2977 outhead1("%sdone", label );
2978 outline1("STA %s", _other ? _other : _destination );
2979
2981
2982
2983}
2984
2985void cpu_less_than_32bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
2986
2988
2990
2991 outline0("CLRA");
2992 outline1("LDX %s", _source);
2993 outline1("CMPX #$%4.4x", ( ( _destination >> 16 ) & 0xffff ) );
2994 outline1("BNE %shigh", label);
2995 outline1("LDX %s", address_displacement(_environment, _source, "2"));
2996 outline1("CMPX #$%4.4x", ( _destination & 0xffff ) );
2997 outhead1("%shigh", label );
2998
2999 if ( _signed ) {
3000 if ( _equal ) {
3001 outline1("BGT %sdone", label);
3002 } else {
3003 outline1("BGE %sdone", label);
3004 }
3005 } else {
3006 if ( _equal ) {
3007 outline1("BHI %sdone", label);
3008 } else {
3009 outline1("BHS %sdone", label);
3010 }
3011 }
3012 outline0("DECA");
3013 outhead1("%sdone", label );
3014 outline1("STA %s", _other );
3015
3017
3018
3019}
3020
3021void cpu_less_than_nbit( Environment * _environment, char *_source, char * _destination, char *_other, int _equal, int _bits ) {
3022
3024
3025 int i;
3026
3027 inline( cpu_less_than_nbit )
3028
3029 for( i=0; i<(_bits>>3); ++i ) {
3030 char offset[MAX_TEMPORARY_STORAGE]; sprintf(offset, "%d", i );
3031 outline1("LDA %s", address_displacement(_environment, _destination, offset ) );
3032 outline1("LDB %s", address_displacement(_environment, _source, offset ) );
3033 outline1("CMPB %s", address_displacement(_environment, _destination, offset ) );
3034 outline1("LBCS %sbga", label );
3035 outline2("BEQ %snext%dx", label, i );
3036 outline1("JMP %sagb", label );
3037 outhead2("%snext%dx", label, i );
3038 }
3039
3040 outhead1("%sbge", label );
3041 if ( _equal ) {
3042 outline0("LDA #$ff" );
3043 } else {
3044 outline0("LDA #$00" );
3045 }
3046 outline1("STA %s", _other );
3047 outline1("BRA %sdone", label );
3048
3049 outhead1("%sbga", label );
3050 outline0("LDA #$ff" );
3051 outline1("STA %s", _other );
3052 outline1("BRA %sdone", label );
3053
3054 outhead1("%sagb", label );
3055 outline0("LDA #$00" );
3056 outline1("STA %s", _other );
3057 outline1("BRA %sdone", label );
3058
3059 outhead1("%sdone", label );
3060
3062
3063}
3064
3065void cpu_less_than_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _bits ) {
3066
3068
3069 int i;
3070
3071 inline( cpu_less_than_nbit_const )
3072
3073 for( i=0; i<(_bits>>3); ++i ) {
3074 char offset[MAX_TEMPORARY_STORAGE]; sprintf(offset, "%d", i );
3075 outline1("LDB %s", address_displacement(_environment, _source, offset ) );
3076 outline1("CMPB #$%2.2x", (unsigned char)((_destination>>(i*8))&0xff) );
3077 outline1("LBCS %sbga", label );
3078 outline2("BEQ %snext%dx", label, i );
3079 outline1("JMP %sagb", label );
3080 outhead2("%snext%dx", label, i );
3081 }
3082
3083 outhead1("%sbge", label );
3084 if ( _equal ) {
3085 outline0("LDA #$ff" );
3086 } else {
3087 outline0("LDA #$00" );
3088 }
3089 outline1("STA %s", _other );
3090 outline1("BRA %sdone", label );
3091
3092 outhead1("%sbga", label );
3093 outline0("LDA #$ff" );
3094 outline1("STA %s", _other );
3095 outline1("BRA %sdone", label );
3096
3097 outhead1("%sagb", label );
3098 outline0("LDA #$00" );
3099 outline1("STA %s", _other );
3100 outline1("BRA %sdone", label );
3101
3102 outhead1("%sdone", label );
3103
3105
3106}
3107
3117void cpu_greater_than_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
3118
3119 inline( cpu_greater_than_32bit )
3120
3122
3123 outline0("CLRB");
3124 outline1("LDX %s", _source);
3125 outline1("CMPX %s", _destination);
3126 outline1("BNE %shigh", label);
3127 outline1("LDX %s", address_displacement(_environment, _source, "2"));
3128 outline1("CMPX %s", address_displacement(_environment, _destination, "2"));
3129 outhead1("%shigh", label );
3130
3131 if ( _signed ) {
3132 if ( _equal ) {
3133 outline1("BLT %sdone", label);
3134 } else {
3135 outline1("BLE %sdone", label);
3136 }
3137 } else {
3138 if ( _equal ) {
3139 outline1("BLO %sdone", label);
3140 } else {
3141 outline1("BLS %sdone", label);
3142 }
3143 }
3144
3145 outline0("DECB");
3146 outhead1("%sdone", label );
3147 outline1("STB %s", _other ? _other : _destination );
3148
3150
3151}
3152
3153void cpu_greater_than_32bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
3154
3155 inline( cpu_greater_than_32bit )
3156
3158
3159 outline0("CLRB");
3160 outline1("LDX %s", _source);
3161 outline1("CMPX #$%4.4x", ( _destination >> 16 ) & 0xffff );
3162 outline1("BNE %shigh", label);
3163 outline1("LDX %s", address_displacement(_environment, _source, "2"));
3164 outline1("CMPX #$%4.4x", ( _destination & 0xffff ) );
3165 outhead1("%shigh", label );
3166
3167 if ( _signed ) {
3168 if ( _equal ) {
3169 outline1("BLT %sdone", label);
3170 } else {
3171 outline1("BLE %sdone", label);
3172 }
3173 } else {
3174 if ( _equal ) {
3175 outline1("BLO %sdone", label);
3176 } else {
3177 outline1("BLS %sdone", label);
3178 }
3179 }
3180
3181 outline0("DECB");
3182 outhead1("%sdone", label );
3183 outline1("STB %s", _other );
3184
3186
3187}
3188
3189void cpu_greater_than_nbit( Environment * _environment, char *_source, char * _destination, char *_other, int _equal, int _bits ) {
3190
3191 inline( cpu_greater_than_nbit )
3192
3193 cpu_less_than_nbit( _environment, _source, _destination, _other, !_equal, _bits );
3194 cpu_not_8bit( _environment, _other, _other );
3195
3197
3198}
3199
3200void cpu_greater_than_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _bits ) {
3201
3202 inline( cpu_greater_than_nbit )
3203
3204 cpu_less_than_nbit_const( _environment, _source, _destination, _other, !_equal, _bits );
3205 cpu_not_8bit( _environment, _other, _other );
3206
3208
3209}
3210
3219void cpu_math_add_32bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
3220
3221 inline( cpu_math_add_32bit )
3222
3224
3225 outline1("LDQ %s", _source );
3226 outline1("ADDW %s", address_displacement( _environment, _destination, "2" ) );
3227 outline1("ADCD %s", _destination );
3228 if ( _other ) {
3229 outline1("STQ %s", _other);
3230 } else {
3231 outline1("STQ %s", _destination);
3232 }
3233
3235
3236}
3237
3238void cpu_math_add_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _bits ) {
3239
3240 inline( cpu_math_add_nbit )
3241
3242 outline0("ANDCC #$FE");
3243 for( int i=0; i<(_bits>>3); ++i ) {
3244 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", (_bits>>3)-i-1 );
3245 outline1("LDA %s", address_displacement(_environment, _source, offset));
3246 outline1("ADCA %s", address_displacement(_environment, _destination, offset));
3247 if ( _other ) {
3248 outline1("STA %s", address_displacement(_environment, _other, offset));
3249 } else {
3250 outline1("STA %s", address_displacement(_environment, _destination, offset));
3251 }
3252 }
3254
3255}
3256
3257void cpu_math_add_32bit_const( Environment * _environment, char *_source, int _destination, char *_other ) {
3258
3259 inline( cpu_math_add_32bit_const )
3260
3262
3263 outline1("LDQ %s", _source );
3264 outline1("ADDW #$%4.4x", (unsigned short)( (_destination ) & 0xffff ) );
3265 outline1("ADCD #$%4.4x", (unsigned short)( (_destination >> 16 ) & 0xffff ) );
3266 outline1("STQ %s", _other);
3267
3269
3270}
3271
3279void cpu_math_double_32bit( Environment * _environment, char *_source, char *_other, int _signed ) {
3280
3281 inline( cpu_math_double_32bit )
3282
3283 outline1("LDQ %s", _source);
3284 outline0("ADDR W,W" );
3285 outline0("ROLD");
3286 if ( _other ) {
3287 outline1("STQ %s", _other);
3288 } else {
3289 outline1("STQ %s", _source);
3290 }
3291
3293
3294}
3295
3304void cpu_math_sub_32bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
3305
3306 inline( cpu_math_sub_32bit )
3307
3308 outline1("LDD %s", address_displacement(_environment, _source, "2"));
3309 outline1("LDX #%s", _destination);
3310 outline0("SUBD 2,X");
3311 if ( _other ) {
3312 outline1("STD %s", address_displacement(_environment, _other, "2"));
3313 } else {
3314 outline0("STD 2,X");
3315 }
3316 outline1("LDD %s", _source);
3317 outline0("SBCB 1,X");
3318 outline0("SBCA ,X");
3319 outline1("STD %s", _other ? _other : ",X");
3320
3322
3323}
3324
3325void cpu_math_sub_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _bits ) {
3326
3327 inline( cpu_math_sub_nbit )
3328
3329 outline0("ANDCC #$FE");
3330 for( int i=0; i<(_bits)>>3; ++i ) {
3331 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", (_bits>>3)-i-1 );
3332 outline1("LDA %s", address_displacement(_environment, _source, offset));
3333 outline1("SBCA %s", address_displacement(_environment, _destination, offset));
3334 if ( _other ) {
3335 outline1("STA %s", address_displacement(_environment, _other, offset));
3336 } else {
3337 outline1("STA %s", address_displacement(_environment, _destination, offset));
3338 }
3339 }
3340
3342
3343}
3344
3352void cpu_math_complement_const_32bit( Environment * _environment, char *_source, int _value ) {
3353
3355
3356 outline1("LDX #%s", _source);
3357 outline1("LDD #$%4.4x", ( _value ) & 0xffff );
3358 outline0("SUBD 2,X");
3359 outline0("STD 2,X");
3360 outline1("LDD #$%4.4x", ( _value>>16 ) & 0xffff );
3361 outline0("SBCB 1,X");
3362 outline0("SBCA ,X");
3363 outline0("STD ,X");
3364
3366
3367}
3368
3376void cpu_math_div2_const_32bit( Environment * _environment, char *_source, int _steps, int _signed, char * _remainder ) {
3377
3379
3381
3382 if ( _signed ) {
3383
3384 if ( _remainder ) {
3385 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
3386 outline0("ANDA #$01");
3387 outline1("STA %s", address_displacement( _environment, _remainder, "3" ) );
3388 }
3389 outline1("LDA %s", _source);
3390 outline0("ANDA #$80");
3391 outline1("BEQ %spos", label );
3392
3393 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3394 outline0("ANDCC #$FE" );
3395 outline0("EORA #$FF" );
3396 outline0("EORB #$FF" );
3397 outline0("STD <MATHPTR2" );
3398 outline1("LDD %s", _source );
3399 outline0("ANDCC #$FE" );
3400 outline0("EORA #$FF" );
3401 outline0("EORB #$FF" );
3402 outline0("STD <MATHPTR0" );
3403 outline0("LDD <MATHPTR2" );
3404 outline0("ANDCC #$FE" );
3405 outline0("ADDD #1" );
3406 outline0("STD <MATHPTR2" );
3407 outline0("LDD <MATHPTR0" );
3408 outline0("ADDD #0" );
3409 outline0("STD <MATHPTR0" );
3410
3411 outline1("JMP %sdone", label );
3412
3413 outhead1("%spos", label );
3414 outline1("LDD %s", _source );
3415 outline0("STD <MATHPTR0" );
3416 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3417 outline0("STD <MATHPTR2" );
3418
3419 outhead1("%sdone", label );
3420
3421 outline1("LDX #$%4.4x", _steps );
3422 outhead1("%sloop", label );
3423 outline0("ANDCC #$FE" );
3424 outline0("ASR <MATHPTR0" );
3425 outline0("ROR <MATHPTR1" );
3426 outline0("ROR <MATHPTR2" );
3427 outline0("ROR <MATHPTR3" );
3428 outline0("LEAX -1, X");
3429 outline0("CMPX #0");
3430 outline1("BNE %sloop", label );
3431
3432 outline1("LDA %s", _source);
3433 outline0("ANDA #$80");
3434 outline1("BEQ %spos2", label );
3435
3436 outline0("ANDCC #$FE" );
3437 outline0("LDD <MATHPTR2" );
3438 outline0("EORA #$FF" );
3439 outline0("EORB #$FF" );
3440 outline0("STD <MATHPTR2" );
3441 outline0("LDD <MATHPTR0" );
3442 outline0("EORA #$FF" );
3443 outline0("EORB #$FF" );
3444 outline0("STD <MATHPTR0" );
3445
3446 outline0("ANDCC #$FE" );
3447 outline0("LDD <MATHPTR2" );
3448 outline0("ADDD #1" );
3449 outline1("STD %s", address_displacement(_environment, _source, "2") );
3450 outline0("LDD <MATHPTR0" );
3451 outline0("ADDD #0" );
3452 outline1("STD %s", _source );
3453
3454 outline1("JMP %sdone2", label );
3455
3456 outhead1("%spos2", label );
3457 outline0("LDD <MATHPTR3" );
3458 outline1("STD %s", address_displacement(_environment, _source, "3") );
3459 outline0("LDD <MATHPTR2" );
3460 outline1("STD %s", address_displacement(_environment, _source, "2") );
3461 outline0("LDD <MATHPTR1" );
3462 outline1("STD %s", address_displacement(_environment, _source, "1") );
3463 outline0("LDD <MATHPTR0" );
3464 outline1("STD %s", _source );
3465 outhead1("%sdone2", label );
3466
3467 } else {
3468
3469 if ( _remainder ) {
3470 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
3471 outline0("ANDA #$01");
3472 outline1("STA %s", address_displacement( _environment, _remainder, "3" ) );
3473 }
3474 outline1("LDD %s", _source );
3475 outline0("STD <MATHPTR0" );
3476 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3477 outline0("STD <MATHPTR2" );
3478
3479 outhead1("%sdone", label );
3480
3481 outline1("LDX #$%4.4x", _steps );
3482 outhead1("%sloop", label );
3483 outline0("ANDCC #$FE" );
3484 outline0("LSR <MATHPTR0" );
3485 outline0("ROR <MATHPTR1" );
3486 outline0("ROR <MATHPTR2" );
3487 outline0("ROR <MATHPTR3" );
3488 outline0("LEAX -1, X");
3489 outline0("CMPX #0");
3490 outline1("BNE %sloop", label );
3491
3492 outline0("LDD <MATHPTR2" );
3493 outline1("STD %s", address_displacement(_environment, _source, "2") );
3494 outline0("LDD <MATHPTR0" );
3495 outline1("STD %s", _source );
3496
3497 }
3498
3500
3501}
3502
3503void cpu_math_div2_const_nbit( Environment * _environment, char *_source, int _steps, int _bits, char * _remainder ) {
3504
3505 inline( cpu_math_div2_const_nbit )
3506
3508
3509 if ( _remainder ) {
3510 outline1("LDA %s", _source);
3511 outline0("ANDA #$01" );
3512 outline1("STA %s", _remainder);
3513 }
3514 char offsetMsb[MAX_TEMPORARY_STORAGE]; sprintf( offsetMsb, "%d", 0 );
3515
3516 outline1("LDA %s", address_displacement(_environment, _source, offsetMsb));
3517 outline0("ANDA #$80");
3518 outline0("TFR A, B");
3519 outline1("LBEQ %snocomplement", label );
3520 cpu_complement2_nbit( _environment, _source, _source, _bits );
3521 outhead1("%snocomplement", label );
3522 while( _steps ) {
3523 outline0("ANDCC #$FE");
3524 outline1("LSR %s", address_displacement(_environment, _source, offsetMsb));
3525 for( int i=1; i<(_bits>>3); ++i ) {
3526 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
3527 outline1("ROR %s", address_displacement(_environment, _source, offset));
3528 }
3529 --_steps;
3530 }
3531 outline0("CMPB #0");
3532 outline1("LBNE %snocomplement2", label );
3533 cpu_complement2_nbit( _environment, _source, _source, _bits );
3534 outhead1("%snocomplement2", label );
3535
3537
3538}
3539
3547void cpu_math_mul2_const_32bit( Environment * _environment, char *_source, int _steps, int _signed ) {
3548
3550
3552
3553 if ( _signed ) {
3554
3555 outline1("LDA %s", _source);
3556 outline0("ANDA #$80");
3557 outline1("BEQ %spos", label );
3558
3559 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3560 outline0("ANDCC #$FE" );
3561 outline0("EORA #$FF" );
3562 outline0("EORB #$FF" );
3563 outline0("STD <MATHPTR2" );
3564 outline1("LDD %s", _source );
3565 outline0("ANDCC #$FE" );
3566 outline0("EORA #$FF" );
3567 outline0("EORB #$FF" );
3568 outline0("STD <MATHPTR0" );
3569 outline0("LDD <MATHPTR2" );
3570 outline0("ANDCC #$FE" );
3571 outline0("ADDD #1" );
3572 outline0("STD <MATHPTR2" );
3573 outline0("LDD <MATHPTR0" );
3574 outline0("ADDD #0" );
3575 outline0("STD <MATHPTR0" );
3576
3577 outline1("JMP %sdone", label );
3578
3579 outhead1("%spos", label );
3580 outline1("LDD %s", _source );
3581 outline0("STD <MATHPTR0" );
3582 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3583 outline0("STD <MATHPTR2" );
3584
3585 outhead1("%sdone", label );
3586
3587 outline1("LDX #$%4.4x", _steps );
3588 outhead1("%sloop", label );
3589 outline0("ANDCC #$FE" );
3590 outline0("LSL <MATHPTR3" );
3591 outline0("ROL <MATHPTR2" );
3592 outline0("ROL <MATHPTR1" );
3593 outline0("ROL <MATHPTR0" );
3594 outline0("LEAX -1, X");
3595 outline0("CMPX #0");
3596 outline1("BNE %sloop", label );
3597
3598 outline1("LDA %s", _source);
3599 outline0("ANDA #$80");
3600 outline1("BEQ %spos2", label );
3601
3602 outline0("ANDCC #$FE" );
3603 outline0("LDD <MATHPTR2" );
3604 outline0("EORA #$FF" );
3605 outline0("EORB #$FF" );
3606 outline0("STD <MATHPTR2" );
3607 outline0("LDD <MATHPTR0" );
3608 outline0("EORA #$FF" );
3609 outline0("EORB #$FF" );
3610 outline0("STD <MATHPTR0" );
3611
3612 outline0("ANDCC #$FE" );
3613 outline0("LDD <MATHPTR2" );
3614 outline0("ADDD #1" );
3615 outline1("STD %s", address_displacement(_environment, _source, "2") );
3616 outline0("LDD <MATHPTR0" );
3617 outline0("ADDD #0" );
3618 outline1("STD %s", _source );
3619
3620 outline1("JMP %sdone2", label );
3621
3622 outhead1("%spos2", label );
3623 outline0("LDD <MATHPTR3" );
3624 outline1("STD %s", address_displacement(_environment, _source, "3") );
3625 outline0("LDD <MATHPTR2" );
3626 outline1("STD %s", address_displacement(_environment, _source, "2") );
3627 outline0("LDD <MATHPTR1" );
3628 outline1("STD %s", address_displacement(_environment, _source, "1") );
3629 outline0("LDD <MATHPTR0" );
3630 outline1("STD %s", _source );
3631 outhead1("%sdone2", label );
3632
3633 } else {
3634
3635 outline1("LDD %s", _source );
3636 outline0("STD <MATHPTR0" );
3637 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3638 outline0("STD <MATHPTR2" );
3639
3640 outhead1("%sdone", label );
3641
3642 outline1("LDX #$%4.4x", _steps );
3643 outhead1("%sloop", label );
3644 outline0("ANDCC #$FE" );
3645 outline0("LSL <MATHPTR3" );
3646 outline0("ROL <MATHPTR2" );
3647 outline0("ROL <MATHPTR1" );
3648 outline0("ROL <MATHPTR0" );
3649 outline0("LEAX -1, X");
3650 outline0("CMPX #0");
3651 outline1("BNE %sloop", label );
3652
3653 outline0("LDD <MATHPTR2" );
3654 outline1("STD %s", address_displacement(_environment, _source, "2") );
3655 outline0("LDD <MATHPTR0" );
3656 outline1("STD %s", _source );
3657
3658 }
3659
3661
3662}
3663
3664void cpu_math_mul2_const_nbit( Environment * _environment, char *_source, int _steps, int _bits ) {
3665
3666 int i;
3667
3668 inline( cpu_math_mul2_const_nbit )
3669
3670 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", (_bits>>3)-1 );
3671 outline1("LDA %s", _source );
3672 outline0("ANDA #$80");
3673 outline0("TFR A, B");
3674 while( _steps ) {
3675 outline0("ANDCC #$FE");
3676 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", (_bits>>3)-1);
3677 outline1("ASL %s", address_displacement(_environment, _source, offset));
3678 for( i=(_bits>>3)-2; i>-1; --i ) {
3679 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i);
3680 outline1("ROL %s", address_displacement(_environment, _source, offset));
3681 }
3682 --_steps;
3683 }
3684 outline1("ORB %s", _source );
3685 outline1("STB %s", _source );
3686
3688
3689}
3690
3698void cpu_math_and_const_32bit( Environment * _environment, char *_source, int _mask ) {
3699
3700 inline( cpu_math_and_const_32bit )
3701
3702 outline1("LDX #%s", _source );
3703 if(_mask & 0xffff0000) {
3704 outline0("LDD ,X");
3705 outline1("ANDA #$%2.2x", ( _mask >> 24 ) & 0xff );
3706 outline1("ANDB #$%2.2x", ( _mask >> 16 ) & 0xff );
3707 } else {
3708 outline0("LDD #0");
3709 }
3710 outline0("STD ,X");
3711 if(_mask & 0x0000ffff) {
3712 outline0("LDD 2,X");
3713 outline1("ANDA #$%2.2x", ( _mask >> 8 ) & 0xff );
3714 outline1("ANDB #$%2.2x", ( _mask >> 0 ) & 0xff );
3715 } else {
3716 outline0("LDD #0");
3717 }
3718 outline0("STD 2,X");
3719
3721
3722}
3723
3724void cpu_combine_nibbles( Environment * _environment, char * _low_nibble, char * _hi_nibble, char * _byte ) {
3725
3727
3728 embedded( cpu_combine_nibbles, src_hw_6309_cpu_combine_nibbles_asm );
3729
3730 outline1("LDX #%s", _hi_nibble );
3731 outline1("LDY #%s", _low_nibble );
3732 outline1("LDU #%s", _byte );
3733 outline0("JSR CPUCOMBINENIBBLES" );
3734
3735 done( )
3736
3737}
3738
3739void cpu_jump( Environment * _environment, char * _label ) {
3740
3741 inline( cpu_jump )
3742
3743 B(RA, _label );
3744
3746
3747}
3748
3749void cpu_call_addr( Environment * _environment, int _address ) {
3750
3751 outline1( "JSR $%4.4x", _address );
3752
3753}
3754
3755void cpu_call( Environment * _environment, char * _label ) {
3756
3757 inline( cpu_call )
3758
3759 B(SR, _label );
3760
3762
3763}
3764
3765void cpu_call_indirect( Environment * _environment, char * _value ) {
3766
3767 inline( cpu_call_indirect )
3768
3770
3771 char indirectLabel[MAX_TEMPORARY_STORAGE]; sprintf( indirectLabel, "%sindirect", label );
3772
3773 cpu_jump( _environment, label );
3774 cpu_label( _environment, indirectLabel );
3775 outline1( "JMP [%s]", _value );
3776 cpu_label( _environment, label );
3777 cpu_call( _environment, indirectLabel );
3778
3780
3781}
3782
3783void cpu_jump_indirect( Environment * _environment, char * _value ) {
3784
3785 inline( cpu_jump_indirect )
3786
3787 outline1( "JMP [%s]", _value );
3788
3790
3791}
3792
3793int cpu_register_decode( Environment * _environment, char * _register ) {
3794
3796
3797 if ( !_environment->emptyProcedure ) {
3798
3799 if ( strcmp( _register, "A" ) == 0 ) {
3800 result = REGISTER_A;
3801 } else if ( strcmp( _register, "B" ) == 0 ) {
3802 result = REGISTER_B;
3803 } else if ( strcmp( _register, "CC" ) == 0 ) {
3804 if ( !_environment->emptyProcedure ) {
3806 }
3807 result = REGISTER_CC;
3808 } else if ( strcmp( _register, "DP" ) == 0 ) {
3809 if ( !_environment->emptyProcedure ) {
3811 }
3812 result = REGISTER_DP;
3813 } else if ( strcmp( _register, "X" ) == 0 ) {
3814 result = REGISTER_X;
3815 } else if ( strcmp( _register, "Y" ) == 0 ) {
3816 result = REGISTER_Y;
3817 } else if ( strcmp( _register, "U" ) == 0 ) {
3818 result = REGISTER_U;
3819 } else if ( strcmp( _register, "S" ) == 0 ) {
3820 result = REGISTER_S;
3821 } else if ( strcmp( _register, "PC" ) == 0 ) {
3822 if ( !_environment->emptyProcedure ) {
3824 }
3825 result = REGISTER_PC;
3826 } else if ( strcmp( _register, "D" ) == 0 ) {
3827 result = REGISTER_D;
3828 } else {
3829
3830 }
3831
3832 }
3833
3834 return (int)result;
3835
3836}
3837
3838void cpu_set_asmio( Environment * _environment, int _asmio, int _value ) {
3839
3840 if ( IS_REGISTER( _asmio ) ) {
3841
3842 CPU6309Register reg = (CPU6309Register) _asmio;
3843
3844 switch ( reg ) {
3845 case REGISTER_NONE:
3847 break;
3848 case REGISTER_CC:
3849 case REGISTER_DP:
3850 break;
3851 case REGISTER_A:
3852 outline1( "LDA #$%2.2x", (unsigned char)(_value & 0xff ) );
3853 break;
3854 case REGISTER_B:
3855 outline1( "LDB #$%2.2x", (unsigned char)(_value & 0xff ) );
3856 break;
3857 case REGISTER_X:
3858 outline1( "LDX #$%4.4x", (unsigned short)(_value & 0xffff ) );
3859 break;
3860 case REGISTER_Y:
3861 outline1( "LDY #$%4.4x", (unsigned short)(_value & 0xffff ) );
3862 break;
3863 case REGISTER_U:
3864 outline1( "LDU #$%4.4x", (unsigned short)(_value & 0xffff ) );
3865 break;
3866 case REGISTER_S:
3867 outline1( "LDS #$%4.4x", (unsigned short)(_value & 0xffff ) );
3868 break;
3869 case REGISTER_D:
3870 outline1( "LDD #$%4.4x", (unsigned short)(_value & 0xffff ) );
3871 break;
3872 default:
3874 break;
3875 }
3876
3877 } else {
3878
3879 CPU6309Stack stk = (CPU6309Stack) _asmio;
3880
3881 switch ( stk ) {
3882 case STACK_NONE:
3883 break;
3884 case STACK_BYTE:
3885 outline1( "LDA %2.2x", _value );
3886 outline0( "PSHS A" );
3887 break;
3888 case STACK_WORD:
3889 outline1( "LDD %4.4x", _value );
3890 outline0( "PSHS D" );
3891 break;
3892 case STACK_DWORD:
3893 outline1( "LDD %4.4x", ( _value & 0xffff ) );
3894 outline0( "PSHS D" );
3895 outline1( "LDD %4.4x", ( (_value >> 16 ) & 0xffff ) );
3896 outline0( "PSHS D" );
3897 break;
3898 }
3899
3900 }
3901
3902}
3903
3904void cpu_set_asmio_indirect( Environment * _environment, int _asmio, char * _value ) {
3905
3906 if ( IS_REGISTER( _asmio ) ) {
3907
3908 CPU6309Register reg = (CPU6309Register) _asmio;
3909
3910 switch ( reg ) {
3911 case REGISTER_NONE:
3913 break;
3914 case REGISTER_CC:
3915 case REGISTER_DP:
3916 break;
3917 case REGISTER_A:
3918 outline1( "LDA %s", _value );
3919 break;
3920 case REGISTER_B:
3921 outline1( "LDB %s", _value );
3922 break;
3923 case REGISTER_X:
3924 outline1( "LDX %s", _value );
3925 break;
3926 case REGISTER_Y:
3927 outline1( "LDY %s", _value );
3928 break;
3929 case REGISTER_U:
3930 outline1( "LDU %s", _value );
3931 break;
3932 case REGISTER_S:
3933 outline1( "LDS %s", _value );
3934 break;
3935 case REGISTER_D:
3936 outline1( "LDD %s", _value );
3937 break;
3938 }
3939
3940 } else {
3941
3942 CPU6309Stack stk = (CPU6309Stack) _asmio;
3943
3944 switch ( stk ) {
3945 case STACK_NONE:
3946 break;
3947 case STACK_BYTE:
3948 outline1( "LDA %s", address_displacement(_environment, _value, "0") );
3949 outline0( "PSHS A" );
3950 break;
3951 case STACK_WORD:
3952 outline1( "LDD %s", address_displacement(_environment, _value, "0") );
3953 outline0( "PSHS D" );
3954 break;
3955 case STACK_DWORD:
3956 outline1( "LDD %s", address_displacement(_environment, _value, "0") );
3957 outline0( "PSHS D" );
3958 outline1( "LDD %s", address_displacement(_environment, _value, "2") );
3959 outline0( "PSHS D" );
3960 break;
3961 }
3962
3963 }
3964
3965}
3966
3967void cpu_get_asmio_indirect( Environment * _environment, int _asmio, char * _value ) {
3968
3969 if ( IS_REGISTER( _asmio ) ) {
3970
3971 CPU6309Register reg = (CPU6309Register) _asmio;
3972
3973 switch ( reg ) {
3974 case REGISTER_NONE:
3976 break;
3977 case REGISTER_CC:
3978 case REGISTER_DP:
3979 break;
3980 case REGISTER_A:
3981 outline1( "STA %s", _value );
3982 break;
3983 case REGISTER_B:
3984 outline1( "STB %s", _value );
3985 break;
3986 case REGISTER_X:
3987 outline1( "STX %s", _value );
3988 break;
3989 case REGISTER_Y:
3990 outline1( "STY %s", _value );
3991 break;
3992 case REGISTER_U:
3993 outline1( "STU %s", _value );
3994 break;
3995 case REGISTER_S:
3996 outline1( "STS %s", _value );
3997 break;
3998 case REGISTER_D:
3999 outline1( "STD %s", _value );
4000 break;
4001 }
4002
4003 } else {
4004
4005 CPU6309Stack stk = (CPU6309Stack) _asmio;
4006
4007 switch ( stk ) {
4008 case STACK_NONE:
4009 break;
4010 case STACK_BYTE:
4011 outline0( "PULS A" );
4012 outline1( "STA %s", address_displacement(_environment, _value, "0") );
4013 break;
4014 case STACK_WORD:
4015 outline0( "PULS D" );
4016 outline1( "STD %s", address_displacement(_environment, _value, "0") );
4017 break;
4018 case STACK_DWORD:
4019 outline0( "PULS D" );
4020 outline1( "STD %s", address_displacement(_environment, _value, "0") );
4021 outline0( "PULS D" );
4022 outline1( "STD %s", address_displacement(_environment, _value, "2") );
4023 break;
4024 }
4025
4026 }
4027
4028}
4029
4030void cpu_return( Environment * _environment ) {
4031
4032 inline( cpu_return )
4033
4034 outline0( "RTS" );
4035
4037
4038}
4039
4040void cpu_pop( Environment * _environment ) {
4041
4042 inline( cpu_pop )
4043
4044 outline0( "LEAS 2,S" );
4045
4047
4048}
4049
4050void cpu_halt( Environment * _environment ) {
4051
4052 inline( cpu_halt )
4053
4055
4056 outline0( "; HALT" );
4057 outhead1("%s", label );
4058 B(RA, label);
4059
4061
4062}
4063
4064void cpu_end( Environment * _environment ) {
4065
4066 inline( cpu_end )
4067
4068 outline0( "ANDCC #$6f" );
4069 cpu_halt( _environment );
4070
4072
4073}
4074
4075void cpu_random( Environment * _environment, char * _entropy ) {
4076
4077 if ( ! _environment->deployed.random ) {
4078
4079 inline( cpu_random )
4080
4082
4083 srand( time( NULL ) );
4084
4085 if ( _entropy ) {
4086 outline0("LDD CPURANDOM_SEED");
4087 outline0("ASLB");
4088 outline0("ASLB");
4089 outline0("ROLA");
4090 outline0("ADDD CPURANDOM_SEED+2");
4091 outline0("LSR CPURANDOM_SEED");
4092 outline0("ROR CPURANDOM_SEED+1");
4093 outline0("ASLB");
4094 outline0("ROLA");
4095 outline1("ADDA %s", _entropy);
4096 outline0("ASLB");
4097 outline0("ROLA");
4098 outline0("ASLB");
4099 outline0("ROLA");
4100 outline0("ADDD CPURANDOM_SEED+1");
4101 outline0("STD CPURANDOM_SEED+1");
4102 }
4103
4104 embedded( cpu_random, src_hw_6309_cpu_random_asm );
4105
4106 _environment->deployed.random = 1;
4107
4108 if ( _entropy ) {
4109 outline1( "LDB %s", _entropy );
4110 outline0( "STB <PATTERN" );
4111 }
4112
4113 outline0( "JSR CPURANDOM" );
4114
4115 done( )
4116
4117 } else {
4118
4119 if ( _entropy ) {
4120 outline1( "LDB %s", _entropy );
4121 outline0( "STB <PATTERN" );
4122 }
4123
4124 outline0( "JSR CPURANDOM" );
4125
4126 }
4127}
4128
4129void cpu_random_8bit( Environment * _environment, char * _entropy, char * _result ) {
4130
4131 cpu_random( _environment, _entropy );
4132
4133 if ( _result ) {
4134 outline0("LDB CPURANDOM_SEED+3");
4135 outline1("STB %s", _result );
4136 }
4137
4138}
4139
4140void cpu_random_16bit( Environment * _environment, char * _entropy, char * _result ) {
4141
4142 cpu_random( _environment, _entropy );
4143
4144 if ( _result ) {
4145 outline0("LDD CPURANDOM_SEED+2");
4146 outline1("STD %s", _result );
4147 }
4148
4149}
4150
4151void cpu_random_32bit( Environment * _environment, char * _entropy, char * _result ) {
4152
4153 cpu_random( _environment, _entropy );
4154
4155 if ( _result ) {
4156 outline0("LDD CPURANDOM_SEED");
4157 outline1("STD %s", _result );
4158 outline0("LDD CPURANDOM_SEED+2");
4159 outline1("STD %s", address_displacement(_environment, _result, "2") );
4160 }
4161
4162}
4163
4164void cpu_limit_16bit( Environment * _environment, char * _variable, int _value ) {
4165
4166 inline( cpu_limit_16bit )
4167
4169
4170 outline0( "LDA #$0" );
4171 outline1( "STA %s", _variable );
4172 outline1( "LDA %s", address_displacement(_environment, _variable, "1") );
4173 outline1( "CMPA #$%2.2x", _value );
4174 outline1( "BCC %s", label );
4175 outline1( "SUBA #$%2.2x", _value );
4176 outline1( "STA %s", _variable );
4177 outhead1( "%s", label );
4178
4180
4181}
4182
4183void cpu_busy_wait( Environment * _environment, char * _timing ) {
4184
4185 inline( cpu_busy_wait )
4186
4188
4189 outline1("LDA %s", _timing );
4190 outhead1("%s", label );
4191 outline0("DECA");
4192 outline1("BNE %s", label);
4193
4195
4196}
4197
4198void cpu_logical_and_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4199
4200 inline( cpu_logical_and_8bit )
4201
4203
4204 outline1("LDB %s", _left );
4205 outline1("BEQ %s", label );
4206 outline1("LDB %s", _right );
4207 outline1("BEQ %s", label );
4208 outline0("LDB #$FF");
4209 outhead1("%s", label);
4210 outline1("STB %s", _result);
4211
4213
4214}
4215
4216void cpu_and_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4217
4218 inline( cpu_and_8bit )
4219
4221
4222 outline1("LDB %s", _right );
4223 outline1("ANDB %s", _left );
4224 outline1("STB %s", _result);
4225
4227
4228}
4229
4230void cpu_and_8bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
4231
4232 inline( cpu_and_8bit )
4233
4235
4236 outline1("LDB %s", _left );
4237 outline1("ANDB #$%2.2x", _right );
4238 outline1("STB %s", _result);
4239
4241
4242}
4243
4244void cpu_and_16bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4245
4246 inline( cpu_and_16bit )
4247
4249
4250 outline1("LDD %s", _right );
4251 outline1("ANDD %s", _left );
4252 outline1("STD %s", _result);
4253
4255
4256}
4257
4258void cpu_and_32bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4259
4260 inline( cpu_and_32bit )
4261
4263
4264 outline1("LDD %s", _left );
4265 outline1("ANDD %s", _right );
4266 outline1("STD %s", _result);
4267 outline1("LDD %s", address_displacement(_environment, _left, "2") );
4268 outline1("ANDD %s", address_displacement(_environment, _right, "2") );
4269 outline1("STD %s", address_displacement(_environment, _result, "2"));
4270
4272
4273}
4274
4275void cpu_logical_or_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4276
4277 inline( cpu_logical_or_8bit )
4278
4280
4281 outline1("LDB %s", _left );
4282 outline1("ORB %s", _right );
4283 outline1("BEQ %s", label);
4284 outline0("LDB #$FF");
4285 outhead1("%s", label);
4286 outline1("STB %s", _result);
4287
4289
4290}
4291
4292void cpu_or_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4293
4294 inline( cpu_or_8bit )
4295
4297
4298 outline1("LDB %s", _right );
4299 outline1("ORB %s", _left );
4300 outline1("STB %s", _result);
4301
4303
4304}
4305
4306void cpu_or_8bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
4307
4308 inline( cpu_or_8bit )
4309
4311
4312 outline1("LDB %s", _left );
4313 outline1("ORB #$%2.2x", _right );
4314 outline1("STB %s", _result);
4315
4317
4318}
4319
4320void cpu_or_16bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4321
4322 inline( cpu_or_16bit )
4323
4325
4326 outline1("LDD %s", _left );
4327 outline1("ORA %s", _right );
4328 outline1("ORB %s", address_displacement(_environment, _right, "1") );
4329 outline1("STD %s", _result);
4330
4332
4333}
4334
4335void cpu_or_32bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4336
4337 inline( cpu_or_32bit )
4338
4340
4341 outline1("LDD %s", _left );
4342 outline1("ORA %s", _right );
4343 outline1("ORB %s", address_displacement(_environment, _right, "1") );
4344 outline1("STD %s", _result);
4345 outline1("LDD %s", address_displacement(_environment, _left, "2") );
4346 outline1("ORA %s", address_displacement(_environment, _right, "2") );
4347 outline1("ORB %s", address_displacement(_environment, _right, "3") );
4348 outline1("STD %s", address_displacement(_environment, _result, "2"));
4349
4351
4352}
4353
4354void cpu_xor_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4355
4356 inline( cpu_xor_8bit )
4357
4359
4360 outline1("LDB %s", _right );
4361 outline1("EORB %s", _left );
4362 outline1("STB %s", _result);
4363
4365
4366}
4367
4368void cpu_xor_8bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
4369
4370 inline( cpu_xor_8bit )
4371
4373
4374 outline1("LDB %s", _left );
4375 outline1("EORB #$%2.2x", _right );
4376 outline1("STB %s", _result);
4377
4379
4380}
4381
4382void cpu_xor_16bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4383
4384 inline( cpu_xor_16bit )
4385
4387
4388 outline1("LDD %s", _left );
4389 outline1("EORA %s", _right );
4390 outline1("EORB %s", address_displacement(_environment, _right, "1") );
4391 outline1("STD %s", _result);
4392
4394
4395}
4396
4397void cpu_xor_16bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
4398
4399 inline( cpu_xor_16bit )
4400
4402
4403 outline1("LDD %s", _left );
4404 outline1("EORA #$%2.2x", (unsigned char)((_right >> 8) & 0xff ) );
4405 outline1("EORB #$%2.2x", (unsigned char)((_right) & 0xff ) );
4406 outline1("STD %s", _result);
4407
4409
4410}
4411
4412
4413void cpu_xor_32bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4414
4415 inline( cpu_xor_32bit )
4416
4418
4419 outline1("LDD %s", _left );
4420 outline1("EORA %s", _right );
4421 outline1("EORB %s", address_displacement(_environment, _right, "1") );
4422 outline1("STD %s", _result);
4423 outline1("LDD %s", address_displacement(_environment, _left, "2") );
4424 outline1("EORA %s", address_displacement(_environment, _right, "2") );
4425 outline1("EORB %s", address_displacement(_environment, _right, "3") );
4426 outline1("STD %s", address_displacement(_environment, _result, "2"));
4427
4429
4430}
4431
4432void cpu_xor_32bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
4433
4434 inline( cpu_xor_32bit )
4435
4437
4438 outline1("LDD %s", _left );
4439 outline1("EORA #$%2.2x", (unsigned char)( (_right >> 24) & 0xff ) );
4440 outline1("EORB #$%2.2x", (unsigned char)( (_right >> 16) & 0xff ) );
4441 outline1("STD %s", _result);
4442 outline1("LDD %s", address_displacement(_environment, _left, "2") );
4443 outline1("EORA #$%2.2x", (unsigned char)( (_right >> 8) & 0xff ) );
4444 outline1("EORB #$%2.2x", (unsigned char)( (_right) & 0xff ) );
4445 outline1("STD %s", address_displacement(_environment, _result, "2"));
4446
4448
4449}
4450
4451void cpu_swap_8bit( Environment * _environment, char * _left, char * _right ) {
4452
4454
4455 embedded( cpu_swap_8bit, src_hw_6309_cpu_swap_asm ); // it is not an error: swap 8/16/32 shares code
4456
4457 outline1("LDX #%s", _right );
4458 outline1("LDY #%s", _left );
4459 outline0("JSR CPUSWAP1" );
4460
4461 done( )
4462
4463}
4464
4465void cpu_swap_16bit( Environment * _environment, char * _left, char * _right ) {
4466
4468
4469 embedded( cpu_swap_8bit, src_hw_6309_cpu_swap_asm ); // it is not an error: swap 8/16/32 shares code
4470
4471 outline1("LDX #%s", _right );
4472 outline1("LDY #%s", _left );
4473 outline0("JSR CPUSWAP2" );
4474
4475 done( )
4476
4477}
4478
4479void cpu_swap_32bit( Environment * _environment, char * _left, char * _right ) {
4480
4482
4483 embedded( cpu_swap_8bit, src_hw_6309_cpu_swap_asm ); // it is not an error: swap 8/16/32 shares code
4484
4485 outline1("LDX #%s", _right );
4486 outline1("LDY #%s", _left );
4487 outline0("JSR CPUSWAP4" );
4488
4489 done( )
4490
4491}
4492
4493void cpu_logical_not_8bit( Environment * _environment, char * _value, char * _result ) {
4494
4495 inline( cpu_logical_not_8bit )
4496
4497 outline1("LDB %s", _value );
4498 outline0("COMA" );
4499 outline1("STB %s", _result );
4500
4502
4503}
4504
4505void cpu_not_8bit( Environment * _environment, char * _value, char * _result ) {
4506
4507 inline( cpu_not_8bit )
4508
4509 outline1("LDB %s", _value );
4510 outline0("COMB" );
4511 outline1("STB %s", _result );
4512
4514
4515}
4516
4517void cpu_not_16bit( Environment * _environment, char * _value, char * _result ) {
4518
4519 inline( cpu_not_16bit )
4520
4521 outline1("LDD %s", _value );
4522 outline0("COMA" );
4523 outline0("COMB" );
4524 outline1("STD %s", _result );
4525
4527
4528}
4529
4530void cpu_not_32bit( Environment * _environment, char * _value, char * _result ) {
4531
4532 inline( cpu_not_32bit )
4533
4534 outline1("LDD %s", _value );
4535 outline0("COMA" );
4536 outline0("COMB" );
4537 outline1("STD %s", _result );
4538 outline1("LDD %s", address_displacement(_environment, _value, "2") );
4539 outline0("COMA" );
4540 outline0("COMB" );
4541 outline1("STD %s", address_displacement(_environment, _result, "2") );
4542
4544
4545}
4546
4547void cpu_di( Environment * _environment ) {
4548 outline0( "ORCC #$50" );
4549}
4550
4551void cpu_ei( Environment * _environment ) {
4552 outline0( "ANDCC #$AF" );
4553}
4554
4555void cpu_inc( Environment * _environment, char * _variable ) {
4556
4557 inline( cpu_inc )
4558
4559 outline1("INC %s", _variable );
4560
4562
4563}
4564
4565void cpu_inc_16bit( Environment * _environment, char * _variable ) {
4566
4567 inline( cpu_inc_16bit )
4568
4569 // 16 cycles all times, but extra possibilites for peephole
4570 // outline0("LDD #1" );
4571 // outline1("ADDD %s", _variable );
4572 // outline1("STD %s", _variable );
4573
4575
4576 // 10 cycles 255 times out of 256 and 17 one out of 256
4577 outline1("INC %s", address_displacement(_environment, _variable, "1"));
4578 outline1("BNE %s", label);
4579 outline1("INC %s", _variable);
4580 outhead1("%s", label)
4581
4583
4584}
4585
4586void cpu_inc_32bit( Environment * _environment, char * _variable ) {
4587
4588 inline( cpu_inc_32bit )
4589
4590 // outline1("LDD %s", address_displacement(_environment, _variable, "2") );
4591 // outline0("ADDD #1" );
4592 // outline1("STD %s", address_displacement(_environment, _variable, "2") );
4593 // outline1("LDD %s", _variable );
4594 // outline0("ADCB #0" );
4595 // outline0("ADCA #0" );
4596 // outline1("STD %s", _variable );
4597
4599
4600 outline1("INC %s", address_displacement(_environment, _variable, "3"));
4601 outline1("BNE %s", label);
4602 outline1("INC %s", address_displacement(_environment, _variable, "2"));
4603 outline1("BNE %s", label);
4604 outline1("INC %s", address_displacement(_environment, _variable, "1"));
4605 outline1("BNE %s", label);
4606 outline1("INC %s", _variable);
4607 outhead1("%s", label)
4608
4610
4611}
4612
4613void cpu_inc_nbit( Environment * _environment, char * _variable, int _bits ) {
4614
4616
4617 inline( cpu_inc_nbit )
4618
4619 for( int i=(_bits>>3)-1; i>-1;--i ) {
4620 char offset[MAX_TEMPORARY_STORAGE]; sprintf(offset, "%d", i );
4621 outline1("INC %s", address_displacement(_environment, _variable, offset ) );
4622 outline1("BNE %s", label );
4623 }
4624 outhead1("%s", label );
4625
4627
4628}
4629
4630void cpu_dec( Environment * _environment, char * _variable ) {
4631
4632 inline( cpu_dec )
4633
4634 outline1("DEC %s", _variable );
4635
4637
4638}
4639
4640void cpu_dec_16bit( Environment * _environment, char * _variable ) {
4641
4642 inline( cpu_dec_16bit )
4643
4644 outline1("LDD %s", _variable );
4645 outline0("SUBD #1" );
4646 outline1("STD %s", _variable );
4647
4649
4650}
4651
4652void cpu_dec_32bit( Environment * _environment, char * _variable ) {
4653
4655
4656 inline( cpu_dec_32bit )
4657
4658 outline1("LDD %s", address_displacement( _environment, _variable, "2" ) );
4659 outline0("SUBD #1" );
4660 outline1("STD %s", address_displacement( _environment, _variable, "2" ) );
4661 outline0("CMPD #$FFFF" );
4662 outline1("BNE %s", label );
4663 outline1("LDD %s", _variable );
4664 outline0("SUBD #1" );
4665 outline1("STD %s", _variable );
4666 outhead1("%s", label );
4667
4669
4670}
4671
4672void cpu_dec_nbit( Environment * _environment, char * _variable, int _bits ) {
4673
4675
4676 inline( cpu_dec_32bit )
4677
4678 for( int i=(_bits>>3)-1; i>-1; --i ) {
4679 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
4680 outline1("DEC %s", address_displacement(_environment, _variable, offset) );
4681 outline1("LDA %s", address_displacement(_environment, _variable, offset) );
4682 outline0("CMPA #$FF" );
4683 outline1("BNE %s", label );
4684 }
4685 outhead1("%s", label );
4686
4688
4689}
4690
4691
4692void cpu_mem_move( Environment * _environment, char *_source, char *_destination, char *_size ) {
4693
4694 deploy_preferred( duff, src_hw_6309_duff_asm );
4695
4697
4698 embedded( cpu_mem_move, src_hw_6309_cpu_mem_move_asm )
4699
4700 outline0("LDA #0" );
4701 outline1("LDB %s", _size );
4702 outline0("TFR D, W" );
4703 outline1("LDY %s", _source );
4704 outline1("LDX %s", _destination );
4705 outline0("JSR DUFFDEVICE" );
4706
4707 done( )
4708
4709}
4710
4711void cpu_mem_move_16bit( Environment * _environment, char *_source, char *_destination, char *_size ) {
4712
4713 deploy_preferred( duff, src_hw_6309_duff_asm );
4714
4716
4717 embedded( cpu_mem_move, src_hw_6309_cpu_mem_move_asm )
4718
4719 outline1("LDW %s", _size );
4720 outline1("LDY %s", _source );
4721 outline1("LDX %s", _destination );
4722 outline0("JSR DUFFDEVICE" );
4723
4724 done( )
4725
4726}
4727
4728void cpu_mem_move_direct( Environment * _environment, char *_source, char *_destination, char *_size ) {
4729
4730 deploy_preferred( duff, src_hw_6309_duff_asm );
4731
4733
4734 embedded( cpu_mem_move, src_hw_6309_cpu_mem_move_asm )
4735
4736 outline0("LDA #0" );
4737 outline1("LDB %s", _size );
4738 outline0("TFR D, W" );
4739 outline1("LDY #%s", _source );
4740 outline1("LDX #%s", _destination );
4741 outline0("JSR DUFFDEVICE" );
4742
4743 done( )
4744
4745}
4746
4747void cpu_mem_move_direct2_size( Environment * _environment, char *_source, char *_destination, int _size ) {
4748
4749 deploy_preferred( duff, src_hw_6309_duff_asm );
4750
4752
4753 embedded( cpu_mem_move, src_hw_6309_cpu_mem_move_asm )
4754
4755 outline1("LDW #$%4.4x", _size );
4756 outline1("LDY %s", _source );
4757 outline1("LDX #%s", _destination );
4758 outline0("JSR DUFFDEVICE" );
4759
4760 done( )
4761
4762}
4763
4764void cpu_mem_move_direct2( Environment * _environment, char *_source, char *_destination, char *_size ) {
4765
4766 deploy_preferred( duff, src_hw_6309_duff_asm );
4767
4769
4770 embedded( cpu_mem_move, src_hw_6309_cpu_mem_move_asm )
4771
4772 outline1("LDW %s", _size );
4773 outline1("LDY %s", _source );
4774 outline1("LDX #%s", _destination );
4775 outline0("JSR DUFFDEVICE" );
4776
4777 done( )
4778
4779}
4780
4781void cpu_mem_move_size( Environment * _environment, char *_source, char *_destination, int _size ) {
4782
4783 deploy_preferred( duff, src_hw_6309_duff_asm );
4784
4786
4787 embedded( cpu_mem_move, src_hw_6309_cpu_mem_move_asm )
4788
4789 outline1("LDW #$%4.4x", _size );
4790 outline1("LDY %s", _source );
4791 outline1("LDX %s", _destination );
4792 outline0("JSR DUFFDEVICE" );
4793
4794 done( )
4795
4796}
4797
4798void cpu_mem_move_direct_size( Environment * _environment, char *_source, char *_destination, int _size ) {
4799
4800 deploy_preferred( duff, src_hw_6309_duff_asm );
4801
4803
4804 embedded( cpu_mem_move, src_hw_6309_cpu_mem_move_asm )
4805
4806 outline1("LDW #$%4.4x", _size );
4807 outline1("LDY #%s", _source );
4808 outline1("LDX #%s", _destination );
4809 outline0("JSR DUFFDEVICE" );
4810
4811 done( )
4812
4813}
4814
4815void cpu_mem_move_direct_indirect_size( Environment * _environment, char *_source, char *_destination, int _size ) {
4816
4817 deploy_preferred( duff, src_hw_6309_duff_asm );
4818
4820
4821 embedded( cpu_mem_move, src_hw_6309_cpu_mem_move_asm )
4822
4823 outline1("LDW #$%4.4x", _size );
4824 outline1("LDY #%s", _source );
4825 outline1("LDX %s", _destination );
4826 outline0("JSR DUFFDEVICE" );
4827
4828 done( )
4829
4830}
4831
4832void cpu_mem_move_indirect_direct_size( Environment * _environment, char *_source, char *_destination, int _size ) {
4833
4834 deploy_preferred( duff, src_hw_6309_duff_asm );
4835
4837
4838 embedded( cpu_mem_move, src_hw_6309_cpu_mem_move_asm )
4839
4840 outline1("LDW #$%4.4x", _size );
4841 outline1("LDY %s", _source );
4842 outline1("LDX #%s", _destination );
4843 outline0("JSR DUFFDEVICE" );
4844
4845 done( )
4846
4847}
4848
4849void cpu_compare_memory( Environment * _environment, char *_source, char *_destination, char *_size, char * _result, int _equal ) {
4850
4851 inline( cpu_compare_memory )
4852
4854
4855 outline1("LDA %s", _size );
4856 outline1("BEQ %sequal", label );
4857
4858 outline1("LDY %s", _source );
4859 outline1("LDX %s", _destination );
4860
4861 outline1("LDA %s", _size );
4862 outline0("ANDA #$80" );
4863 outline1("BEQ %ssecond", label );
4864
4865 outhead1("%sfirst", label );
4866 outline0("LDA #0" );
4867 outhead1("%sloop", label );
4868 outline0("LDB A,X" );
4869 outline0("CMPB A,Y" );
4870 outline1("BNE %sdiff", label );
4871 outline0("ADDA #1" );
4872 outline0("CMPA #$7F" );
4873 outline1("BNE %sloop", label );
4874 outline0("LEAY 127,Y" );
4875 outline0("LEAX 127,X" );
4876 outline0("LEAY 1,Y" );
4877 outline0("LEAX 1,X" );
4878
4879 outhead1("%ssecond", label );
4880 outline1("LDA %s", _size );
4881 outline0("ANDA #$7f" );
4882 outline0("STA <MATHPTR0" );
4883 outline0("LDA #0" );
4884 outhead1("%sloop2", label );
4885 outline0("LDB A,X" );
4886 outline0("CMPB A,Y" );
4887 outline1("BNE %sdiff", label );
4888 outline0("ADDA #1" );
4889 outline0("CMPA <MATHPTR0" );
4890 outline1("BNE %sloop2", label );
4891
4892 outhead1("%sequal", label );
4893 outline1("LDA #$%2.2x", _equal ? 0xff : 0x00 );
4894 outline1("STA %s", _result );
4895 outline1("JMP %sfinal", label );
4896
4897 outhead1("%sdiff", label );
4898 outline1("LDA #$%2.2x", _equal ? 0x00 : 0xff );
4899 outline1("STA %s", _result );
4900 outhead1("%sfinal", label );
4901
4903
4904}
4905
4906void cpu_compare_memory_size( Environment * _environment, char *_source, char *_destination, int _size, char * _result, int _equal ) {
4907
4908 inline( cpu_compare_memory_size )
4909
4911
4912 if ( _size ) {
4913
4914 outline1("LDY %s", _source );
4915 outline1("LDX %s", _destination );
4916
4917 if ( _size >= 0x7f ) {
4918
4919 outhead1("%sfirst", label );
4920 outline0("LDA #0" );
4921 outhead1("%sloop", label );
4922 outline0("LDB A,X" );
4923 outline0("CMPB A,Y" );
4924 outline1("BNE %sdiff", label );
4925 outline0("ADDA #1" );
4926 outline0("CMPA #$7F" );
4927 outline1("BNE %sloop", label );
4928 outline0("LEAY 127,Y" );
4929 outline0("LEAX 127,X" );
4930 outline0("LEAY 1,Y" );
4931 outline0("LEAX 1,X" );
4932
4933 _size -= 0x7f;
4934
4935 }
4936
4937 if ( _size ) {
4938
4939 outhead1("%ssecond", label );
4940 outline1("LDA #$%2.2x", _size );
4941 outline0("STA <MATHPTR0" );
4942 outline0("LDA #0" );
4943 outhead1("%sloop2", label );
4944 outline0("LDB A,X" );
4945 outline0("CMPB A,Y" );
4946 outline1("BNE %sdiff", label );
4947 outline0("ADDA #1" );
4948 outline0("CMPA <MATHPTR0" );
4949 outline1("BNE %sloop2", label );
4950
4951 }
4952
4953 outhead1("%sequal", label );
4954 outline1("LDA #$%2.2x", _equal ? 0xff : 0x00 );
4955 outline1("STA %s", _result );
4956 outline1("JMP %sfinal", label );
4957
4958 outhead1("%sdiff", label );
4959 outline1("LDA #$%2.2x", _equal ? 0x00 : 0xff );
4960 outline1("STA %s", _result );
4961 outhead1("%sfinal", label );
4962
4963 }
4964
4965 no_embedded( cpu_compare_memory_soze )
4966
4967}
4968
4969void cpu_less_than_memory( Environment * _environment, char *_source, char *_destination, char *_size, char * _result, int _equal ) {
4970
4971 inline( cpu_less_than_memory )
4972
4974
4975 outline1("LDA %s", _size );
4976 outline1("BEQ %sequal", label );
4977
4978 outline1("LDY %s", _destination );
4979 outline1("LDX %s", _source );
4980
4981 outline1("LDA %s", _size );
4982 outline0("ANDA #$80" );
4983 outline1("BEQ %ssecond", label );
4984
4985 outhead1("%sfirst", label );
4986 outline0("LDA #0" );
4987 outhead1("%sloop", label );
4988 outline0("LDB A,X" );
4989 outline0("CMPB A,Y" );
4990 if ( _equal ) {
4991 outline1("BHI %sdiff", label);
4992 } else {
4993 outline1("BHS %sdiff", label);
4994 }
4995 outline0("ADDA #1" );
4996 outline0("CMPA #$7F" );
4997 outline1("BNE %sloop", label );
4998 outline0("LEAY 127,Y" );
4999 outline0("LEAX 127,X" );
5000 outline0("LEAY 1,Y" );
5001 outline0("LEAX 1,X" );
5002
5003 outhead1("%ssecond", label );
5004 outline1("LDA %s", _size );
5005 outline0("ANDA #$7f" );
5006 outline0("STA <MATHPTR0" );
5007 outline0("LDA #0" );
5008 outhead1("%sloop2", label );
5009 outline0("LDB A,X" );
5010 outline0("CMPB A,Y" );
5011 if ( _equal ) {
5012 outline1("BHI %sdiff", label);
5013 } else {
5014 outline1("BHS %sdiff", label);
5015 }
5016 outline0("ADDA #1" );
5017 outline0("CMPA <MATHPTR0" );
5018 outline1("BNE %sloop2", label );
5019
5020 outhead1("%sequal", label );
5021 outline0("LDA #$FF");
5022 outline1("STA %s", _result );
5023 outline1("JMP %sfinal", label );
5024
5025 outhead1("%sdiff", label );
5026 outline0("LDA #$0");
5027 outline1("STA %s", _result );
5028 outhead1("%sfinal", label );
5029
5031
5032}
5033
5034void cpu_less_than_memory_size( Environment * _environment, char *_source, char *_destination, int _size, char * _result, int _equal ) {
5035
5037
5039
5040 if ( _size ) {
5041
5042 outline1("LDY %s", _destination );
5043 outline1("LDX %s", _source );
5044
5045 if ( _size >= 0x7f ) {
5046
5047 outhead1("%sfirst", label );
5048 outline0("LDA #0" );
5049 outhead1("%sloop", label );
5050 outline0("LDB A,X" );
5051 outline0("CMPB A,Y" );
5052 if ( _equal ) {
5053 outline1("BHI %sdiff", label);
5054 } else {
5055 outline1("BHS %sdiff", label);
5056 }
5057 outline0("ADDA #1" );
5058 outline0("CMPA #$7F" );
5059 outline1("BNE %sloop", label );
5060 outline0("LEAY 127,Y" );
5061 outline0("LEAX 127,X" );
5062 outline0("LEAY 1,Y" );
5063 outline0("LEAX 1,X" );
5064
5065 _size -= 0x7f;
5066
5067 }
5068
5069 if ( _size ) {
5070
5071 outhead1("%ssecond", label );
5072 outline1("LDA #$%2.2x", _size );
5073 outline0("STA <MATHPTR0" );
5074 outline0("LDA #0" );
5075 outhead1("%sloop2", label );
5076 outline0("LDB A,X" );
5077 outline0("CMPB A,Y" );
5078 if ( _equal ) {
5079 outline1("BHI %sdiff", label);
5080 } else {
5081 outline1("BHS %sdiff", label);
5082 }
5083 outline0("ADDA #1" );
5084 outline0("CMPA <MATHPTR0" );
5085 outline1("BNE %sloop2", label );
5086
5087 }
5088
5089 outhead1("%sequal", label );
5090 outline0("LDA #$FF");
5091 outline1("STA %s", _result );
5092 outline1("JMP %sfinal", label );
5093
5094 outhead1("%sdiff", label );
5095 outline0("LDA #$0");
5096 outline1("STA %s", _result );
5097 outhead1("%sfinal", label );
5098
5099 }
5100
5102
5103}
5104
5105void cpu_greater_than_memory( Environment * _environment, char *_source, char *_destination, char *_size, char * _result, int _equal ) {
5106
5107 inline( cpu_greater_than_memory )
5108
5110
5111 outline1("LDA %s", _size );
5112 outline1("BEQ %sequal", label );
5113
5114 outline1("LDY %s", _destination );
5115 outline1("LDX %s", _source );
5116
5117 outline1("LDA %s", _size );
5118 outline0("ANDA #$80" );
5119 outline1("BEQ %ssecond", label );
5120
5121 outhead1("%sfirst", label );
5122 outline0("LDA #0" );
5123 outhead1("%sloop", label );
5124 outline0("LDB A,X" );
5125 outline0("CMPB A,Y" );
5126 if ( _equal ) {
5127 outline1("BLO %sdiff", label);
5128 } else {
5129 outline1("BLS %sdiff", label);
5130 }
5131 outline0("ADDA #1" );
5132 outline0("CMPA #$7F" );
5133 outline1("BNE %sloop", label );
5134 outline0("LEAY 127,Y" );
5135 outline0("LEAX 127,X" );
5136 outline0("LEAY 1,Y" );
5137 outline0("LEAX 1,X" );
5138
5139 outhead1("%ssecond", label );
5140 outline1("LDA %s", _size );
5141 outline0("ANDA #$7f" );
5142 outline0("STA <MATHPTR0" );
5143 outline0("LDA #0" );
5144 outhead1("%sloop2", label );
5145 outline0("LDB A,X" );
5146 outline0("CMPB A,Y" );
5147 if ( _equal ) {
5148 outline1("BLO %sdiff", label);
5149 } else {
5150 outline1("BLS %sdiff", label);
5151 }
5152 outline0("ADDA #1" );
5153 outline0("CMPA <MATHPTR0" );
5154 outline1("BNE %sloop2", label );
5155
5156 outhead1("%sequal", label );
5157 outline0("LDA #$FF");
5158 outline1("STA %s", _result );
5159 outline1("JMP %sfinal", label );
5160
5161 outhead1("%sdiff", label );
5162 outline0("LDA #$0");
5163 outline1("STA %s", _result );
5164 outhead1("%sfinal", label );
5165
5167
5168}
5169
5170void cpu_greater_than_memory_size( Environment * _environment, char *_source, char *_destination, int _size, char * _result, int _equal ) {
5171
5173
5175
5176 if ( _size ) {
5177
5178 outline1("LDY %s", _destination );
5179 outline1("LDX %s", _source );
5180
5181 if ( _size >= 0x7f ) {
5182
5183 outhead1("%sfirst", label );
5184 outline0("LDA #0" );
5185 outhead1("%sloop", label );
5186 outline0("LDB A,X" );
5187 outline0("CMPB A,Y" );
5188 if ( _equal ) {
5189 outline1("BLO %sdiff", label);
5190 } else {
5191 outline1("BLS %sdiff", label);
5192 }
5193 outline0("ADDA #1" );
5194 outline0("CMPA #$7F" );
5195 outline1("BNE %sloop", label );
5196 outline0("LEAY 127,Y" );
5197 outline0("LEAX 127,X" );
5198
5199 _size -= 0x7f;
5200
5201 }
5202
5203 if ( _size ) {
5204
5205 outhead1("%ssecond", label );
5206 outline1("LDA #$%2.2x", _size );
5207 outline0("STA <MATHPTR0" );
5208 outline0("LDA #0" );
5209 outhead1("%sloop2", label );
5210 outline0("LDB A,X" );
5211 outline0("CMPB A,Y" );
5212 if ( _equal ) {
5213 outline1("BLO %sdiff", label);
5214 } else {
5215 outline1("BLS %sdiff", label);
5216 }
5217 outline0("ADDA #1" );
5218 outline0("CMPA <MATHPTR0" );
5219 outline1("BNE %sloop2", label );
5220
5221 }
5222
5223 outhead1("%sequal", label );
5224 outline0("LDA #$FF");
5225 outline1("STA %s", _result );
5226 outline1("JMP %sfinal", label );
5227
5228 outhead1("%sdiff", label );
5229 outline0("LDA #$0");
5230 outline1("STA %s", _result );
5231 outhead1("%sfinal", label );
5232
5233 }
5234
5236
5237}
5238
5239void cpu_move_8bit_indirect( Environment * _environment, char *_source, char * _value ) {
5240
5241 inline( cpu_move_8bit_indirect )
5242
5243 outline1("LDB %s", _source);
5244 outline1("STB [%s]", _value);
5245
5247
5248}
5249
5250void cpu_move_8bit_indirect_with_offset( Environment * _environment, char *_source, char * _value, int _offset ) {
5251
5252 inline( cpu_move_8bit_with_offset )
5253
5254 outline1("LDB %s", _source);
5255 outline1("LDX %s", _value);
5256 outline1("STB %d,X", _offset );
5257
5258 no_embedded( cpu_move_8bit_with_offset )
5259
5260}
5261
5262void cpu_move_8bit_indirect_with_offset2( Environment * _environment, char *_source, char * _value, char * _offset ) {
5263
5265
5267
5268 outline1("LDA %s", _source);
5269 outline1("LDX %s", _value);
5270 outline1("LDB %s", _offset);
5271 outline0("ABX");
5272 outline0("STA ,X");
5273
5275
5276}
5277
5278void cpu_move_8bit_with_offset2( Environment * _environment, char *_source, char * _value, char * _offset ) {
5279
5281
5283
5284 outline1("LDX #%s", _value);
5285 outline1("LDB %s", _offset);
5286 outline0("ABX");
5287 outline1("LDA %s", _source);
5288 outline0("STA ,X");
5289
5291
5292}
5293
5294void cpu_move_8bit_indirect2( Environment * _environment, char * _value, char *_source ) {
5295
5296 inline( cpu_move_8bit_indirect2 )
5297
5299
5300 outline1("LDB [%s]", _value);
5301 outline1("STB %s", _source );
5302
5304
5305}
5306
5307void cpu_move_8bit_indirect2_8bit( Environment * _environment, char * _value, char * _offset, char *_source ) {
5308
5310
5312
5313 outline1("LDX #%s", _value);
5314 outline1("LDB %s", _offset);
5315 outline0("ABX");
5316 outline0("LDB ,X");
5317 outline1("STB %s", _source);
5318
5320
5321}
5322
5323void cpu_move_8bit_indirect2_16bit( Environment * _environment, char * _value, char * _offset, char *_source ) {
5324
5326
5328
5329 outline1("LDX #%s", _value);
5330 outline1("LDD %s", _offset);
5331 outline0("LEAX D,X");
5332 outline0("LDA ,X");
5333 outline1("STA %s", _source);
5334
5336
5337}
5338
5339void cpu_move_16bit_indirect( Environment * _environment, char *_source, char * _value ) {
5340
5341 inline( cpu_move_16bit_indirect )
5342
5344
5345 outline1("LDD %s", _source);
5346 outline1("STD [%s]", _value);
5347
5349
5350}
5351
5352void cpu_move_16bit_indirect2( Environment * _environment, char * _value, char *_source ) {
5353
5354 inline( cpu_move_16bit_indirect2 )
5355
5357
5358 outline1("LDD [%s]", _value);
5359 outline1("STD %s", _source );
5360
5362
5363}
5364
5365void cpu_move_16bit_indirect2_8bit( Environment * _environment, char * _value, char * _offset, char *_source ) {
5366
5368
5370
5371 outline1("LDX #%s", _value);
5372 outline1("LDB %s", _offset);
5373 outline0("ABX");
5374 outline0("ABX");
5375 outline0("LDD ,X");
5376 outline1("STD %s", _source);
5377
5379
5380}
5381
5382void cpu_move_32bit_indirect( Environment * _environment, char *_source, char * _value ) {
5383
5384 inline( cpu_move_32bit_indirect )
5385
5387
5388 outline1("LDX %s", _value);
5389 outline0("LDD ,X");
5390 outline1("STD %s", _source );
5391 outline0("LDD 2,X");
5392 outline1("STD %s", address_displacement(_environment, _source, "2") );
5393
5395
5396}
5397
5398void cpu_move_32bit_indirect2( Environment * _environment, char * _value, char *_source ) {
5399
5400 inline( cpu_move_32bit_indirect2 )
5401
5403
5404 outline1("LDX %s", _value);
5405 outline0("LDD ,X");
5406 outline1("STD %s", _source );
5407 outline0("LDD 2,X");
5408 outline1("STD %s", address_displacement(_environment, _source, "2") );
5409
5411
5412}
5413
5414void cpu_uppercase( Environment * _environment, char *_source, char *_size, char *_result ) {
5415
5416 inline( cpu_uppercase )
5417
5419
5420 outline1("LDA %s ", _size );
5421 B(EQ, label);
5422 outline1("LDX %s", _source );
5423 if ( _result ) {
5424 outline1("LDU %s", _result );
5425 } else {
5426 outline1("LDU %s", _source );
5427 }
5428 outhead1("%supper", label );
5429 outline0("LDB ,X+" );
5430
5431 outline0("CMPB #97");
5432 outline1("BLO %snext", label);
5433
5434 outline0("CMPB #122");
5435 outline1("BHI %snext", label);
5436
5437 outline0("SUBB #32");
5438
5439 outhead1("%snext", label );
5440 outline0("STB ,U+" );
5441 outline0("DECA" );
5442 outline1("BNE %supper", label );
5443
5444 outhead1("%s", label );
5445
5447
5448
5449}
5450
5451void cpu_lowercase( Environment * _environment, char *_source, char *_size, char *_result ) {
5452
5453 inline( cpu_lowercase )
5454
5456
5457 outline1("LDA %s ", _size );
5458 B(EQ, label);
5459 outline1("LDX %s", _source );
5460 if ( _result ) {
5461 outline1("LDU %s", _result );
5462 } else {
5463 outline1("LDU %s", _source );
5464 }
5465 outhead1("%supper", label );
5466 outline0("LDB ,X+" );
5467
5468 outline0("CMPB #65");
5469 outline1("BLO %snext", label);
5470
5471 outline0("CMPB #90");
5472 outline1("BHI %snext", label);
5473
5474 outline0("ADDB #32");
5475
5476 outhead1("%snext", label );
5477 outline0("STB ,U+" );
5478 outline0("DECA" );
5479 outline1("BNE %supper", label );
5480
5481 outhead1("%s", label );
5482
5484
5485}
5486
5487void cpu_convert_string_into_8bit( Environment * _environment, char * _string, char * _len, char * _value ) {
5488
5490
5491 embedded( cpu_convert_string_into_16bit, src_hw_6309_cpu_convert_string_into_16bit_asm );
5492
5493 outline1("LDU %s", _string );
5494 outline1("LDB %s", _len );
5495 outline0("JSR CPUCONVERTSTRING8BIT" );
5496 outline1("STB %s", _value );
5497
5498 done( )
5499
5500}
5501
5502void cpu_convert_string_into_16bit( Environment * _environment, char * _string, char * _len, char * _value ) {
5503
5505
5506 embedded( cpu_convert_string_into_16bit, src_hw_6309_cpu_convert_string_into_16bit_asm );
5507
5508 outline1("LDU %s", _string );
5509 outline1("LDB %s", _len );
5510 outline0("JSR CPUCONVERTSTRING16BIT" );
5511 outline1("STX %s", _value );
5512
5513 done( )
5514
5515}
5516
5517void cpu_fill_indirect( Environment * _environment, char * _address, char * _size, char * _pattern, int _size_size ) {
5518
5519 inline( cpu_fill_indirect )
5520
5522
5523 if( _size_size >= 16 ) {
5524 outline1("LDD %s", _size);
5525 } else {
5526 outline1("LDB %s", _size);
5527 outline0("LDA #0");
5528 }
5529 outline0("TFR D,Y");
5530 outline1("LDX %s", _pattern );
5531 outline0("LDA ,X" );
5532 outline1("LDX %s", _address);
5533 outhead1("%s", label);
5534 outhead1("%sinner", label);
5535 outline0("STA ,X+");
5536 outline0("LEAY -1, Y");
5537 outline0("CMPY #$ffff");
5538 outline1("BNE %sinner", label);
5539
5541
5542}
5543
5544void cpu_flip_8bit( Environment * _environment, char * _source, char * _destination ) {
5545
5547
5548 embedded( cpu_flip, src_hw_6309_cpu_flip_asm );
5549
5550 outline1("LDA %s", _source);
5551 outline0("JSR CPUFLIP8");
5552 if ( _destination ) {
5553 outline1("STB %s", _destination);
5554 } else {
5555 outline1("STB %s", _source);
5556 }
5557
5558 done( )
5559
5560}
5561
5562void cpu_flip( Environment * _environment, char * _source, char * _size, char * _destination ) {
5563
5565
5566 embedded( cpu_flip, src_hw_6309_cpu_flip_asm );
5567
5568 outline1("LDU %s", _source);
5569 outline1("LDX %s", _destination);
5570 outline1("LDB %s", _size);
5571 outline0("JSR CPUFLIP");
5572
5573 done( )
5574
5575}
5576
5577void cpu_bit_check( Environment * _environment, char * _value, int _position, char *_result, int _bitwidth ) {
5578
5580
5581 embedded( cpu_bit_check_extended, src_hw_6309_cpu_bit_check_extended_asm );
5582
5583 switch( _bitwidth ) {
5584 case 8:
5585 outline1("LDX #%s", _value);
5586 break;
5587 case 16:
5588 outline1("LDX #%s", address_displacement( _environment, _value, "1" ) );
5589 break;
5590 case 32:
5591 outline1("LDX #%s", address_displacement( _environment, _value, "3" ) );
5592 break;
5593 }
5594 outline1("LDA #$%2.2x", _position );
5595 outline0("JSR CPUBITCHECKEXTENDED" );
5596
5597 if ( _result ) {
5598 outline1("STA %s", _result);
5599 }
5600
5601 done( )
5602
5603}
5604
5605void cpu_bit_check_extended( Environment * _environment, char * _value, char * _position, char *_result, int _bitwidth ) {
5606
5608
5609 embedded( cpu_bit_check_extended, src_hw_6309_cpu_bit_check_extended_asm );
5610
5611 switch( _bitwidth ) {
5612 case 8:
5613 outline1("LDX #%s", _value);
5614 break;
5615 case 16:
5616 outline1("LDX #(%s)", address_displacement( _environment, _value, "1" ) );
5617 break;
5618 case 32:
5619 outline1("LDX #(%s)", address_displacement( _environment, _value, "3" ) );
5620 break;
5621 }
5622 outline1("LDA %s", _position );
5623 outline0("JSR CPUBITCHECKEXTENDED" );
5624
5625 if ( _result ) {
5626 outline1("STA %s", _result);
5627 }
5628
5629 done( )
5630
5631}
5632
5633void cpu_bit_inplace_8bit( Environment * _environment, char * _value, int _position, int * _bit ) {
5634
5635 _environment->bitmaskNeeded = 1;
5636
5638
5639 no_inline( cpu_bit_inplace )
5640
5641 embedded( cpu_bit_inplace, src_hw_6309_cpu_bit_inplace_asm );
5642
5643 if ( ! _bit ) {
5644 outline0("PSHS CC");
5645 }
5646 outline1("LDX #%s", _value);
5647 outline1("LDA #$%2.2x", _position);
5648 if ( _bit ) {
5649 if ( *_bit ) {
5650 outline0("ORCC #$01");
5651 } else {
5652 outline0("ANDCC #$FE");
5653 }
5654 } else {
5655 outline0("PULS CC");
5656 }
5657 outline0("JSR CPUBITINPLACE");
5658
5659 done( )
5660
5661}
5662
5663void cpu_bit_inplace_8bit_extended_indirect( Environment * _environment, char * _address, char * _position, char * _bit ) {
5664
5665 _environment->bitmaskNeeded = 1;
5666
5668
5669 no_inline( cpu_bit_inplace )
5670
5671 embedded( cpu_bit_inplace, src_hw_6309_cpu_bit_inplace_asm );
5672
5673 outline1("LDX %s", _address);
5674 outline1("LDA %s", _position);
5675 if ( _bit ) {
5676 outline0("ANDCC #$FE");
5677 outline1("LDB %s", _bit);
5678 outline1("BEQ %s", label );
5679 outline0("ORCC #$01");
5680 outhead1("%s", label );
5681 }
5682 outline0("JSR CPUBITINPLACE");
5683
5684 done( )
5685
5686}
5687
5688void cpu_number_to_string( Environment * _environment, char * _number, char * _string, char * _string_size, int _bits, int _signed ) {
5689
5691
5692 deploy( numberToString, src_hw_6309_number_to_string_asm );
5693
5694
5695 switch( _bits ) {
5696 case 32:
5697 outline1("LDD %s", address_displacement(_environment, _number, "2") );
5698 outline1("STD N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 2 );
5699 outline1("LDD %s", _number );
5700 outline1("STD N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) );
5701 for( int i=(_environment->numberConfig.maxBytes - 4 ) - 2; i>0; i-=2 ) {
5702 outline0("LDD #0");
5703 outline1("STD N2STRINGNUMBER+%d", i );
5704 }
5705 if ( _signed ) {
5706 outline0("STA N2STRINGNUMBERSIGNED");
5707 outline1("BPL %spositive", label );
5708 char number[MAX_TEMPORARY_STORAGE];
5709 sprintf( number, "N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 2 );
5710 cpu_complement2_32bit( _environment, number, NULL);
5711 outhead1("%spositive", label );
5712 } else {
5713 outline0("CLR N2STRINGNUMBERSIGNED");
5714 }
5715 break;
5716 case 16:
5717 outline1("LDD %s", _number );
5718 outline1("STD N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 2 );
5719 for( int i=(_environment->numberConfig.maxBytes - 4 ); i>0; i-=2 ) {
5720 outline0("LDD #0");
5721 outline1("STD N2STRINGNUMBER+%d", i );
5722 }
5723 if ( _signed ) {
5724 outline0("STA N2STRINGNUMBERSIGNED");
5725 outline1("BPL %spositive", label );
5726 char number[MAX_TEMPORARY_STORAGE];
5727 sprintf( number, "N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 2 );
5728 cpu_complement2_16bit( _environment, number, NULL);
5729 outhead1("%spositive", label );
5730 }
5731 outline0("LDD #0");
5732 outline0("STD N2STRINGNUMBER");
5733 if ( !_signed ) outline0("STA N2STRINGNUMBERSIGNED");
5734 break;
5735 case 8:
5736 outline1("LDB %s", _number );
5737 outline0("CLRA");
5738 outline1("STD N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 2);
5739 for( int i=(_environment->numberConfig.maxBytes - 4 ); i>0; i-=2 ) {
5740 outline0("LDD #0");
5741 outline1("STD N2STRINGNUMBER+%d", i );
5742 }
5743 if ( _signed && _bits == 8 ) {
5744 outline0("STB N2STRINGNUMBERSIGNED");
5745 outline1("BPL %spositive", label );
5746 char number[MAX_TEMPORARY_STORAGE];
5747 sprintf( number, "N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 3 );
5748 cpu_complement2_8bit( _environment, number, NULL);
5749 outhead1("%spositive", label );
5750 }
5751 outline0("CLRB");
5752 outline0("STD N2STRINGNUMBER");
5753 if ( !_signed ) outline0("STA N2STRINGNUMBERSIGNED");
5754 break;
5755 default:
5756 cpu_mem_move_direct_size( _environment, _number, "N2STRINGNUMBER", _bits >> 3 );
5757 outline1("LDB %s", _number );
5758 outline0("ANDB #$80" );
5759 outline0("STB N2STRINGNUMBERSIGNED");
5760 outline1("LBPL %spositive", label );
5761 cpu_complement2_nbit( _environment, "N2STRINGNUMBER", NULL, _bits );
5762 outhead1("%spositive", label );
5763 break;
5764 case 0:
5765 CRITICAL_DEBUG_UNSUPPORTED( _number, "unknown");
5766 }
5767
5768
5769 outline1("LDX %s", _string );
5770 outline1("LDA #$%2.2X", _bits );
5771 outline0("JSR N2STRING");
5772
5773 outline1("STA %s", _string_size);
5774
5775}
5776
5777void cpu_bits_to_string( Environment * _environment, char * _number, char * _string, char * _string_size, int _bits, char * _zero, char * _one ) {
5778
5779 deploy( bitsToString, src_hw_6309_bits_to_string_asm );
5780
5781 if ( _zero ) {
5782 outline1("LDA %s", _zero);
5783 } else {
5784 outline0("LDA #'0'" );
5785 }
5786 outline0("STA BINSTRO0+1" );
5787
5788 if ( _one ) {
5789 outline1("LDA %s", _one);
5790 } else {
5791 outline0("LDA #'1'" );
5792 }
5793 outline0("STA BINSTRO1+1" );
5794
5795 switch( _bits ) {
5796 case 32:
5797 outline1("LDD %s", _number );
5798 outline0("STD <MATHPTR0" );
5799 outline1("LDD %s", address_displacement(_environment, _number, "2") );
5800 outline0("STD <MATHPTR2" );
5801 outline0("LDB #32" );
5802 outline1("STB %s", _string_size );
5803 break;
5804 case 16:
5805 outline0("LDD #0" );
5806 outline0("STD <MATHPTR0" );
5807 outline1("LDD %s", _number );
5808 outline0("STD <MATHPTR2" );
5809 outline0("LDB #16" );
5810 outline1("STB %s", _string_size );
5811 break;
5812 case 8:
5813 outline0("LDD #0" );
5814 outline0("STD <MATHPTR0" );
5815 outline0("LDA #0" );
5816 outline0("STA <MATHPTR2" );
5817 outline1("LDA %s", _number );
5818 outline0("STA <MATHPTR3" );
5819 outline0("LDB #8" );
5820 outline1("STB %s", _string_size );
5821 break;
5822 }
5823
5824 outline1("LDB #$%2.2x", (unsigned char)(_bits&0xff) );
5825 outline0("JSR BINSTR");
5826
5827 cpu_mem_move_direct_indirect_size( _environment, "BINSTRBUF", _string, _bits );
5828
5829}
5830
5831void cpu_hex_to_string_calc_string( Environment * _environment, char * _size, int _separator, char * _string_size ) {
5832
5834
5835 inline( cpu_hex_to_string )
5836
5837 embedded( cpu_hex_to_string, src_hw_6309_cpu_hex_to_string_asm );
5838
5839 outline1("LDA #$%2.2x", _separator?1:0 );
5840 outline1("LDB %s", _size );
5841 outline0("JSR H2STRINGCALCSIZE" );
5842 outline1("STB %s", _string_size );
5843
5844 done()
5845
5846}
5847
5848void cpu_hex_to_string_calc_string_size( Environment * _environment, int _size, int _separator, char * _string_size ) {
5849
5851
5852 inline( cpu_hex_to_string )
5853
5854 embedded( cpu_hex_to_string, src_hw_6309_cpu_hex_to_string_asm );
5855
5856 outline1("LDA #$%2.2x", _separator?1:0 );
5857 outline1("LDB #$%2.2x", (unsigned char)( _size & 0xff ) );
5858 outline0("JSR H2STRINGCALCSIZE" );
5859 outline1("STB %s", _string_size );
5860
5861 done()
5862
5863}
5864
5865void cpu_hex_to_string( Environment * _environment, char * _number, char * _string, char * _size, int _separator ) {
5866
5868
5869 inline( cpu_hex_to_string )
5870
5871 embedded( cpu_hex_to_string, src_hw_6309_cpu_hex_to_string_asm );
5872
5873 outline1("LDA #$%2.2x", (unsigned char)( _separator * 3 ) );
5874 outline1("LDB %s", _size );
5875 outline1("LDX %s", _number );
5876 outline1("LDY %s", _string );
5877
5878 outline0("JSR H2STRING" );
5879
5880 done()
5881
5882}
5883
5884void cpu_dsdefine( Environment * _environment, char * _string, char * _index ) {
5885
5886 deploy_preferred( duff, src_hw_6309_duff_asm );
5887 deploy( dstring, src_hw_6309_dstring_asm );
5888
5889 outline1( "LDY #%s", _string );
5890 outline0( "JSR DSDEFINE" );
5891 outline1( "STB %s", _index );
5892
5893}
5894
5895void cpu_dsalloc( Environment * _environment, char * _size, char * _index ) {
5896
5897 deploy_preferred( duff, src_hw_6309_duff_asm );
5898 deploy( dstring, src_hw_6309_dstring_asm );
5899
5900 outline1( "LDA %s", _size );
5901 outline0( "JSR DSALLOC" );
5902 outline1( "STB %s", _index );
5903
5904}
5905
5906void cpu_dsalloc_size( Environment * _environment, int _size, char * _index ) {
5907
5908 deploy_preferred( duff, src_hw_6309_duff_asm );
5909 deploy( dstring, src_hw_6309_dstring_asm );
5910
5911 outline1( "LDA #$%2.2x", _size );
5912 outline0( "JSR DSALLOC" );
5913 outline1( "STB %s", _index );
5914
5915}
5916
5917void cpu_dsfree( Environment * _environment, char * _index ) {
5918
5919 deploy_preferred( duff, src_hw_6309_duff_asm );
5920 deploy( dstring, src_hw_6309_dstring_asm );
5921
5922 outline1( "LDB %s", _index );
5923 outline0( "JSR DSFREE" );
5924
5925}
5926
5927void cpu_dswrite( Environment * _environment, char * _index ) {
5928
5929 deploy_preferred( duff, src_hw_6309_duff_asm );
5930 deploy( dstring, src_hw_6309_dstring_asm );
5931
5932 outline1( "LDB %s", _index );
5933 outline0( "JSR DSWRITE" );
5934
5935}
5936
5937void cpu_dsresize( Environment * _environment, char * _index, char * _resize ) {
5938
5939 deploy_preferred( duff, src_hw_6309_duff_asm );
5940 deploy( dstring, src_hw_6309_dstring_asm );
5941
5942 outline1( "LDB %s", _index );
5943 outline1( "LDA %s", _resize );
5944 outline0( "JSR DSRESIZE" );
5945
5946}
5947
5948void cpu_dsresize_size( Environment * _environment, char * _index, int _resize ) {
5949
5950 deploy_preferred( duff, src_hw_6309_duff_asm );
5951 deploy( dstring, src_hw_6309_dstring_asm );
5952
5953 outline1( "LDB %s", _index );
5954 outline1( "LDA #$%2.2X", _resize );
5955 outline0( "JSR DSRESIZE" );
5956
5957}
5958
5959void cpu_dsgc( Environment * _environment ) {
5960
5961 deploy_preferred( duff, src_hw_6309_duff_asm );
5962 deploy( dstring, src_hw_6309_dstring_asm );
5963
5964 outline0( "JSR DSGC" );
5965
5966}
5967
5968void cpu_dsinit( Environment * _environment ) {
5969
5970 deploy_preferred( duff, src_hw_6309_duff_asm );
5971 deploy( dstring, src_hw_6309_dstring_asm );
5972
5973 outline0( "JSR DSINIT" );
5974
5975}
5976
5977void cpu_dsdescriptor( Environment * _environment, char * _index, char * _address, char * _size ) {
5978
5979 deploy_preferred( duff, src_hw_6309_duff_asm );
5980 deploy( dstring,src_hw_6309_dstring_asm );
5981
5982 if ( _address || _size ) {
5983 outline1( "LDB %s", _index );
5984 outline0( "JSR DSDESCRIPTOR" );
5985 if ( _address ) {
5986 outline0( "LDD 1, X" );
5987 outline1( "STD %s", _address );
5988 }
5989 if ( _size ) {
5990 outline0( "LDA , X" );
5991 outline1( "STA %s", _size );
5992 }
5993 }
5994
5995}
5996
5997void cpu_dsassign( Environment * _environment, char * _original, char * _copy ) {
5998
5999 deploy_preferred( duff, src_hw_6309_duff_asm );
6000 deploy( dstring,src_hw_6309_dstring_asm );
6001
6002 outline1( "LDA %s", _original );
6003 outline1( "LDB %s", _copy );
6004 outline0( "JSR DSASSIGN" );
6005 outline1( "STB %s", _copy );
6006
6007}
6008
6009void cpu_dsassign_string( Environment * _environment, char * _string, char * _copy ) {
6010
6011 deploy_preferred( duff, src_hw_6309_duff_asm );
6012 deploy( dstring, src_hw_6309_dstring_asm );
6013
6014 outline1( "LDY #%s", _string );
6015 outline1( "LDB %s", _copy );
6016 outline0( "JSR DSASSIGNSTR" );
6017 outline1( "STB %s", _copy );
6018
6019}
6020
6021void cpu_store_8bit_with_offset( Environment * _environment, char *_destination, int _value, int _offset ) {
6022
6023 outline1("LDX %s", _destination);
6024 outline1("LDB #$%2.2x", (unsigned char)(_value & 0xff));
6025 outline1("STB $%2.2x,X", _offset);
6026
6027}
6028
6029void cpu_store_8bit_with_offset2( Environment * _environment, char * _source, char * _offset, int _value ) {
6030
6032
6034
6035 outline1("LDX #%s", _source);
6036 outline1("LDB %s", _offset);
6037 outline0("ABX");
6038 outline1("LDA #$%2.2x", _value);
6039 outline0("STA ,X");
6040
6042
6043}
6044
6045void cpu_complement2_8bit( Environment * _environment, char * _source, char * _destination ) {
6046
6047 if ( _destination ) {
6048 outline1( "LDB %s", _source );
6049 outline0( "NEGB");
6050 outline1( "STB %s", _destination );
6051 } else {
6052 outline1( "NEG %s", _source );
6053 }
6054
6055}
6056
6057void cpu_complement2_16bit( Environment * _environment, char * _source, char * _destination ) {
6058
6059 outline1( "LDD %s", _source );
6060 outline0( "NEGD" );
6061 outline0( "SBCA #0" );
6062 if ( _destination ) {
6063 outline1( "STD %s", _destination );
6064 } else {
6065 outline1( "STD %s", _source );
6066 }
6067
6068}
6069
6070void cpu_complement2_32bit( Environment * _environment, char * _source, char * _destination ) {
6071 char *out = _destination ?_destination : _source;
6072
6074
6075 outline1( "LDD %s", _source );
6076 outline0( "COMA");
6077 outline0( "COMB");
6078 outline1( "STD %s", out );
6079
6080 outline1( "LDD %s", address_displacement(_environment, _source, "2") );
6081 outline0( "NEGD" );
6082 outline0( "SBCA #0" );
6083 outline1( "STD %s", address_displacement(_environment, out, "2") );
6084
6085 outline1( "BNE %s", label);
6086 outline1( "INC %s", address_displacement(_environment, out, "1"));
6087 outline1( "BNE %s", label);
6088 outline1( "INC %s", out);
6089 outhead1( "%s", label);
6090
6091}
6092
6093void cpu_complement2_nbit( Environment * _environment, char * _source, char * _destination, int _bits ) {
6094
6095 for( int i=0; i<(_bits>>3); ++i ) {
6096 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
6097 outline1( "LDA %s", address_displacement(_environment, _source, offset) );
6098 outline0( "COMA" );
6099 if ( _destination ) {
6100 outline1( "STA %s", address_displacement(_environment, _destination, offset) );
6101 } else {
6102 outline1( "STA %s", address_displacement(_environment, _source, offset) );
6103 }
6104 }
6105 if ( _destination ) {
6106 cpu_inc_nbit( _environment, _destination, _bits );
6107 } else {
6108 cpu_inc_nbit( _environment, _source, _bits );
6109 }
6110
6111}
6112
6113void cpu_sqroot( Environment * _environment, char * _number, char * _result ) {
6114
6115 deploy( sqr, src_hw_6309_sqr_asm );
6116
6117 outline1("LDD %s", _number );
6118 outline0("STA <Numberh" );
6119 outline0("STB <Numberl" );
6120
6121 outline0("JSR SQROOT" );
6122
6123 outline0("LDB <Root" );
6124 outline1("STB %s", _result );
6125
6126}
6127
6128void cpu_dstring_vars( Environment * _environment ) {
6129
6130 int count = _environment->dstring.count == 0 ? DSTRING_DEFAULT_COUNT : _environment->dstring.count;
6131 int space = _environment->dstring.space == 0 ? DSTRING_DEFAULT_SPACE : _environment->dstring.space;
6132
6133 outhead1("stringscount equ %d", count );
6134 outhead1("stringsspace equ %d", (space-1) );
6135 outhead0("MAXSTRINGS equ stringscount" );
6136 outhead0("DESCRIPTORS rzb stringscount*4");
6137 outhead0("WORKING rzb stringsspace" );
6138 outhead0("TEMPORARY rzb stringsspace" );
6139 outhead0("FREE_STRING fdb stringsspace" );
6140
6141}
6142
6143void cpu_protothread_vars( Environment * _environment ) {
6144
6145 int count = _environment->protothreadConfig.count;
6146
6147 outhead1("PROTOTHREADLC rzb %d", count );
6148 outhead1("PROTOTHREADST rzb %d", count );
6149 outhead0("PROTOTHREADCT fcb 0" );
6150 outhead0("PROTOTHREADLOOP");
6151
6152 for( int i=0; i<count; ++i ) {
6153 outline1("LDB #%d-1", i+1 ); /* prevents optimizer changing code length */
6154 outline0("STB PROTOTHREADCT" );
6155 outline0("JSR PROTOTHREADVOID" );
6156 }
6157
6158 outline0("RTS" );
6159
6160}
6161
6162void cpu_protothread_loop( Environment * _environment ) {
6163
6164 deploy_with_vars( protothread, src_hw_6309_protothread_asm, cpu_protothread_vars );
6165
6166 outline0("JSR PROTOTHREADLOOP" );
6167
6168}
6169
6170void cpu_protothread_register_at( Environment * _environment, char * _index, char * _label ) {
6171
6172 deploy_with_vars( protothread, src_hw_6309_protothread_asm, cpu_protothread_vars );
6173
6174 outline1("LDY #%s", _label );
6175 outline1("LDB %s", _index );
6176
6177 outline0("JSR PROTOTHREADREGAT" );
6178
6179}
6180
6181void cpu_protothread_register( Environment * _environment, char * _label, char * _index ) {
6182
6183 deploy_with_vars( protothread, src_hw_6309_protothread_asm, cpu_protothread_vars );
6184
6185 outline1("LDY #%s", _label );
6186
6187 outline0("JSR PROTOTHREADREG" );
6188
6189 outline1("STB %s", _index );
6190
6191}
6192
6193void cpu_protothread_unregister( Environment * _environment, char * _index ) {
6194
6195 deploy_with_vars( protothread, src_hw_6309_protothread_asm, cpu_protothread_vars );
6196
6197 outline1("LDB %s", _index );
6198
6199 outline0("JSR PROTOTHREADUNREG" );
6200
6201}
6202
6203void cpu_protothread_save( Environment * _environment, char * _index, int _step ) {
6204
6205 deploy_with_vars( protothread, src_hw_6309_protothread_asm, cpu_protothread_vars );
6206
6207 outline1("LDB %s", _index );
6208 outline1("LDA #$%2.2x", _step );
6209
6210 outline0("JSR PROTOTHREADSAVE" );
6211
6212}
6213
6214void cpu_protothread_restore( Environment * _environment, char * _index, char * _step ) {
6215
6216 deploy_with_vars( protothread, src_hw_6309_protothread_asm, cpu_protothread_vars );
6217
6218 outline1("LDB %s", _index );
6219
6220 outline0("JSR PROTOTHREADRESTORE" );
6221
6222 outline1("STA %s", _step );
6223
6224}
6225
6226void cpu_protothread_set_state( Environment * _environment, char * _index, int _state ) {
6227
6228 deploy_with_vars( protothread, src_hw_6309_protothread_asm, cpu_protothread_vars );
6229
6230 outline1("LDB %s", _index );
6231 outline1("LDA #$%2.2x", _state );
6232
6233 outline0("JSR PROTOTHREADSETSTATE" );
6234
6235}
6236
6237void cpu_protothread_get_state( Environment * _environment, char * _index, char * _state ) {
6238
6239 deploy_with_vars( protothread, src_hw_6309_protothread_asm, cpu_protothread_vars );
6240
6241 outline1("LDB %s", _index );
6242
6243 outline0("JSR PROTOTHREADGETSTATE" );
6244
6245 outline1("STA %s", _state );
6246
6247}
6248
6249void cpu_protothread_current( Environment * _environment, char * _current ) {
6250
6251 deploy_with_vars( protothread, src_hw_6309_protothread_asm, cpu_protothread_vars );
6252
6253 outline0("LDB PROTOTHREADCT" );
6254 outline1("STB %s", _current );
6255
6256}
6257
6258void cpu_protothread_get_address( Environment * _environment, char * _index, char * _address ) {
6259
6260 deploy_with_vars( protothread, src_hw_6309_protothread_asm, cpu_protothread_vars );
6261
6262 outline1("LDB %s", _index );
6263
6264 outline0("JSR PROTOTHREADGETADDRESS" );
6265
6266 outline1("STY %s", _address );
6267
6268}
6269
6270void cpu_set_callback( Environment * _environment, char * _callback, char * _label ) {
6271
6272 outline1("LDY #%s", _label );
6273 outline1("LDU #%s", _callback );
6274 outline0("LEAU 1, U" );
6275 outline0("STY ,U" );
6276
6277}
6278
6279void cpu_msc1_uncompress_direct_direct( Environment * _environment, char * _input, char * _output ) {
6280
6282
6283 if ( ! _environment->deployed.msc1 ) {
6284
6285 inline( cpu_msc1_uncompress )
6286
6287 embedded( cpu_msc1_uncompress, src_hw_6309_msc1_asm );
6288
6289 outline1("LDX #%s", _input);
6290 outline1("LDY #%s", _output);
6291 outline0("JSR MSC1UNCOMPRESS");
6292
6293 done()
6294
6295 } else {
6296
6297 outline1("LDX #%s", _input);
6298 outline1("LDY #%s", _output);
6299 outline0("JSR MSC1UNCOMPRESS");
6300
6301 }
6302
6303}
6304
6305void cpu_msc1_uncompress_direct_indirect( Environment * _environment, char * _input, char * _output ) {
6306
6308
6309 inline( cpu_msc1_uncompress )
6310
6311 embedded( cpu_msc1_uncompress, src_hw_6309_msc1_asm );
6312
6313 outline1("LDX #%s", _input);
6314 outline1("LDY %s", _output);
6315 outline0("JSR MSC1UNCOMPRESS");
6316
6317 done()
6318
6319}
6320
6321void cpu_msc1_uncompress_indirect_direct( Environment * _environment, char * _input, char * _output ) {
6322
6324
6325 inline( cpu_msc1_uncompress )
6326
6327 embedded( cpu_msc1_uncompress, src_hw_6309_msc1_asm );
6328
6329 outline1("LDX %s", _input);
6330 outline1("LDY #%s", _output);
6331 outline0("JSR MSC1UNCOMPRESS");
6332
6333 done()
6334
6335}
6336
6337void cpu_msc1_uncompress_indirect_indirect( Environment * _environment, char * _input, char * _output ) {
6338
6340
6341 inline( cpu_msc1_uncompress )
6342
6343 embedded( cpu_msc1_uncompress, src_hw_6309_msc1_asm );
6344
6345 outline1("LDX %s", _input);
6346 outline1("LDY %s", _output);
6347 outline0("JSR MSC1UNCOMPRESS");
6348
6349 done()
6350
6351}
6352
6353void cpu_out( Environment * _environment, char * _port, char * _value ) {
6354
6355}
6356
6357void cpu_in( Environment * _environment, char * _port, char * _value ) {
6358
6359}
6360
6361void cpu_out_direct( Environment * _environment, char * _port, char * _value ) {
6362
6363}
6364
6365void cpu_in_direct( Environment * _environment, char * _port, char * _value ) {
6366
6367}
6368
6369
6370void cpu_string_sub( Environment * _environment, char * _source, char * _source_size, char * _pattern, char * _pattern_size, char * _destination, char * _destination_size ) {
6371
6373
6374 inline( cpu_string_sub )
6375
6376 embedded( cpu_string_sub, src_hw_6309_cpu_string_sub_asm );
6377
6378 outline1("LDY %s", _source);
6379 outline1("LDA %s", _source_size);
6380 outline0("STA <MATHPTR0");
6381 outline1("LDX %s", _pattern);
6382 outline1("LDA %s", _pattern_size);
6383 outline0("STA <MATHPTR1");
6384 outline1("LDU %s", _destination);
6385
6386 outline0("JSR CPUSTRINGSUB");
6387
6388 outline0("LDA <MATHPTR2");
6389 outline1("STA %s", _destination_size);
6390
6391 done()
6392}
6393
6394static char cpu_BLIT_REGISTER[][9] = {
6395 "BLITR0",
6396 "BLITR1",
6397 "BLITR2",
6398 "BLITR3"
6399};
6400
6401#define cpu_BLIT_REGISTER_COUNT ( sizeof( cpu_BLIT_REGISTER ) / 9 )
6402
6403void cpu_blit_initialize( Environment * _environment ) {
6404
6405 _environment->blit.freeRegisters = 0;
6406 _environment->blit.usedMemory = 0;
6407
6408}
6409
6410void cpu_blit_finalize( Environment * _environment ) {
6411
6412 _environment->blit.freeRegisters = 0;
6413 _environment->blit.usedMemory = 0;
6414
6415}
6416
6417char * cpu_blit_register_name( Environment * _environment, int _register ) {
6418
6419 if ( _register < cpu_BLIT_REGISTER_COUNT ) {
6420 return &cpu_BLIT_REGISTER[_register][0];
6421 } else {
6422 return &cpu_BLIT_REGISTER[ (_register & 0xff00) >> 8][0];
6423 }
6424}
6425
6427
6428 int reg = 0;
6429
6430 for( reg = 0; reg < cpu_BLIT_REGISTER_COUNT; ++reg ) {
6431 int registerMask = ( 0x01 << reg );
6432 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
6433 if ( ! isRegisterUsed ) {
6434 _environment->blit.freeRegisters |= registerMask;
6435 return reg;
6436 }
6437 }
6438
6439 int location = _environment->blit.usedMemory++;
6440
6441 if ( location > 0xff ) {
6443 }
6444
6445 for( reg = 0; reg < cpu_BLIT_REGISTER_COUNT; ++reg ) {
6446 int registerMask = ( 0x10 << reg );
6447 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
6448 if ( ! isRegisterUsed ) {
6449 outline1( "LDA %s", &cpu_BLIT_REGISTER[reg][0] );
6450 outline2( "STA %sbs+$%2.2x", _environment->blit.realName, location );
6451 _environment->blit.freeRegisters |= registerMask;
6452 return ( ( (reg+1) << 8 ) | location );
6453 }
6454 }
6455
6457
6458}
6459
6460void cpu_blit_free_register( Environment * _environment, int _register ) {
6461
6462 // printf( "z80_blit_free_register($%4.4x)\n", _register );
6463
6464 int location = _register & 0xff;
6465 int reg;
6466
6467 if ( _register < cpu_BLIT_REGISTER_COUNT ) {
6468 int registerMask = ( 0x01 << _register );
6469 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
6470 if ( isRegisterUsed ) {
6471 _environment->blit.freeRegisters &= ~registerMask;
6472 return;
6473 } else {
6474 CRITICAL_BLIT_INVALID_FREE_REGISTER( _environment->blit.name, _register );
6475 }
6476 } else {
6477 int registerMask = 0x10 << ( ( ( _register >> 8 ) & 0xff ) - 1 );
6478 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
6479 if ( isRegisterUsed ) {
6480 outline2( "LDA (%sbs+$%2.2x)", _environment->blit.realName, location );
6481 outline1( "LDA %s", &cpu_BLIT_REGISTER[reg][0] );
6482 _environment->blit.freeRegisters &= ~registerMask;
6483 return;
6484 }
6485 }
6486
6487 CRITICAL_BLIT_INVALID_FREE_REGISTER( _environment->blit.name, _register );
6488
6489}
6490
6499void cpu_store_nbit( Environment * _environment, char *_destination, int _n, int _value[] ) {
6500
6501 int n = _n >> 3;
6502 int i = 0;
6503 while( _n ) {
6504 char destinationAddress[MAX_TEMPORARY_STORAGE]; sprintf( destinationAddress, "%s+%d", _destination, i*4 );
6505 if ( _n <= 32 ) {
6506 switch( _n ) {
6507 case 1: case 2: case 3: case 4:
6508 case 5: case 6: case 7: case 8:
6509 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4)] & (0xff>>(8-_n)) ) );
6510 i+=1;
6511 break;
6512 case 9: case 10: case 11: case 12:
6513 case 13: case 14: case 15: case 16:
6514 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4)] & (0xff>>(16-_n)) ) );
6515 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6516 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+1)] & (0xff) ) );
6517 break;
6518 case 17: case 18: case 19: case 20:
6519 case 21: case 22: case 23: case 24:
6520 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4)] & (0xff>>(24-_n)) ) );
6521 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6522 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+1)] & (0xff) ) );
6523 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6524 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+2)] & (0xff) ) );
6525 break;
6526 case 25: case 26: case 27: case 28:
6527 case 29: case 30: case 31: case 32:
6528 default:
6529 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4)] & (0xff>>(32-_n)) ) );
6530 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6531 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+1)] & (0xff) ) );
6532 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6533 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+2)] & (0xff) ) );
6534 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
6535 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+3)] & (0xff) ) );
6536 break;
6537 }
6538 _n = 0;
6539 } else {
6540 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4)] & (0xff) ) );
6541 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6542 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+1)] & (0xff) ) );
6543 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6544 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+2)] & (0xff) ) );
6545 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
6546 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+3)] & (0xff) ) );
6547 _n -= 32;
6548 }
6549 ++i;
6550 }
6551
6552
6553}
6554
6563void cpu_move_nbit( Environment * _environment, int _n, char * _source, char *_destination ) {
6564
6565 int i = 0;
6566 while( _n ) {
6567 char sourceAddress[MAX_TEMPORARY_STORAGE]; sprintf( sourceAddress, "%s+%d", _source, i*4 );
6568 char destinationAddress[MAX_TEMPORARY_STORAGE]; sprintf( destinationAddress, "%s+%d", _destination, i*4 );
6569 if ( _n <= 32 ) {
6570 switch( _n ) {
6571 case 1: case 2: case 3: case 4:
6572 case 5: case 6: case 7: case 8:
6573 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6574 break;
6575 case 9: case 10: case 11: case 12:
6576 case 13: case 14: case 15: case 16:
6577 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6578 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
6579 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6580 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6581 break;
6582 case 17: case 18: case 19: case 20:
6583 case 21: case 22: case 23: case 24:
6584 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6585 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
6586 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6587 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6588 sprintf( sourceAddress, "%s+%d", _source, i*4+2 );
6589 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6590 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6591 break;
6592 case 25: case 26: case 27: case 28:
6593 case 29: case 30: case 31: case 32:
6594 default:
6595 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6596 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
6597 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6598 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6599 sprintf( sourceAddress, "%s+%d", _source, i*4+2 );
6600 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6601 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6602 sprintf( sourceAddress, "%s+%d", _source, i*4+3 );
6603 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
6604 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6605 break;
6606 }
6607 _n = 0;
6608 } else {
6609 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6610 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
6611 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6612 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6613 sprintf( sourceAddress, "%s+%d", _source, i*4+2 );
6614 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6615 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6616 sprintf( sourceAddress, "%s+%d", _source, i*4+3 );
6617 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
6618 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6619 _n -= 32;
6620 }
6621 ++i;
6622 }
6623
6624}
6625
6626void cpu_move_nbit_indirect( Environment * _environment, int _n, char *_source, char * _value ) {
6627
6628 outline1("LDX %s", _value);
6629
6630 char step[MAX_TEMPORARY_STORAGE];
6631 char step1[MAX_TEMPORARY_STORAGE];
6632 char step2[MAX_TEMPORARY_STORAGE];
6633 char step3[MAX_TEMPORARY_STORAGE];
6634
6635 int stepIndex = 0;
6636 while( _n ) {
6637 sprintf( step, "%d", stepIndex );
6638 sprintf( step1, "%d", stepIndex+1 );
6639 sprintf( step2, "%d", stepIndex+2 );
6640 sprintf( step3, "%d", stepIndex+3 );
6641 if ( _n >= 32 ) {
6642 outline1("LDD %s", address_displacement(_environment, _source, step) );
6643 outline1("STD %d,X", stepIndex);
6644 outline1("LDD %s", address_displacement(_environment, _source, step2) );
6645 outline1("STD %d,X", stepIndex+2);
6646 stepIndex += 4;
6647 _n -= 32;
6648 } else {
6649 switch( _n ) {
6650 case 32: case 31: case 30: case 29:
6651 case 28: case 27: case 26: case 25:
6652 outline1("LDD %s", address_displacement(_environment, _source, step) );
6653 outline1("STD %d,X", stepIndex);
6654 outline1("LDD %s", address_displacement(_environment, _source, step2) );
6655 outline1("STD %d,X", stepIndex+2);
6656 break;
6657 case 24: case 23: case 22: case 21:
6658 case 20: case 19: case 18: case 17:
6659 outline1("LDD %s", address_displacement(_environment, _source, step) );
6660 outline1("STD %d,X", stepIndex);
6661 outline1("LDA %s", address_displacement(_environment, _source, step2) );
6662 outline1("STA %d,X", stepIndex+2);
6663 break;
6664 case 16: case 15: case 14: case 13:
6665 case 12: case 11: case 10: case 9:
6666 outline1("LDD %s", address_displacement(_environment, _source, step) );
6667 outline1("STD %d,X", stepIndex);
6668 break;
6669 case 8: case 7: case 6: case 5:
6670 case 4: case 3: case 2: case 1:
6671 outline1("LDA %s", address_displacement(_environment, _source, step) );
6672 outline1("STA %d,X", stepIndex);
6673 break;
6674 }
6675 _n = 0;
6676 }
6677 }
6678
6679}
6680
6681void cpu_move_nbit_indirect2( Environment * _environment, int _n, char * _value, char *_source ) {
6682
6683 outline1("LDX %s", _value);
6684
6685 char step[MAX_TEMPORARY_STORAGE];
6686 char step1[MAX_TEMPORARY_STORAGE];
6687 char step2[MAX_TEMPORARY_STORAGE];
6688 char step3[MAX_TEMPORARY_STORAGE];
6689
6690 int stepIndex = 0;
6691 while( _n ) {
6692 sprintf( step, "%d", stepIndex );
6693 sprintf( step1, "%d", stepIndex+1 );
6694 sprintf( step2, "%d", stepIndex+2 );
6695 sprintf( step3, "%d", stepIndex+3 );
6696 if ( _n >= 32 ) {
6697 outline1("LDD %d,X", stepIndex);
6698 outline1("STD %s", address_displacement(_environment, _source, step) );
6699 outline1("LDD %d,X", stepIndex+2);
6700 outline1("STD %s", address_displacement(_environment, _source, step2) );
6701 stepIndex += 4;
6702 _n -= 32;
6703 } else {
6704 switch( _n ) {
6705 case 32: case 31: case 30: case 29:
6706 case 28: case 27: case 26: case 25:
6707 outline1("LDD %d,X", stepIndex);
6708 outline1("STD %s", address_displacement(_environment, _source, step) );
6709 outline1("LDD %d,X", stepIndex+2);
6710 outline1("STD %s", address_displacement(_environment, _source, step2) );
6711 break;
6712 case 24: case 23: case 22: case 21:
6713 case 20: case 19: case 18: case 17:
6714 outline1("LDD %d,X", stepIndex);
6715 outline1("STD %s", address_displacement(_environment, _source, step) );
6716 outline1("LDA %d,X", stepIndex+2);
6717 outline1("STA %s", address_displacement(_environment, _source, step2) );
6718 break;
6719 case 16: case 15: case 14: case 13:
6720 case 12: case 11: case 10: case 9:
6721 outline1("LDD %d,X", stepIndex);
6722 outline1("STD %s", address_displacement(_environment, _source, step) );
6723 break;
6724 case 8: case 7: case 6: case 5:
6725 case 4: case 3: case 2: case 1:
6726 outline1("LDA %d,X", stepIndex);
6727 outline1("STA %s", address_displacement(_environment, _source, step) );
6728 break;
6729 }
6730 _n = 0;
6731 }
6732 }
6733
6734}
6735
6736
6737
6738//
6739// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
6740// SINGLE (40) eeeeeeee smmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
6741//
6742
6743void cpu_float_fast_from_double_to_int_array( Environment * _environment, double _value, int _result[] ) {
6744 cpu_float_single_from_double_to_int_array( _environment, _value, _result );
6745}
6746
6747void cpu_float_single_from_double_to_int_array( Environment * _environment, double _value, int _result[] ) {
6748
6749 double value = 0.0;
6750 double integral = 0.0;
6751 double fractional = 0.0;
6752 int sign = 0;
6753 int left = 0;
6754 int right[4];
6755 int steps = 0;
6756 int exp = 0;
6757 int mantissa_bits = 31;
6758
6759 // printf("value = %f\n", _value );
6760
6761 memset( &right[0], 0, sizeof( int ) * 4 );
6762
6763 // Step 1: Determine Sign
6764 // If the number is positive, then the sign bit will be 0. If the number is negative, then the sign bit
6765 // will be 1. For the number zero, both positive and negative zero are possible, and these are considered
6766 // different values (a quirk of using sign bits).
6767
6768 if ( _value >= 0 ) {
6769 sign = 0;
6770 } else {
6771 sign = 1;
6772 }
6773
6774 value = fabs( _value );
6775
6776 // Step 2: Convert the Integral Portion to Unsigned Binary
6777 // Convert the integral portion of the floating-point value to unsigned binary (not two's complement).
6778 // The integral portion is the part of the number before the decimal point. For example, if the
6779 // number to convert is -0.75, then 0 is the integral portion, and it's unsigned binary representation
6780 // is simply 0. As another example, if the number to convert is 127.99, then the integral portion would
6781 // be 127, and it's unsigned binary representation is 1111111.
6782
6783 fractional = modf(value, &integral);
6784
6785 left = (unsigned int) integral;
6786
6787 // printf(" integral = %f (%d)\n", integral, left );
6788
6789 // Step 3: Convert the Fractional Portion to Binary
6790 // The fractional portion of the number must also be converted to binary, though the conversion process
6791 // is much different from what you're used to. The algorithm you'll used is based on performing repeated
6792 // multiplications by 2, and then checking if the result is >= 1.0. If the result is >= 1.0, then a 1 is
6793 // recorded for the binary fractional component, and the leading 1 is chopped of the result. If the
6794 // result is < 1.0, then a 0 is recorded for the binary fractional component, and the result is kept
6795 // as-is. The recorded builds are built-up left-to-right. The result keeps getting chained along in this
6796 // way until one of the following is true:
6797 // - The result is exactly 1.0
6798 // - 23 iterations of this process have occurred; i.e. the final converted binary value holds 23 bits
6799 // With the first possible terminating condition (the result is exactly 1.0), this means that the fractional
6800 // component has been represented without any loss of precision. With the second possible terminating
6801 // condition (23 iterations have passed), this means that we ran out of bits in the final result, which
6802 // can never exceed 23. In this case, precision loss occurs (an unfortunate consequence of using a finite
6803 // number of bits).
6804
6805 while( ( fractional != 1.0 ) && ( steps < mantissa_bits ) ) {
6806
6807 // printf(" > %f %d %2.2x %2.2x %2.2x %2.2x\n", fractional, steps, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2], (unsigned char) right[3] );
6808
6809 right[3] = right[3] << 1;
6810 right[2] = right[2] << 1;
6811 right[1] = right[1] << 1;
6812 right[0] = right[0] << 1;
6813 if ( ( right[3] & 0x100 ) ) {
6814 right[2] = right[2] | 0x1;
6815 }
6816 if ( ( right[2] & 0x100 ) ) {
6817 right[1] = right[1] | 0x1;
6818 }
6819 if ( ( right[1] & 0x100 ) ) {
6820 right[0] = right[0] | 0x1;
6821 }
6822 right[3] = right[3] & 0xff;
6823 right[2] = right[2] & 0xff;
6824 right[1] = right[1] & 0xff;
6825 right[0] = right[0] & 0x7f;
6826
6827 fractional = fractional * 2;
6828
6829 if ( fractional >= 1.0 ) {
6830 right[3] |= 1;
6831 fractional = modf(fractional, &integral);
6832 }
6833
6834 ++steps;
6835
6836 }
6837
6838 // Step 4: Normalize the Value via Adjusting the Exponent
6839 // A trick to encode an extra bit is to make it so that the binary scientific representation is always
6840 // of the form 1.XXXX * 2YYYY. That is, a 1 always leads, so there is no need to explicitly encode it.
6841 // In order to encode this properly, we need to move the decimal point to a position where it is
6842 // immediately after the first 1, and then record exactly how we moved it. To see this in action, consider
6843 // again the example of 0.75, which is encoded in binary as such (not IEEE-754 notation):
6844 // 0.11
6845 // 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:
6846 // 1.1
6847 // Most importantly, we need to record that we moved the decimal point by one position to the right.
6848 // Moves to the right result in negative exponents, and moves to the left result in positive exponents.
6849 // In this case, because we moved the decimal point one position to the right, the recorded exponent should be -1.
6850 // As another example, consider the following binary floating point representation (again, not IEEE-754):
6851 // 1111111.11100
6852 // 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:
6853 // 1.11111111100
6854 // Because this moves six positions to the left, the recorded exponent should be 6.
6855
6856 int mantissa_high_bit = 0x80000000 >> ( 32 - mantissa_bits);
6857 int mantissa_mask = 0xffffffff >> ( 32 - mantissa_bits);
6858
6859 if ( left == 0 ) {
6860
6861 if ( value != 0 ) {
6862
6863 while( left == 0 ) {
6864
6865 // printf("b) 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] );
6866
6867 if ( ! right[0] && ! right[1] && ! right[2] && ! right[3] ) {
6868 left = 0x1;
6869 }
6870
6871 if ( right[0] & 0x40 ) {
6872 left = 0x1;
6873 }
6874
6875 right[0] = right[0] << 1;
6876 right[1] = right[1] << 1;
6877 right[2] = right[2] << 1;
6878 right[3] = right[3] << 1;
6879 if ( ( right[1] & 0x100 )) {
6880 right[0] = right[0] | 0x1;
6881 }
6882 if ( ( right[2] & 0x100 )) {
6883 right[1] = right[1] | 0x1;
6884 }
6885 if ( ( right[3] & 0x100 )) {
6886 right[2] = right[2] | 0x1;
6887 }
6888 right[0] = right[0] & 0x7f;
6889 right[1] = right[1] & 0xff;
6890 right[2] = right[2] & 0xff;
6891 right[3] = right[3] & 0xff;
6892
6893 --exp;
6894 }
6895
6896 ++exp;
6897
6898 } else {
6899
6900 exp = -128;
6901
6902 }
6903
6904 // printf("exp = %d left = %2.2x right = %2.2x %2.2x %2.2x %2.2x\n", exp, (unsigned char) left, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2], (unsigned char) right[3] );
6905
6906 } else {
6907
6908 while( left ) {
6909
6910 // printf("a) left = %8.8x right = %2.2x %2.2x %2.2x %2.2x\n", left, (unsigned char) right[0], (unsigned char) right[1], (unsigned char) right[2], (unsigned char) right[3] );
6911
6912 if ( ( right[0] & 0x01 ) ) {
6913 right[1] = right[1] | 0x100;
6914 }
6915 if ( ( right[1] & 0x01 ) ) {
6916 right[2] = right[2] | 0x100;
6917 }
6918 if ( ( right[2] & 0x01 ) ) {
6919 right[3] = right[3] | 0x100;
6920 }
6921 right[0] = right[0] >> 1;
6922 right[1] = right[1] >> 1;
6923 right[2] = right[2] >> 1;
6924 right[3] = right[3] >> 1;
6925 if ( left & 0x1 ) {
6926 right[0] = right[0] | 0x40;
6927 }
6928 left = left >> 1;
6929 ++exp;
6930 }
6931 // --exp;
6932 left = 1;
6933 right[3] = right[3] << 1;
6934 right[2] = right[2] << 1;
6935 right[1] = right[1] << 1;
6936 right[0] = right[0] << 1;
6937 if ( right[3] & 0x100 ) {
6938 right[2] = right[2] | 0x01;
6939 }
6940 if ( right[2] & 0x100 ) {
6941 right[1] = right[1] | 0x01;
6942 }
6943 if ( right[1] & 0x100 ) {
6944 right[0] = right[0] | 0x01;
6945 }
6946 right[3] = right[3] & 0xff;
6947 right[2] = right[2] & 0xff;
6948 right[1] = right[1] & 0xff;
6949 right[0] = right[0] & 0x7f;
6950
6951 }
6952
6953 // Step 5: Add Bias to the Exponent
6954 // Internally, IEEE-754 values store their exponents in an unsigned representation, which may seem odd considering that
6955 // the exponent can be negative. Negative exponents are accomodated by using a biased representation, wherein a
6956 // pre-set number is always subtracted from the given unsigned number. Because the given unsigned number may be less
6957 // than this number, this allows for negative values to be effectively encoded without resorting to two's complement.
6958 // Specifically, for the binary32 representation, the number 127 will be subtracted from anything encoded in the
6959 // exponent field of the IEEE-754 number. As such, in this step, we need to add 127 to the normalized exponent value
6960 // from the previous step.
6961
6962 exp += 127;
6963
6964 // printf("exp = %2.2x\n", exp );
6965
6966 // Step 6: Convert the Biased Exponent to Unsigned Binary
6967 // The biased exponent value from the previous step must be converted into unsigned binary, using the usual process.
6968 // The result must be exactly 8 bits. It should not be possible to need more than 8 bits. If fewer than 8 bits are
6969 // needed in this conversion process, then leading zeros must be added to the front of the result to produce an
6970 // 8-bit value.
6971
6972 exp = exp & 0xff;
6973
6974 // printf("exp = %2.2x\n", exp );
6975
6976 // Step 7: Determine the Final Bits for the Mantissa
6977 // After step 4, there are a bunch of bits after the normalized decimal point. These bits will become the
6978 // mantissa (note that we ignore the bits to the left of the decimal point - normalization allows us to do this,
6979 // because it should always be just a 1). We need exactly 23 mantissa bits. If less than 23 mantissa bits follow the
6980 // decimal point, and the algorithm in step 3 ended with a result that wasn't 1.0, then follow the algorithm in step 3
6981 // until we can fill enough bits. If that's still not enough (eventually reaching 1.0 before we had enough bits, or
6982 // perhaps it had ended with 1.0 already), then the right side can be padded with zeros until 23 bits is reached.
6983 // If there are more than 23 bits after the decimal point in step 4, then these extra bits are simply cutoff from the
6984 // right. For example, if we had 26 bits to the right of the decimal point, then the last three would need to be cutoff
6985 // to get us to 23 bits. Note that in this case we will necessarily lose some precision.
6986
6987 if ( _value == 0.0f ) {
6988 exp = 0;
6989 }
6990
6991 // Step 8: Put it All Together
6992 // 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
6993 // step 6. The last 23 bits will be from the mantissa from step 7. The result will be a 32-bit number encoded in
6994 // IEEE-754 binary32 format, assuming no mistakes were made in the process.
6995
6996 // [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
6997 // SINGLE (32) seeeeeee emmmmmmm mmmmmmmm mmmmmmmm
6998
6999 _result[0] = exp & 0xff;
7000 _result[1] = ( sign << 7 ) | ( right[0] & 0x7f );
7001 _result[2] = ( right[1] );
7002 _result[3] = ( right[2] );
7003 _result[4] = ( right[3] );
7004
7005 int tmp;
7006
7007 tmp = _result[0];
7008 _result[0] = _result[4];
7009 _result[4] = tmp;
7010
7011 tmp = _result[1];
7012 _result[1] = _result[3];
7013 _result[3] = tmp;
7014
7015 // printf( "\n| %f = %2.2x %2.2x %2.2x %2.2x %2.2x\n\n", _value, _result[0], _result[1], _result[2], _result[3], _result[4] );
7016
7017}
7018
7019void cpu_float_fast_to_string( Environment * _environment, char * _x, char * _string, char * _string_size ) {
7020 cpu_float_single_to_string( _environment, _x, _string, _string_size );
7021}
7022
7023void cpu_float_single_to_string( Environment * _environment, char * _x, char * _string, char * _string_size ) {
7024
7026
7027 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7028
7029 outline0( "LDU #FPSPAREA" );
7030 outline1( "LDX #%s",_x );
7031 outline0( "JSR FPLOD" );
7032
7033 outline1( "LDY %s", _string );
7034
7035 outline0( "JSR FPSCIENT" );
7036
7037 outline0( "TFR Y, D" );
7038 outline1( "SUBD %s", _string );
7039 outline1( "STB %s", _string_size );
7040
7041}
7042
7043void cpu_float_fast_from_8( Environment * _environment, char * _value, char * _result, int _signed ) {
7044 cpu_float_single_from_8( _environment, _value, _result, _signed );
7045}
7046
7047void cpu_float_single_from_8( Environment * _environment, char * _value, char * _result, int _signed ) {
7048
7049 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7050
7051 outline0( "CLRA" );
7052 outline1( "LDB %s", _value );
7053 outline0( "LDU #FPSPAREA" );
7054
7055 if ( _signed ) {
7056 outline0( "JSR INT2FP" );
7057 } else {
7058 outline0( "JSR UNINT2FP" );
7059 }
7060
7061 outline1( "LDX #%s", _result );
7062 outline0( "JSR FPSTO" );
7063
7064}
7065
7066void cpu_float_fast_from_16( Environment * _environment, char * _value, char * _result, int _signed ) {
7067 cpu_float_single_from_16( _environment, _value, _result, _signed );
7068}
7069
7070void cpu_float_single_from_16( Environment * _environment, char * _value, char * _result, int _signed ) {
7071
7072 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7073
7074 outline1( "LDD %s", _value );
7075 outline0( "LDU #FPSPAREA" );
7076
7077 if ( _signed ) {
7078 outline0( "JSR INT2FP" );
7079 } else {
7080 outline0( "JSR UNINT2FP" );
7081 }
7082
7083 outline1( "LDX #%s", _result );
7084 outline0( "JSR FPSTO" );
7085
7086}
7087
7088void cpu_float_fast_to_8( Environment * _environment, char * _value, char * _result, int _signed ) {
7089 cpu_float_single_to_8( _environment, _value, _result, _signed );
7090}
7091
7092void cpu_float_single_to_8( Environment * _environment, char * _value, char * _result, int _signed ) {
7093
7094 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7095
7096 outline0( "LDU #FPSPAREA" );
7097 outline1( "LDX #%s", _value );
7098 outline0( "JSR FPLOD" );
7099
7100 if ( _signed ) {
7101 outline0( "JSR FP2INT" );
7102 } else {
7103 outline0( "JSR FP2UINT" );
7104 }
7105 outline1( "STB %s", _result );
7106
7107}
7108
7109void cpu_float_fast_to_16( Environment * _environment, char * _value, char * _result, int _signed ) {
7110 cpu_float_single_to_16( _environment, _value, _result, _signed );
7111}
7112
7113void cpu_float_single_to_16( Environment * _environment, char * _value, char * _result, int _signed ) {
7114
7115 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7116
7117 outline0( "LDU #FPSPAREA" );
7118 outline1( "LDX #%s", _value );
7119 outline0( "JSR FPLOD" );
7120
7121 if ( _signed ) {
7122 outline0( "JSR FP2INT" );
7123 } else {
7124 outline0( "JSR FP2UINT" );
7125 }
7126 outline1( "STD %s", _result );
7127
7128}
7129
7130void cpu_float_fast_sub( Environment * _environment, char * _x, char * _y, char * _result ) {
7131 cpu_float_single_sub( _environment, _x, _y, _result );
7132}
7133
7134void cpu_float_single_sub( Environment * _environment, char * _x, char * _y, char * _result ) {
7135
7136 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7137
7138 outline0( "LDU #FPSPAREA" );
7139 outline1( "LDX #%s", _x );
7140 outline0( "JSR FPLOD" );
7141 outline1( "LDX #%s", _y );
7142 outline0( "JSR FPLOD" );
7143
7144 outline0( "JSR FPSUB" );
7145
7146 outline1( "LDX #%s", _result );
7147 outline0( "JSR FPSTO" );
7148
7149}
7150
7151void cpu_float_fast_add( Environment * _environment, char * _x, char * _y, char * _result ) {
7152 cpu_float_single_add( _environment, _x, _y, _result );
7153}
7154
7155void cpu_float_single_add( Environment * _environment, char * _x, char * _y, char * _result ) {
7156
7157 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7158
7159 outline0( "LDU #FPSPAREA" );
7160 outline1( "LDX #%s", _x );
7161 outline0( "JSR FPLOD" );
7162 outline1( "LDX #%s", _y );
7163 outline0( "JSR FPLOD" );
7164
7165 outline0( "JSR FPADD" );
7166
7167 outline1( "LDX #%s", _result );
7168 outline0( "JSR FPSTO" );
7169
7170}
7171
7172void cpu_float_fast_cmp( Environment * _environment, char * _x, char * _y, char * _result ) {
7173 cpu_float_single_cmp( _environment, _x, _y, _result );
7174}
7175
7176void cpu_float_single_cmp( Environment * _environment, char * _x, char * _y, char * _result ) {
7177
7179
7180 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7181
7182 outline0( "LDU #FPSPAREA" );
7183 outline1( "LDX #%s", _x );
7184 outline0( "JSR FPLOD" );
7185 outline1( "LDX #%s", _y );
7186 outline0( "JSR FPLOD" );
7187
7188 outline0( "JSR FPCMP" );
7189
7190 outline1( "BEQ %sequal", label );
7191 outline1( "BCS %sless", label );
7192 outline0( "LDA #$1" );
7193 outline1( "STA %s", _result );
7194 outline1( "JMP %sdone", label );
7195 outhead1( "%sequal", label );
7196 outline0( "LDA #$0" );
7197 outline1( "STA %s", _result );
7198 outline1( "JMP %sdone", label );
7199 outhead1( "%sless", label );
7200 outline0( "LDA #$ff" );
7201 outline1( "STA %s", _result );
7202 outline1( "JMP %sdone", label );
7203 outhead1( "%sdone", label );
7204
7205}
7206
7207void cpu_float_fast_mul( Environment * _environment, char * _x, char * _y, char * _result ) {
7208 cpu_float_single_mul( _environment, _x, _y, _result );
7209}
7210
7211void cpu_float_single_mul( Environment * _environment, char * _x, char * _y, char * _result ) {
7212
7213 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7214
7215 outline0( "LDU #FPSPAREA" );
7216 outline1( "LDX #%s", _x );
7217 outline0( "JSR FPLOD" );
7218 outline1( "LDX #%s", _y );
7219 outline0( "JSR FPLOD" );
7220
7221 outline0( "JSR FPMUL" );
7222
7223 outline1( "LDX #%s", _result );
7224 outline0( "JSR FPSTO" );
7225
7226}
7227
7228void cpu_float_fast_div( Environment * _environment, char * _x, char * _y, char * _result ) {
7229 cpu_float_single_div( _environment, _x, _y, _result );
7230}
7231
7232void cpu_float_single_div( Environment * _environment, char * _x, char * _y, char * _result ) {
7233
7234 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7235
7236 outline0( "LDU #FPSPAREA" );
7237 outline1( "LDX #%s", _x );
7238 outline0( "JSR FPLOD" );
7239 outline1( "LDX #%s", _y );
7240 outline0( "JSR FPLOD" );
7241
7242 outline0( "JSR FPDIV" );
7243
7244 outline1( "LDX #%s", _result );
7245 outline0( "JSR FPSTO" );
7246
7247}
7248
7249void cpu_float_fast_sin( Environment * _environment, char * _angle, char * _result ) {
7250 cpu_float_single_sin( _environment, _angle, _result );
7251}
7252
7253void cpu_float_single_sin( Environment * _environment, char * _angle, char * _result ) {
7254
7255 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7256
7257 outline0( "LDU #FPSPAREA" );
7258 outline1( "LDX #%s", _angle );
7259 outline0( "JSR FPLOD" );
7260
7261 outline0( "JSR FPSIN" );
7262
7263 outline1( "LDX #%s", _result );
7264 outline0( "JSR FPSTO" );
7265
7266}
7267
7268void cpu_float_fast_cos( Environment * _environment, char * _angle, char * _result ) {
7269 cpu_float_single_cos( _environment, _angle, _result );
7270}
7271
7272void cpu_float_single_cos( Environment * _environment, char * _angle, char * _result ) {
7273
7274 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7275
7276 outline0( "LDU #FPSPAREA" );
7277 outline1( "LDX #%s", _angle );
7278 outline0( "JSR FPLOD" );
7279
7280 outline0( "JSR FPCOS" );
7281
7282 outline1( "LDX #%s", _result );
7283 outline0( "JSR FPSTO" );
7284
7285}
7286
7287void cpu_float_fast_tan( Environment * _environment, char * _angle, char * _result ) {
7288 cpu_float_single_tan( _environment, _angle, _result );
7289}
7290
7291void cpu_float_single_tan( Environment * _environment, char * _angle, char * _result ) {
7292
7293 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7294
7295 outline0( "LDU #FPSPAREA" );
7296 outline1( "LDX #%s", _angle );
7297 outline0( "JSR FPLOD" );
7298
7299 outline0( "JSR FPTAN" );
7300
7301 outline1( "LDX #%s", _result );
7302 outline0( "JSR FPSTO" );
7303
7304}
7305
7306void cpu_float_fast_log( Environment * _environment, char * _value, char * _result ) {
7307 cpu_float_single_log( _environment, _value, _result );
7308}
7309
7310void cpu_float_single_log( Environment * _environment, char * _value, char * _result ) {
7311
7312 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7313
7314 outline0( "LDU #FPSPAREA" );
7315 outline1( "LDX #%s", _value );
7316 outline0( "JSR FPLOD" );
7317
7318 outline0( "JSR FPLN" );
7319
7320 outline1( "LDX #%s", _result );
7321 outline0( "JSR FPSTO" );
7322
7323}
7324
7325void cpu_float_fast_exp( Environment * _environment, char * _value, char * _result ) {
7326 cpu_float_single_exp( _environment, _value, _result );
7327}
7328
7329void cpu_float_single_exp( Environment * _environment, char * _value, char * _result ) {
7330
7331 deploy( fp_vars, src_hw_6309_fp_routines_asm );
7332
7333 outline0( "LDU #FPSPAREA" );
7334 outline1( "LDX #%s", _value );
7335 outline0( "JSR FPLOD" );
7336
7337 outline0( "JSR FPEXP" );
7338
7339 outline1( "LDX #%s", _result );
7340 outline0( "JSR FPSTO" );
7341
7342}
7343
7344void cpu_address_table_build( Environment * _environment, char * _table, int * _values, char *_address[], int _count ) {
7345
7346 outhead1("%s", _table );
7347 for( int i=0; i<_count; ++i ) {
7348 outline2("fdb $%4.4x, %s", _values[i], _address[i] );
7349 }
7350
7351}
7352
7353void cpu_address_table_lookup( Environment * _environment, char * _table, int _count ) {
7354
7355 outhead1("LOOKFOR%s", _table );
7356 if ( _count ) {
7357 outline1("LDX #%s", _table );
7358 outline0("LDU #0" );
7359 outhead1("LOOKFOR%sL1", _table );
7360 outline0("CMPD , X" );
7361 outline1("BNE LOOKFOR%sNEXT4", _table );
7362 outline0("LDD 2, X" );
7363 outline0("RTS" );
7364 outhead1("LOOKFOR%sNEXT4", _table );
7365 outline0("LEAX 4, X" );
7366 outline0("LEAU 4, U" );
7367 outline1("CMPU #$%4.4x", (_count+1) * 4 );
7368 outline1("BNE LOOKFOR%sL1", _table );
7369 }
7370 outline0("RTS" );
7371
7372}
7373
7374void cpu_address_table_call( Environment * _environment, char * _table, char * _value, char * _address ) {
7375
7376 outline1("LDD %s", _value );
7377 outline1("JSR LOOKFOR%s", _table );
7378 outline1("STD %s", _address );
7379
7380}
7381
7382void cpu_move_8bit_signed_16bit_signed( Environment * _environment, char *_source, char *_destination ) {
7383
7384 outline1("LDB %s", _source );
7385 outline0("SEX" );
7386 outline1("STD %s", _destination );
7387
7388}
7389
7390void cpu_move_8bit_signed_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7391
7392 outline1("LDB %s", _source );
7393 outline0("SEX" );
7394 outline1("STD %s", _destination );
7395
7396}
7397
7398void cpu_move_8bit_unsigned_16bit_signed( Environment * _environment, char *_source, char *_destination ){
7399
7400 outline1("LDB %s", _source );
7401 outline0("LDA #0" );
7402 outline1("STD %s", _destination );
7403
7404}
7405
7406void cpu_move_8bit_unsigned_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7407
7408 outline1("LDB %s", _source );
7409 outline0("LDA #0" );
7410 outline1("STD %s", _destination );
7411
7412}
7413
7414void cpu_move_8bit_signed_32bit_signed( Environment * _environment, char *_source, char *_destination ){
7415
7416 outline1("LDB %s", _source );
7417 outline0("SEX" );
7418 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7419 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
7420 outline1("STA %s", _destination );
7421
7422}
7423
7424void cpu_move_8bit_signed_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7425
7426 outline1("LDB %s", _source );
7427 outline0("SEX" );
7428 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7429 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
7430 outline1("STA %s", _destination );
7431
7432}
7433
7434void cpu_move_8bit_unsigned_32bit_signed( Environment * _environment, char *_source, char *_destination ){
7435
7436 outline1("LDB %s", _source );
7437 outline0("LDA #0" );
7438 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7439 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
7440 outline1("STA %s", _destination );
7441
7442}
7443void cpu_move_8bit_unsigned_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7444
7445 outline1("LDB %s", _source );
7446 outline0("LDA #0" );
7447 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7448 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
7449 outline1("STA %s", _destination );
7450
7451}
7452
7453void cpu_move_16bit_signed_8bit_signed( Environment * _environment, char *_source, char *_destination ){
7454
7455 outline1("LDD %s", _source );
7456 outline1("STB %s", _destination );
7457
7458}
7459void cpu_move_16bit_signed_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7460
7461 outline1("LDD %s", _source );
7462 outline1("STB %s", _destination );
7463
7464}
7465void cpu_move_16bit_unsigned_8bit_signed( Environment * _environment, char *_source, char *_destination ){
7466
7467 outline1("LDD %s", _source );
7468 outline1("STB %s", _destination );
7469
7470}
7471void cpu_move_16bit_unsigned_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7472
7473 outline1("LDD %s", _source );
7474 outline1("STB %s", _destination );
7475
7476}
7477
7478void cpu_move_16bit_signed_32bit_signed( Environment * _environment, char *_source, char *_destination ){
7479
7480 outline1("LDB %s", _source );
7481 outline0("SEX" );
7482 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
7483 outline1("STA %s", _destination );
7484 outline1("LDD %s", _source );
7485 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7486
7487}
7488void cpu_move_16bit_signed_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7489
7490 outline1("LDB %s", address_displacement( _environment, _source, "1" ) );
7491 outline0("SEX" );
7492 outline0("TFR A, B" );
7493 outline1("STD %s", _destination );
7494 outline1("LDD %s", _source );
7495 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7496
7497}
7498
7499void cpu_move_16bit_unsigned_32bit_signed( Environment * _environment, char *_source, char *_destination ){
7500
7501 outline0("LDD #0" );
7502 outline1("STD %s", _destination );
7503 outline1("LDD %s", _source );
7504 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7505
7506}
7507void cpu_move_16bit_unsigned_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7508
7509 outline0("LDD #0" );
7510 outline1("STD %s", _destination );
7511 outline1("LDD %s", _source );
7512 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7513
7514}
7515
7516void cpu_move_32bit_signed_8bit_signed( Environment * _environment, char *_source, char *_destination ){
7517
7518 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
7519 outline1("STA %s", _destination );
7520
7521}
7522void cpu_move_32bit_signed_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7523
7524 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
7525 outline1("STA %s", _destination );
7526
7527}
7528void cpu_move_32bit_unsigned_8bit_signed( Environment * _environment, char *_source, char *_destination ){
7529
7530 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
7531 outline1("STA %s", _destination );
7532
7533}
7534void cpu_move_32bit_unsigned_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7535
7536 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
7537 outline1("STA %s", _destination );
7538
7539}
7540
7541void cpu_move_32bit_signed_16bit_signed( Environment * _environment, char *_source, char *_destination ){
7542
7543 outline1("LDD %s", address_displacement( _environment, _source, "2" ) );
7544 outline1("STD %s", _destination );
7545
7546}
7547
7548void cpu_move_32bit_signed_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7549
7550 outline1("LDD %s", address_displacement( _environment, _source, "2" ) );
7551 outline1("STD %s", _destination );
7552
7553}
7554
7555void cpu_move_32bit_unsigned_16bit_signed( Environment * _environment, char *_source, char *_destination ){
7556
7557 outline1("LDD %s", address_displacement( _environment, _source, "2" ) );
7558 outline1("STD %s", _destination );
7559
7560}
7561
7562void cpu_move_32bit_unsigned_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7563
7564 outline1("LDD %s", address_displacement( _environment, _source, "2" ) );
7565 outline1("STD %s", _destination );
7566
7567}
7568
7569void cpu_encrypt( Environment * _environment, char * _data, char * _data_size, char * _key, char * _key_size, char * _output ) {
7570
7571 deploy( encrypt, src_hw_6309_encrypt_asm );
7572
7573 outline1("LDX %s", _data );
7574 outline1("LDU %s", _key );
7575 outline1("LDY %s", _output );
7576 outline1("LDA %s", _key_size );
7577 outline1("LDB %s", _data_size );
7578 outline0("JSR ENCRYPT" );
7579
7580}
7581
7582void cpu_decrypt( Environment * _environment, char * _data, char * _data_size, char * _key, char * _key_size, char * _output, char * _result ) {
7583
7584 deploy( decrypt, src_hw_6309_decrypt_asm );
7585
7586 outline1("LDX %s", _data );
7587 outline1("LDU %s", _key );
7588 outline1("LDY %s", _output );
7589 outline1("LDA %s", _key_size );
7590 outline1("LDB %s", _data_size );
7591 outline0("JSR DECRYPT" );
7592 cpu_ztoa( _environment );
7593 outline1("STA %s", _result );
7594
7595}
7596
7597void cpu_hex_to_bin( Environment * _environment, char * _value_address, char * _value_size, char * _variable_address, char * _variable_size, char * _result ) {
7598
7599 deploy( hex2bin, src_hw_6309_hex2bin_asm );
7600
7601 outline1("LDX %s", _value_address );
7602 outline1("LDA %s", _value_size );
7603 outline1("LDY %s", _variable_address );
7604 outline1("LDB %s", _variable_size );
7605 outline0("JSR HEX2BIN" );
7606 outline1("STA %s", _result );
7607
7608}
7609
7610void cpu_dsfill( Environment * _environment, char * _string, char * _value ) {
7611
7612 deploy_preferred( duff, src_hw_6309_duff_asm );
7613 deploy( dstring, src_hw_6309_dstring_asm );
7614
7615 outline1( "LDB %s", _string );
7616 outline1( "LDA %s", _value );
7617 outline0( "JSR DSFILL" );
7618
7619}
7620
7621void cpu_dsfill_value( Environment * _environment, char * _string, int _value ) {
7622
7623 deploy_preferred( duff, src_hw_6309_duff_asm );
7624 deploy( dstring, src_hw_6309_dstring_asm );
7625
7626 outline1( "LDB %s", _string );
7627 outline1( "LDA #$%2.2x", (unsigned char)(_value&0xff) );
7628 outline0( "JSR DSFILL" );
7629
7630}
7631
7632#endif
void cpu_and_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4258
void cpu_float_single_cos(Environment *_environment, char *_angle, char *_result)
Definition 6309.c:7272
void cpu_protothread_get_state(Environment *_environment, char *_index, char *_state)
Definition 6309.c:6237
void cpu_set_callback(Environment *_environment, char *_callback, char *_label)
Definition 6309.c:6270
void cpu_move_32bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6309.c:5398
void cpu_dsfree(Environment *_environment, char *_index)
Definition 6309.c:5917
void cpu_less_than_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6309.c:5034
void cpu_dsresize_size(Environment *_environment, char *_index, int _resize)
Definition 6309.c:5948
void cpu_less_than_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:970
void cpu_hex_to_string_calc_string(Environment *_environment, char *_size, int _separator, char *_string_size)
Definition 6309.c:5831
void cpu_move_8bit_signed_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7424
void cpu_float_fast_from_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6309.c:7043
void cpu_in(Environment *_environment, char *_port, char *_value)
Definition 6309.c:6357
void cpu_hex_to_string_calc_string_size(Environment *_environment, int _size, int _separator, char *_string_size)
Definition 6309.c:5848
void cpu_pokew(Environment *_environment, char *_address, char *_source)
Definition 6309.c:410
void cpu_move_32bit_signed_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7548
void cpu_combine_nibbles(Environment *_environment, char *_low_nibble, char *_hi_nibble, char *_byte)
Definition 6309.c:3724
char * cpu_blit_register_name(Environment *_environment, int _register)
Definition 6309.c:6417
void cpu_di(Environment *_environment)
Definition 6309.c:4547
#define B(code, label)
Definition 6309.c:47
void cpu_float_fast_tan(Environment *_environment, char *_angle, char *_result)
Definition 6309.c:7287
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_protothread_restore(Environment *_environment, char *_index, char *_step)
Definition 6309.c:6214
void cpu_msc1_uncompress_indirect_indirect(Environment *_environment, char *_input, char *_output)
Definition 6309.c:6337
void cpu_not_16bit(Environment *_environment, char *_value, char *_result)
Definition 6309.c:4517
void cpu_move_8bit_unsigned_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7434
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_move_16bit_signed_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7478
void cpu_move_8bit_unsigned_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7398
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 6309.c:2871
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_swap_32bit(Environment *_environment, char *_left, char *_right)
Definition 6309.c:4479
void cpu_float_fast_from_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6309.c:7066
void cpu_bveq(Environment *_environment, char *_value, char *_label)
Definition 6309.c:334
void cpu_dsresize(Environment *_environment, char *_index, char *_resize)
Definition 6309.c:5937
void cpu_move_nbit_indirect(Environment *_environment, int _n, char *_source, char *_value)
Definition 6309.c:6626
void cpu_math_div_8bit_to_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _signed)
Definition 6309.c:1242
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_float_fast_div(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7228
void cpu_move_32bit_signed_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7541
void cpu_move_32bit_unsigned_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7534
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_address_table_build(Environment *_environment, char *_table, int *_values, char *_address[], int _count)
Definition 6309.c:7344
void cpu_mem_move(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6309.c:4692
void cpu_set_asmio_indirect(Environment *_environment, int _asmio, char *_value)
Definition 6309.c:3904
void cpu_msc1_uncompress_direct_indirect(Environment *_environment, char *_input, char *_output)
Definition 6309.c:6305
void cpu_math_sub_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to subtract two 8 bit values
Definition 6309.c:1049
void cpu_xor_32bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6309.c:4432
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_protothread_save(Environment *_environment, char *_index, int _step)
Definition 6309.c:6203
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_poked(Environment *_environment, char *_address, char *_source)
Definition 6309.c:445
void cpu_and_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6309.c:4230
void cpu_dsassign(Environment *_environment, char *_original, char *_copy)
Definition 6309.c:5997
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_complement2_8bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:6045
void cpu_msc1_uncompress_indirect_direct(Environment *_environment, char *_input, char *_output)
Definition 6309.c:6321
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_dsalloc_size(Environment *_environment, int _size, char *_index)
Definition 6309.c:5906
void cpu_get_asmio_indirect(Environment *_environment, int _asmio, char *_value)
Definition 6309.c:3967
void cpu_move_16bit_unsigned_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7471
void cpu_float_fast_cos(Environment *_environment, char *_angle, char *_result)
Definition 6309.c:7268
void cpu_protothread_set_state(Environment *_environment, char *_index, int _state)
Definition 6309.c:6226
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_float_single_add(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7155
void cpu_float_single_sub(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7134
void cpu_bit_inplace_8bit_extended_indirect(Environment *_environment, char *_address, char *_position, char *_bit)
Definition 6309.c:5663
void cpu_move_8bit_unsigned_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7443
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_fill_direct_size(Environment *_environment, char *_address, int _bytes, char *_pattern)
CPU 6309: emit code to fill up a memory area
Definition 6309.c:675
void cpu_addressof_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:1485
void cpu_dec_16bit(Environment *_environment, char *_variable)
Definition 6309.c:4640
void cpu_dsgc(Environment *_environment)
Definition 6309.c:5959
void cpu_move_16bit_signed_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7488
void cpu_inc(Environment *_environment, char *_variable)
Definition 6309.c:4555
void cpu_poke_const(Environment *_environment, char *_address, int _source)
Definition 6309.c:388
void cpu_fill_direct(Environment *_environment, char *_address, char *_bytes, char *_pattern)
CPU 6309: emit code to fill up a memory area
Definition 6309.c:643
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_dsdefine(Environment *_environment, char *_string, char *_index)
Definition 6309.c:5884
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_move_16bit_unsigned_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7507
void cpu_math_mul2_const_nbit(Environment *_environment, char *_source, int _steps, int _bits)
Definition 6309.c:3664
void cpu_float_single_exp(Environment *_environment, char *_value, char *_result)
Definition 6309.c:7329
void cpu_move_32bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 32 bit
Definition 6309.c:2520
void cpu_fill_size(Environment *_environment, char *_address, int _bytes, char *_pattern)
CPU 6309: emit code to fill up a memory area
Definition 6309.c:575
void cpu_dsfill(Environment *_environment, char *_string, char *_value)
Definition 6309.c:7610
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
void cpu_fill_direct_size_value(Environment *_environment, char *_address, int _bytes, int _pattern)
CPU 6309: emit code to fill up a memory area
Definition 6309.c:712
#define cpu_BLIT_REGISTER_COUNT
Definition 6309.c:6401
void cpu_dec_32bit(Environment *_environment, char *_variable)
Definition 6309.c:4652
void cpu_greater_than_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:1642
void cpu_protothread_get_address(Environment *_environment, char *_index, char *_address)
Definition 6309.c:6258
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_bit_inplace_8bit(Environment *_environment, char *_value, int _position, int *_bit)
Definition 6309.c:5633
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_poked_const(Environment *_environment, char *_address, int _source)
Definition 6309.c:458
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_dswrite(Environment *_environment, char *_index)
Definition 6309.c:5927
void cpu_complement2_nbit(Environment *_environment, char *_source, char *_destination, int _bits)
Definition 6309.c:6093
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_move_nbit_indirect2(Environment *_environment, int _n, char *_value, char *_source)
Definition 6309.c:6681
void cpu_and_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4216
void cpu_float_single_log(Environment *_environment, char *_value, char *_result)
Definition 6309.c:7310
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_compare_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive)
CPU 6309: emit code to compare two 16 bit values
Definition 6309.c:1542
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_store_nbit(Environment *_environment, char *_destination, int _n, int _value[])
CPU 6309: emit code to store n bit
Definition 6309.c:6499
void cpu_mem_move_direct_indirect_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6309.c:4815
void cpu_dec_nbit(Environment *_environment, char *_variable, int _bits)
Definition 6309.c:4672
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_float_single_from_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6309.c:7070
void cpu_fill_indirect(Environment *_environment, char *_address, char *_size, char *_pattern, int _size_size)
Definition 6309.c:5517
void cpu_mem_move_indirect_direct_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6309.c:4832
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_float_fast_sin(Environment *_environment, char *_angle, char *_result)
Definition 6309.c:7249
void cpu_math_mul_nbit_to_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6309.c:1886
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_float_fast_log(Environment *_environment, char *_value, char *_result)
Definition 6309.c:7306
void cpu_move_nbit(Environment *_environment, int _n, char *_source, char *_destination)
CPU cpu6309: emit code to store n bit
Definition 6309.c:6563
void cpu_address_table_call(Environment *_environment, char *_table, char *_value, char *_address)
Definition 6309.c:7374
void cpu_logical_not_8bit(Environment *_environment, char *_value, char *_result)
Definition 6309.c:4493
void cpu_pokew_const(Environment *_environment, char *_address, int _source)
Definition 6309.c:421
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_float_fast_from_double_to_int_array(Environment *_environment, double _value, int _result[])
Definition 6309.c:6743
void cpu_compare_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6309.c:4849
void cpu_greater_than_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:999
void cpu_complement2_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:6057
void cpu_dsinit(Environment *_environment)
Definition 6309.c:5968
void cpu_xor_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4354
void cpu_protothread_unregister(Environment *_environment, char *_index)
Definition 6309.c:6193
void cpu_decrypt(Environment *_environment, char *_data, char *_data_size, char *_key, char *_key_size, char *_output, char *_result)
Definition 6309.c:7582
void cpu_complement2_32bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:6070
void cpu_protothread_register_at(Environment *_environment, char *_index, char *_label)
Definition 6309.c:6170
void cpu_blit_free_register(Environment *_environment, int _register)
Definition 6309.c:6460
void cpu_lowercase(Environment *_environment, char *_source, char *_size, char *_result)
Definition 6309.c:5451
void cpu_float_single_to_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6309.c:7092
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_out(Environment *_environment, char *_port, char *_value)
Definition 6309.c:6353
void cpu_move_16bit_unsigned_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7465
void cpu_blit_finalize(Environment *_environment)
Definition 6309.c:6410
void cpu_encrypt(Environment *_environment, char *_data, char *_data_size, char *_key, char *_key_size, char *_output)
Definition 6309.c:7569
void cpu_bneq(Environment *_environment, char *_label)
CPU 6309: emit code to make long conditional jump
Definition 6309.c:324
void cpu_compare_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive, int _bits)
Definition 6309.c:2836
void cpu_move_16bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6309.c:5352
void cpu_float_fast_cmp(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7172
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_float_fast_mul(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7207
void cpu_bits_to_string(Environment *_environment, char *_number, char *_string, char *_string_size, int _bits, char *_zero, char *_one)
Definition 6309.c:5777
void cpu_dsalloc(Environment *_environment, char *_size, char *_index)
Definition 6309.c:5895
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_float_single_from_double_to_int_array(Environment *_environment, double _value, int _result[])
Definition 6309.c:6747
void cpu_float_single_to_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6309.c:7113
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_move_8bit_indirect_with_offset(Environment *_environment, char *_source, char *_value, int _offset)
Definition 6309.c:5250
void cpu_sqroot(Environment *_environment, char *_number, char *_result)
Definition 6309.c:6113
void cpu_number_to_string(Environment *_environment, char *_number, char *_string, char *_string_size, int _bits, int _signed)
Definition 6309.c:5688
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_peekd(Environment *_environment, char *_address, char *_target)
Definition 6309.c:432
void cpu_in_direct(Environment *_environment, char *_port, char *_value)
Definition 6309.c:6365
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_xor_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6309.c:4368
void cpu_move_16bit_signed_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7459
void cpu_mem_move_direct(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6309.c:4728
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_float_fast_to_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6309.c:7088
void cpu_mem_move_direct2(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6309.c:4764
void cpu_init(Environment *_environment)
Definition 6309.c:62
void cpu_dstring_vars(Environment *_environment)
Definition 6309.c:6128
void cpu_protothread_loop(Environment *_environment)
Definition 6309.c:6162
void cpu_float_single_div(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7232
void cpu_hex_to_bin(Environment *_environment, char *_value_address, char *_value_size, char *_variable_address, char *_variable_size, char *_result)
Definition 6309.c:7597
void cpu_out_direct(Environment *_environment, char *_port, char *_value)
Definition 6309.c:6361
void cpu_greater_than_32bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:3153
void cpu_protothread_current(Environment *_environment, char *_current)
Definition 6309.c:6249
void cpu_float_fast_to_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6309.c:7109
void cpu_mem_move_16bit(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6309.c:4711
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_set_asmio(Environment *_environment, int _asmio, int _value)
Definition 6309.c:3838
void cpu_jump(Environment *_environment, char *_label)
Definition 6309.c:3739
void cpu_store_8bit_with_offset2(Environment *_environment, char *_source, char *_offset, int _value)
Definition 6309.c:6029
void cpu_move_16bit_unsigned_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7499
int cpu_blit_alloc_register(Environment *_environment)
Definition 6309.c:6426
void cpu_move_32bit_signed_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7522
void cpu_mem_move_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6309.c:4781
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_float_single_mul(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7211
void cpu_float_fast_exp(Environment *_environment, char *_value, char *_result)
Definition 6309.c:7325
void cpu_move_16bit_signed_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7453
void cpu_compare_and_branch_16bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6309.c:1552
void cpu_fill_size_value(Environment *_environment, char *_address, int _bytes, int _pattern)
CPU 6309: emit code to fill up a memory area
Definition 6309.c:611
void cpu_call_addr(Environment *_environment, int _address)
Definition 6309.c:3749
void cpu_math_div_16bit_to_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _signed)
Definition 6309.c:2153
void cpu_poke(Environment *_environment, char *_address, char *_source)
Definition 6309.c:377
void cpu_bit_check(Environment *_environment, char *_value, int _position, char *_result, int _bitwidth)
Definition 6309.c:5577
void cpu_protothread_register(Environment *_environment, char *_label, char *_index)
Definition 6309.c:6181
void cpu_move_32bit_signed_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7516
void cpu_float_single_to_string(Environment *_environment, char *_x, char *_string, char *_string_size)
Definition 6309.c:7023
void cpu_math_div_nbit_to_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _bits)
Definition 6309.c:2701
void cpu_float_single_tan(Environment *_environment, char *_angle, char *_result)
Definition 6309.c:7291
void cpu_nop(Environment *_environment)
Definition 6309.c:256
void cpu_random_32bit(Environment *_environment, char *_entropy, char *_result)
Definition 6309.c:4151
void cpu_move_32bit_unsigned_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7562
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_prepare_for_compare_and_branch_8bit(Environment *_environment, char *_source)
Definition 6309.c:841
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_mem_move_direct2_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6309.c:4747
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_move_32bit_unsigned_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7555
void cpu_msc1_uncompress_direct_direct(Environment *_environment, char *_input, char *_output)
Definition 6309.c:6279
void cpu_inc_32bit(Environment *_environment, char *_variable)
Definition 6309.c:4586
void cpu_move_8bit_signed_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7382
void cpu_mem_move_direct_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6309.c:4798
void cpu_float_fast_sub(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7130
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
int cpu_register_decode(Environment *_environment, char *_register)
Definition 6309.c:3793
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_convert_string_into_8bit(Environment *_environment, char *_string, char *_len, char *_value)
Definition 6309.c:5487
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_address_table_lookup(Environment *_environment, char *_table, int _count)
Definition 6309.c:7353
void cpu_ztoa(Environment *_environment)
Definition 6309.c:262
void cpu_random(Environment *_environment, char *_entropy)
Definition 6309.c:4075
void cpu_move_32bit_unsigned_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7528
void cpu_compare_and_branch_8bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6309.c:851
void cpu_execute_compare_and_branch_8bit_const(Environment *_environment, 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:901
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_float_single_from_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6309.c:7047
void cpu_math_sub_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6309.c:3325
void cpu_float_single_cmp(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7176
void cpu_move_8bit_signed_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7414
void cpu_math_div2_const_nbit(Environment *_environment, char *_source, int _steps, int _bits, char *_remainder)
Definition 6309.c:3503
void cpu_store_8bit_with_offset(Environment *_environment, char *_destination, int _value, int _offset)
Definition 6309.c:6021
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_peekw(Environment *_environment, char *_address, char *_target)
Definition 6309.c:399
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_float_fast_add(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6309.c:7151
void cpu_convert_string_into_16bit(Environment *_environment, char *_string, char *_len, char *_value)
Definition 6309.c:5502
void cpu_float_single_sin(Environment *_environment, char *_angle, char *_result)
Definition 6309.c:7253
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_dsdescriptor(Environment *_environment, char *_index, char *_address, char *_size)
Definition 6309.c:5977
void cpu_math_add_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6309.c:3238
void cpu_compare_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:831
void cpu_xor_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4382
void cpu_xor_16bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6309.c:4397
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_math_div_32bit_to_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _signed)
Definition 6309.c:2734
void cpu_greater_than_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _bits)
Definition 6309.c:3200
void cpu_float_fast_to_string(Environment *_environment, char *_x, char *_string, char *_string_size)
Definition 6309.c:7019
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_dsfill_value(Environment *_environment, char *_string, int _value)
Definition 6309.c:7621
void cpu_dsassign_string(Environment *_environment, char *_string, char *_copy)
Definition 6309.c:6009
void cpu_move_8bit_signed_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7390
void cpu_move_8bit_unsigned_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:7406
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_flip_8bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:5544
void cpu_blit_initialize(Environment *_environment)
Definition 6309.c:6403
void cpu_less_than_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:1613
enum _CPU6309Stack CPU6309Stack
#define IS_REGISTER(x)
Definition 6309.h:58
@ REGISTER_B
Definition 6309.h:64
@ REGISTER_DP
Definition 6309.h:66
@ REGISTER_CC
Definition 6309.h:65
@ REGISTER_Y
Definition 6309.h:68
@ REGISTER_D
Definition 6309.h:72
@ REGISTER_A
Definition 6309.h:63
@ REGISTER_X
Definition 6309.h:67
@ REGISTER_S
Definition 6309.h:70
@ REGISTER_U
Definition 6309.h:69
@ REGISTER_NONE
Definition 6309.h:62
@ REGISTER_PC
Definition 6309.h:71
enum _CPU6309Register CPU6309Register
@ STACK_NONE
Definition 6309.h:78
@ STACK_BYTE
Definition 6309.h:79
@ STACK_WORD
Definition 6309.h:80
@ STACK_DWORD
Definition 6309.h:81
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_mul2_const_16bit_generated[16]
Definition ugbc.h:2084
int cpu_math_div_nbit_to_nbit_const[32]
Definition ugbc.h:2087
int cpu_math_mul2_const_8bit_generated[8]
Definition ugbc.h:2083
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
int msc1
Definition ugbc.h:1937
int random
Definition ugbc.h:1940
int stackStartAddress
Definition ugbc.h:3296
int bitmaskNeeded
Definition ugbc.h:2659
NumberConfig numberConfig
Definition ugbc.h:2410
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
Deployed deployed
Definition ugbc.h:2921
int maxBytes
Definition ugbc.h:2261
#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 CRITICAL_DEBUG_UNSUPPORTED(v, t)
Definition ugbc.h:3478
#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.
#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(s, e)
Definition ugbc.h:4288
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247