ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
6809.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(__d32__) || defined(__d64__) || defined(__pc128op__) || defined(__mo5__) || defined(__coco__) || defined(__coco3__) || defined(__to8__)
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_6809_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_6809_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 outline1("LDX %s", _address);
556
557 done( )
558
559}
560
574void cpu_fill_size( Environment * _environment, char * _address, int _bytes, char * _pattern ) {
575
577
578 embedded( cpu_fill, src_hw_6809_cpu_fill_asm );
579
580 if ( _pattern ) {
581 outline1("LDA %s", _pattern );
582 } else {
583 outline0("LDX #0");
584 }
585 outline1("LDX %s", _address);
586 outline1("LDY #$%4.4x", _bytes );
587 if ( _bytes < 256 ) {
588 outline0("JSR CPUFILL8");
589 } else {
590 outline0("JSR CPUFILL16");
591 }
592
593 done( )
594
595}
596
610void cpu_fill_size_value( Environment * _environment, char * _address, int _bytes, int _pattern ) {
611
613
614 embedded( cpu_fill, src_hw_6809_cpu_fill_asm );
615
616 outline1("LDA #$%2.2x", _pattern );
617 outline1("LDX %s", _address);
618 outline1("LDY #$%4.4x", _bytes );
619 if ( _bytes < 256 ) {
620 outline0("JSR CPUFILL8");
621 } else {
622 outline0("JSR CPUFILL16");
623 }
624
625 done( )
626
627}
628
642void cpu_fill_direct( Environment * _environment, char * _address, char * _bytes, char * _pattern ) {
643
645
646 embedded( cpu_fill, src_hw_6809_cpu_fill_asm );
647
648 if ( _pattern ) {
649 outline1("LDA %s", _pattern );
650 } else {
651 outline0("LDA #0");
652 }
653 outline1("LDX #%s", _address);
654 outline1("LDY %s", _bytes);
655 outline0("JSR CPUFILL16");
656
657 done( )
658
659}
660
674void cpu_fill_direct_size( Environment * _environment, char * _address, int _bytes, char * _pattern ) {
675
677
678 embedded( cpu_fill, src_hw_6809_cpu_fill_asm );
679
680 if ( _pattern ) {
681 outline1("LDA %s", _pattern );
682 } else {
683 outline0("LDA #0");
684 }
685 outline1("LDX #%s", _address);
686 outline1("LDY #$%4.4x", _bytes);
687
688 if ( _bytes < 256 ) {
689 outline0("JSR CPUFILL8");
690 } else {
691 outline0("JSR CPUFILL16");
692 }
693
694 done( )
695
696}
697
711void cpu_fill_direct_size_value( Environment * _environment, char * _address, int _bytes, int _pattern ) {
712
714
715 embedded( cpu_fill, src_hw_6809_cpu_fill_asm );
716
717 outline1("LDA #$%2.2x", _pattern );
718 outline1("LDX #%s", _address);
719 outline1("LDY #$%4.4x", _bytes);
720
721 if ( _bytes < 256 ) {
722 outline0("JSR CPUFILL8");
723 } else {
724 outline0("JSR CPUFILL16");
725 }
726
727 done( )
728
729}
730
731/*****************************************************************************
732 * 8 BIT MANIPULATION
733 ****************************************************************************/
734
742void cpu_move_8bit( Environment * _environment, char *_source, char *_destination ) {
743
744 inline( cpu_move_8bit )
745
746 outline1("LDB %s", _source);
747 outline1("STB %s", _destination);
748
750
751}
752
760void cpu_store_8bit( Environment * _environment, char *_destination, int _value ) {
761
762 inline( cpu_store_8bit )
763
764 if(_value) {
765 outline1("LDB #$%2.2x" , (unsigned char)(_value & 0xff) );
766 outline1("STB %s", _destination );
767 } else {
768 // make A=0 as much as possible
769 outline0("CLRA");
770 outline1("STA %s", _destination );
771 }
772
774
775}
776
784void cpu_store_char( Environment * _environment, char *_destination, int _value ) {
785
786 inline( cpu_store_char )
787
788 if(_value) {
789 outline1("LDB #'%c'" , _value );
790 outline1("STB %s", _destination );
791 } else {
792 // make A=0 as much as possible
793 outline0("CLRA");
794 outline1("STA %s", _destination );
795 }
796
798
799}
800
810void cpu_compare_8bit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive ) {
811
812 inline( cpu_compare_8bit )
813
814 cpu_compare(_environment,_source, _destination, _other, _positive, 8);
815
817
818}
819
820
830void cpu_compare_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive ) {
831
832 inline( cpu_compare_8bit )
833
834 cpu_compare_const(_environment,_source, _destination, _other, _positive, 8);
835
837
838}
839
840void cpu_prepare_for_compare_and_branch_8bit( Environment * _environment, char *_source ) {
841
843
844 outline1("LDB %s", _source);
845
847
848}
849
850void cpu_compare_and_branch_8bit( Environment * _environment, char *_source, char * _destination, char *_label, int _positive ) {
851
853
854 outline1("LDB %s", _source);
855 outline1("CMPB %s", _destination);
856 if ( _positive ) {
857 B(EQ, _label);
858 } else {
859 B(NE, _label);
860 }
861
863
864}
865
875void cpu_compare_and_branch_8bit_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
876
878
879 outline1("LDB %s", _source);
880 outline1("CMPB #$%2.2x", _destination);
881 if ( _positive ) {
882 B(EQ, _label);
883 } else {
884 B(NE, _label);
885 }
886
888
889}
890
900void cpu_execute_compare_and_branch_8bit_const( Environment * _environment, int _destination, char *_label, int _positive ) {
901
903
904 outline1("CMPB #$%2.2x", _destination);
905 if ( _positive ) {
906 B(EQ, _label);
907 } else {
908 B(NE, _label);
909 }
910
912
913}
914
924void cpu_compare_and_branch_char_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
925
927
928 outline1("LDB %s", _source);
929 outline1("CMPB #'%c'", _destination);
930 if ( _positive ) {
931 B(EQ, _label);
932 } else {
933 B(NE, _label);
934 }
935
937
938}
939
949void cpu_less_than_8bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
950
951 inline( cpu_less_than_8bit )
952
953 cpu_less_than(_environment, _source, _destination, _other, _equal, _signed, 8);
954
956
957}
958
959void cpu_less_than_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
960
962
963 cpu_less_than_const(_environment, _source, _destination, _other, _equal, _signed, 8);
964
966
967}
968
969void cpu_less_than_and_branch_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
970
972
973 cpu_less_than_and_branch_const(_environment, _source, _destination, _other, _equal, _signed, 8);
974
976
977}
978
988void cpu_greater_than_8bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
989
990 inline( cpu_greater_than_8bit )
991
992 cpu_greater_than(_environment, _source, _destination, _other, _equal, _signed, 8);
993
995
996}
997
998void cpu_greater_than_8bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
999
1000 inline( cpu_greater_than_8bit )
1001
1002 cpu_greater_than_const(_environment, _source, _destination, _other, _equal, _signed, 8);
1003
1005
1006}
1007
1016void cpu_math_add_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
1017
1018 inline( cpu_math_add_8bit )
1019
1020 outline1("LDB %s", _source);
1021 outline1("ADDB %s", _destination);
1022 outline1("STB %s", _other ? _other : _destination);
1023
1025
1026}
1027
1028void cpu_math_add_8bit_const( Environment * _environment, char *_source, int _destination, char *_other ) {
1029
1030 inline( cpu_math_add_8bit )
1031
1032 outline1("LDB %s", _source);
1033 outline1("ADDB #$%2.2x", ( _destination & 0xff ) );
1034 outline1("STB %s", _other );
1035
1037
1038}
1039
1048void cpu_math_sub_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
1049
1050 inline( cpu_math_sub_8bit )
1051
1052 outline1("LDB %s", _source);
1053 outline1("SUBB %s", _destination);
1054 outline1("STB %s", _other ? _other : _destination);
1055
1057
1058}
1059
1067void cpu_math_double_8bit( Environment * _environment, char *_source, char *_other, int _signed ) {
1068
1069 inline( cpu_math_sub_8bit )
1070
1071 outline1("LDB %s", _source);
1072 outline0("ASLB");
1073 outline1("STB %s", _other ? _other : _source);
1074
1076
1077}
1078
1087void cpu_math_mul_8bit_to_16bit( Environment * _environment, char *_source, char *_destination, char *_other, int _signed ) {
1088
1090
1092
1093 if ( _signed ) {
1094
1095 outline0("LDA #0" );
1096 outline0("STA <MATHPTR0" );
1097 outline1("LDA %s", _source );
1098 outline1("EORA %s", _destination );
1099 outline0("ANDA #$80" );
1100 outline1("BEQ %ssamesign", label );
1101 outline0("STA <MATHPTR0" );
1102 outhead1("%ssamesign", label );
1103
1104 outline1("LDA %s", _source );
1105 outline0("ANDA #$80" );
1106 outline1("BEQ %spositive1", label );
1107 outline1("LDA %s", _source );
1108 outline0("EORA #$FF" );
1109 outline0("ADDA #1" );
1110 outline1("JMP %spositive1b", label );
1111
1112 outhead1("%spositive1", label );
1113 outline1("LDA %s", _source );
1114 outhead1("%spositive1b", label );
1115 outline1("LDB %s", _destination );
1116 outline0("ANDB #$80" );
1117 outline1("BEQ %spositive2", label );
1118 outline1("LDB %s", _destination );
1119 outline0("EORB #$FF" );
1120 outline0("ADDB #1" );
1121 outline1("JMP %spositive2b", label );
1122
1123 outhead1("%spositive2", label );
1124 outline1("LDB %s", _destination );
1125 outhead1("%spositive2b", label );
1126 } else {
1127 outline1("LDA %s", _source );
1128 outline1("LDB %s", _destination );
1129 }
1130
1131 outline0("MUL" );
1132
1133 outline1("STD %s", _other );
1134
1135 if ( _signed ) {
1136 outline0("LDA <MATHPTR0" );
1137 outline0("CMPA #0" );
1138 outline1("BEQ %sdone", label );
1139 outline1("LDD %s", _other );
1140 outline0("EORA #$FF" );
1141 outline0("EORB #$FF" );
1142 outline0("ADDD #1" );
1143 outline1("STD %s", _other );
1144 outhead1("%sdone", label );
1145 }
1146
1147 embedded( cpu_math_mul_8bit_to_16bit, src_hw_6809_cpu_math_mul_8bit_to_16bit_asm );
1148
1149 outline1("LDB %s", _source );
1150 outline1("LDA %s", _destination );
1151 if ( _signed ) {
1152 outline0("JSR CPUMATHMUL8BITTO16BIT_SIGNED" );
1153 } else {
1154 outline0("MUL" );
1155 }
1156 outline1("STD %s", _other );
1157
1158 done( )
1159
1160}
1161
1162void cpu_math_div_8bit_to_8bit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _signed ) {
1163
1165
1167 outline0("LDX #$0");
1168 outline1("LDA %s", _destination);
1169 if ( _signed ) {
1170 outline0("ANDA #$80");
1171 outline0("CMPA #$0");
1172 outline1("BEQ %spos1", label);
1173 outline0("LDX #$1");
1174 outline1("LDA %s", _destination);
1175 outline0("EORA #$FF");
1176 outline0("ADDA #$1");
1177 outline0("STA <TMPPTR");
1178 outline1("JMP %sdone1", label);
1179 outhead1("%spos1", label );
1180 outline0("STA <TMPPTR");
1181 outline1("JMP %sdone1", label);
1182 outhead1("%sdone1", label );
1183 } else {
1184 outline0("STA <TMPPTR");
1185 }
1186 outline1("LDA %s", _source);
1187 if ( _signed ) {
1188 outline0("ANDA #$80");
1189 outline0("CMPA #$0");
1190 outline1("BEQ %spos2", label);
1191 outline0("LDX #$1");
1192 outline1("LDA %s", _source);
1193 outline0("EORA #$FF");
1194 outline0("ADDA #$1");
1195 outline0("STA <TMPPTR+1");
1196 outline1("JMP %sdone2", label);
1197 outhead1("%spos2", label );
1198 outline0("STA <TMPPTR+1");
1199 outline1("JMP %sdone2", label);
1200 outhead1("%sdone2", label );
1201 } else {
1202 outline0("STA <TMPPTR+1");
1203 }
1204 outhead1("%spos", label );
1205 outline0("LDA #$8");
1206 outline1("STA %s", _other_remainder);
1207 outline0("LDA #$0" );
1208 outline0("LDB <TMPPTR+1" );
1209 outhead1("%sdivide", label );
1210 outline0("ASLB" );
1211 outline0("ROLA" );
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_6809_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_6809_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_6809_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 if(_other) {
1733 outline1("LDD %s", _source);
1734 outline0("LSLB");
1735 outline0("ROLA");
1736 outline1("STD %s", _other);
1737 } else {
1738 outline1("LSL %s", address_displacement(_environment, _source, "1"));
1739 outline1("ROL %s", _source);
1740 }
1741
1743
1744}
1745
1754void cpu_math_mul_16bit_to_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _signed ) {
1755
1757
1759
1760 if ( _signed ) {
1761 outline0("LDA #0" );
1762 outline0("STA <TMPPTR" );
1763 outline1("LDA %s", _source );
1764 outline1("EORA %s", _destination );
1765 outline0("ANDA #$80" );
1766 outline1("BEQ %ssamesign", label );
1767 outline0("STA <TMPPTR" );
1768 outhead1("%ssamesign", label );
1769
1770 outline1("LDA %s", _source );
1771 outline0("ANDA #$80" );
1772 outline1("BEQ %spos1", label );
1773 outline1("LDA %s", address_displacement(_environment, _source, "1") );
1774 outline0("EORA #$FF" );
1775 outline0("STA <MATHPTR1" );
1776 outline1("LDA %s", _source );
1777 outline0("EORA #$FF" );
1778 outline0("STA <MATHPTR0" );
1779 outline0("LDX <MATHPTR0" );
1780 outline0("LEAX 1,X" );
1781 outline0("STX <MATHPTR0" );
1782 outline1("JMP %sdone1", label );
1783 outhead1("%spos1", label );
1784 outline1("LDX %s", _source );
1785 outline0("STX <MATHPTR0" );
1786 outhead1("%sdone1", label );
1787
1788 outline1("LDA %s", _destination );
1789 outline0("ANDA #$80" );
1790 outline1("BEQ %spos2", label );
1791 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
1792 outline0("EORA #$FF" );
1793 outline0("STA <MATHPTR3" );
1794 outline1("LDA %s", _destination );
1795 outline0("EORA #$FF" );
1796 outline0("STA <MATHPTR2" );
1797 outline0("LDX <MATHPTR2" );
1798 outline0("LEAX 1,X" );
1799 outline0("STX <MATHPTR2" );
1800 outline1("JMP %sdone2", label );
1801 outhead1("%spos2", label );
1802 outline1("LDX %s", _destination );
1803 outline0("STX <MATHPTR2" );
1804 outhead1("%sdone2", label );
1805 } else {
1806 outline1("LDD %s", _source );
1807 outline0("STD <MATHPTR0" );
1808 outline1("LDD %s", _destination );
1809 outline0("STD <MATHPTR2" );
1810 }
1811 outline0("LDA <MATHPTR0" );
1812 outline0("LDB <MATHPTR2" );
1813 outline0("MUL");
1814 outline1("STD %s", _other );
1815
1816 outline0("LDA <MATHPTR1" );
1817 outline0("LDB <MATHPTR3" );
1818 outline0("MUL" );
1819 outline1("STD %s", address_displacement(_environment, _other, "2") );
1820
1821 outline0("LDA <MATHPTR1" );
1822 outline0("LDB <MATHPTR2" );
1823 outline0("MUL" );
1824 outline0("TFR D, X" );
1825
1826 outline0("LDA <MATHPTR0" );
1827 outline0("LDB <MATHPTR3" );
1828 outline0("MUL" );
1829 outline0("LEAX D, X" );
1830
1831 outline0("TFR X, D" );
1832
1833 outline1("ADDB %s", address_displacement(_environment, _other, "2") );
1834 outline1("STB %s", address_displacement(_environment, _other, "2") );
1835
1836 outline1("ADDA %s", address_displacement(_environment, _other, "1") );
1837 outline1("STA %s", address_displacement(_environment, _other, "1") );
1838
1839 if ( _signed ) {
1840 outline0("LDA <TMPPTR" );
1841 outline0("CMPA #0" );
1842 outline1("BEQ %sdonex", label );
1843 outline1("LDA %s", _other );
1844 outline0("EORA #$FF" );
1845 outline1("STA %s", _other );
1846 outline1("LDA %s", address_displacement(_environment, _other, "1") );
1847 outline0("EORA #$FF" );
1848 outline1("STA %s", address_displacement(_environment, _other, "1") );
1849 outline1("LDA %s", address_displacement(_environment, _other, "2") );
1850 outline0("EORA #$FF" );
1851 outline1("STA %s", address_displacement(_environment, _other, "2") );
1852 outline1("LDA %s", address_displacement(_environment, _other, "3") );
1853 outline0("EORA #$FF" );
1854 outline1("STA %s", address_displacement(_environment, _other, "3") );
1855 outline1("LDA %s", address_displacement(_environment, _other, "3") );
1856 outline0("ADDA #1" );
1857 outline1("STA %s", address_displacement(_environment, _other, "3") );
1858 outline1("LDA %s", address_displacement(_environment, _other, "2") );
1859 outline0("ADDA #0" );
1860 outline1("STA %s", address_displacement(_environment, _other, "2") );
1861 outline1("LDA %s", address_displacement(_environment, _other, "1") );
1862 outline0("ADDA #0" );
1863 outline1("STA %s", address_displacement(_environment, _other, "1") );
1864 outline1("LDA %s", _other );
1865 outline0("ADDA #0" );
1866 outline1("STA %s", _other );
1867 outhead1("%sdonex", label );
1868 }
1869
1870 embedded( cpu_math_mul_16bit_to_32bit, src_hw_6809_cpu_math_mul_16bit_to_32bit_asm );
1871
1872 outline1("LDD %s", _destination );
1873 outline1("LDX %s", _source );
1874
1875 if ( _signed ) {
1876 outline0("JSR CPUMATHMUL16BITTO32BIT_SIGNED" );
1877 } else {
1878 outline0("JSR CPUMATHMUL16BITTO32BIT" );
1879 }
1880
1881 outline1("STX %s", _other );
1882 outline1("STD %s", address_displacement(_environment, _other, "2") );
1883
1884 done( )
1885
1886}
1887
1888void cpu_math_mul_nbit_to_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _bits ) {
1889
1891
1892 int i;
1893
1894 char afterLabel[MAX_TEMPORARY_STORAGE]; sprintf( afterLabel, "%safter", label);
1895 char destination[MAX_TEMPORARY_STORAGE]; sprintf( destination, "CPUMATHMULNBITTONBIT%d_DESTINATION", (_bits>>3));
1896 char source[MAX_TEMPORARY_STORAGE]; sprintf( source, "CPUMATHMULNBITTONBIT%d_SOURCE", (_bits>>3));
1897 char other[MAX_TEMPORARY_STORAGE]; sprintf( other, "CPUMATHMULNBITTONBIT%d_OTHER", (_bits>>3));
1898
1899 // no_inline( cpu_math_mul_nbit_to_nbit )
1900
1901 // embedded( cpu_math_mul_nbit_to_nbit, src_hw_6502_cpu_math_mul_nbit_to_nbit_asm )
1902
1903 if ( ! _environment->cpuOptimization.cpu_math_mul_nbit_to_nbit[_bits>>3] ) {
1904
1905 outline1("JMP %s", afterLabel );
1906
1907 outhead2("CPUMATHMULNBITTONBIT%d_SOURCE rzb %d", _bits>>3, _bits>>3 );
1908 outhead2("CPUMATHMULNBITTONBIT%d_DESTINATION rzb %d", _bits>>3, _bits>>3 );
1909 outhead2("CPUMATHMULNBITTONBIT%d_OTHER rzb %d", _bits>>3, _bits>>3 );
1910
1911 outhead1("CPUMATHMULNBITTONBIT%d", _bits>>3);
1912 outline0("LDA #$00");
1913 for( i=0; i<(_bits>>3); ++i ) {
1914 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
1915 outline1("STA %s", address_displacement( _environment, other, offset ) );
1916 }
1917 outline1("LDB #$%2.2x", _bits );
1918
1919 outhead1("CPUMATHMULNBITTONBIT%dL1", _bits>>3);
1920
1921 // The process of multiplying binary numbers is similar and easier to do than
1922 // decimal multiplication as binary numbers consist of only two digits which
1923 // are 0 and 1. The method of multiplying binary numbers is given below. The
1924 // same set of rules also apply to binary numbers with a decimal point. Let
1925 // us take the example of multiplying (11101) and (1001).
1926 //
1927 // The decimal equivalent of (11101) is 29 and the decimal equivalent
1928 // of (1001) is 9. Now let us multiply these numbers.
1929
1930 // Step 1: Write down the multiplicand (11101) and the multiplier (1001)
1931 // one below the other in proper positions.
1932
1933 char multiplyByBit0Label[MAX_TEMPORARY_STORAGE]; sprintf( multiplyByBit0Label, "%sb%dbit0", label, _bits>>3 );
1934
1935 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", 0 );
1936
1937 outline1("LSR %s", address_displacement( _environment, destination, offset ) );
1938 for( i=1; i<(_bits>>3); ++i ) {
1939 sprintf( offset, "%d", i );
1940 outline1("ROR %s", address_displacement( _environment, destination, offset ) );
1941 }
1942 outline1("LBCC %s", multiplyByBit0Label );
1943
1944 // Step 2: Multiply the rightmost digit or the least significant bit (LSB)
1945 // of the multiplier (1) with all the digits of the multiplicand (11101).
1946
1947 outline0("ANDCC #$FE" );
1948 for( i=(_bits>>3)-1; i>-1; --i ) {
1949 sprintf( offset, "%d", i );
1950 outline1("LDA %s", address_displacement( _environment, source, offset ) );
1951 outline1("ADCA %s", address_displacement( _environment, other, offset ) );
1952 outline1("STA %s", address_displacement( _environment, other, offset ) );
1953 }
1954
1955 // Step 3: Add a place holder of '0' or 'X' before multiplying the next
1956 // higher order digit of the multiplier& with the multiplicand.
1957
1958 outhead1("%s", multiplyByBit0Label);
1959
1960 outline0("ANDCC #$FE" );
1961 sprintf( offset, "%d", (_bits>>3)-1 );
1962 outline1("ASL %s", address_displacement( _environment, source, offset ) );
1963 for( i=(_bits>>3)-2; i>-1; --i ) {
1964 sprintf( offset, "%d", i );
1965 outline1("ROL %s", address_displacement( _environment, source, offset ) );
1966 }
1967
1968 // Step 4: Repeat the same process for all the next higher-order digits
1969 // until we reach the most significant bit (MSB) which is the left-most
1970 // digit of the multiplicand with the multiplier.
1971
1972 outline0("DECB" );
1973 outline1("BEQ CPUMATHMULNBITTONBIT%dL1x", (_bits>>3) );
1974 outline1("JMP CPUMATHMULNBITTONBIT%dL1", (_bits>>3) );
1975 outhead1("CPUMATHMULNBITTONBIT%dL1x", (_bits>>3) );
1976
1977 outline0("RTS" );
1978
1979 // Step 5: The product obtained in each row is called the partial product.
1980 // Finally, add all the partial products. To add all the binary numbers
1981 // use the rules of binary addition.
1982
1983 // (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)
1984 outhead1("%s", afterLabel );
1985
1986 }
1987
1988 for( i=0; i<(_bits>>3); ++i ) {
1989 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
1990 outline1("LDA %s", address_displacement( _environment, _source, offset ) );
1991 outline1("STA %s", address_displacement( _environment, source, offset ) );
1992 outline1("LDA %s", address_displacement( _environment, _destination, offset ) );
1993 outline1("STA %s", address_displacement( _environment, destination, offset ) );
1994 }
1995 outline1("JSR CPUMATHMULNBITTONBIT%d", _bits >> 3 );
1996 for( i=0; i<(_bits>>3); ++i ) {
1997 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
1998 outline1("LDA %s", address_displacement( _environment, other, offset ) );
1999 if ( _other ) {
2000 outline1("STA %s", address_displacement( _environment, _other, offset ) );
2001 } else {
2002 outline1("STA %s", address_displacement( _environment, _destination, offset ) );
2003 }
2004 }
2005
2006 // done()
2007
2008}
2009
2010
2011void cpu_math_div_16bit_to_16bit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _signed ) {
2012
2014
2016
2017 if ( _signed ) {
2018
2019 outline1("LDA %s", _source );
2020 outline1("EORA %s", _destination );
2021 outline0("ANDA #$80" );
2022 outline0("PSHS A");
2023
2024 outline1("LDA %s", _source );
2025 outline0("ANDA #$80" );
2026 outline1("BEQ %ssecond", label );
2027 outline0("ANDCC #$FE" );
2028 outline1("LDA %s", _source );
2029 outline0("EORA #$ff" );
2030 outline0("STA <MATHPTR0" );
2031 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2032 outline0("EORA #$ff" );
2033 outline0("STA <MATHPTR1" );
2034 outline0("ANDCC #$FE" );
2035 outline0("LDD <MATHPTR0" );
2036 outline0("ADDD #1" );
2037 outline0("STD <MATHPTR0" );
2038 outline1("JMP %ssecond2", label );
2039 outhead1("%ssecond", label );
2040 outline1("LDD %s", _source );
2041 outline0("STD <MATHPTR0");
2042 outline1("JMP %ssecond2", label );
2043
2044 outhead1("%ssecond2", label );
2045 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2046 outline0("ANDA #$80" );
2047 outline1("BEQ %sthird", label );
2048 outline0("ANDCC #$FE" );
2049 outline1("LDA %s", _destination );
2050 outline0("EORA #$ff" );
2051 outline0("STA <MATHPTR2" );
2052 outline1("LDA %s", address_displacement(_environment, _destination, "1") );
2053 outline0("EORA #$ff" );
2054 outline0("STA <MATHPTR3" );
2055 outline0("ANDCC #$FE" );
2056 outline0("LDD <MATHPTR2" );
2057 outline0("ADDD #1" );
2058 outline0("STD <MATHPTR2" );
2059 outline1("JMP %sthird2", label );
2060 outhead1("%sthird", label );
2061 outline1("LDD %s", _destination );
2062 outline0("STD <MATHPTR2");
2063 outline1("JMP %sthird2", label );
2064
2065 outhead1("%sthird2", label );
2066
2067 outline0("LDX <MATHPTR0" );
2068 outline0("LDY <MATHPTR2" );
2069
2070 outhead1("%sDIVXY", label);
2071 outline0("PSHS Y,X,D,CC" );
2072 outline0("LDB #$10" );
2073 outline0("PSHS B" );
2074 outline0("CLRB" );
2075 outline0("CLRA" );
2076 outhead1("%sDIVLP", label);
2077 outline0("ASL 5,S" );
2078 outline0("ROL 4,S" );
2079 outline0("ROLB" );
2080 outline0("ROLA" );
2081 outline0("CMPD 6,S" );
2082 outline1("BLO %sDIVLT", label );
2083 outline0("SUBD 6,S" );
2084 outline0("INC 5,S" );
2085 outhead1("%sDIVLT", label);
2086 outline0("DEC ,S" );
2087 outline1("BNE %sDIVLP", label );
2088 outline0("STD 6,S" );
2089 outline0("LEAS 1,S" );
2090 outline0("PULS Y,X,D,CC" );
2091
2092 outline1("STX %s", _other );
2093 outline1("STY %s", _other_remainder );
2094
2095 outline0("PULS A");
2096 outline0("ANDA #$80");
2097 outline1("BEQ %sdone", label);
2098 outline1("LDA %s", _other );
2099 outline0("EORA #$ff" );
2100 outline1("STA %s", _other );
2101 outline1("LDA %s", address_displacement(_environment, _other, "1") );
2102 outline0("EORA #$ff" );
2103 outline1("STA %s", address_displacement(_environment, _other, "1") );
2104 outline0("ANDCC #$FE" );
2105 outline1("LDD %s", _other );
2106 outline0("ADDD #1" );
2107 outline1("STD %s", _other );
2108 outhead1("%sdone", label );
2109
2110 } else {
2111
2112 outline1("LDX %s", _source );
2113 outline1("LDY %s", _destination );
2114 outhead1("%sDIVXY", label);
2115 outline0("PSHS Y,X,D,CC" );
2116 outline0("LDB #$10" );
2117 outline0("PSHS B" );
2118 outline0("CLRB" );
2119 outline0("CLRA" );
2120 outhead1("%sDIVLP", label);
2121 outline0("ASL 5,S" );
2122 outline0("ROL 4,S" );
2123 outline0("ROLB" );
2124 outline0("ROLA" );
2125 outline0("CMPD 6,S" );
2126 outline1("BLO %sDIVLT", label );
2127 outline0("SUBD 6,S" );
2128 outline0("INC 5,S" );
2129 outhead1("%sDIVLT", label);
2130 outline0("DEC ,S" );
2131 outline1("BNE %sDIVLP", label );
2132 outline0("STD 6,S" );
2133 outline0("LEAS 1,S" );
2134 outline0("PULS Y,X,D,CC" );
2135 outline1("STX %s", _other );
2136 outline1("STY %s", _other_remainder );
2137 }
2138
2139 embedded( cpu_math_div_16bit_to_16bit, src_hw_6809_cpu_math_div_16bit_to_16bit_asm );
2140
2141 outline1("LDD %s", _source );
2142 outline1("LDX %s", _destination );
2143 if ( _signed ) {
2144 outline0("JSR CPUMATHDIV16BITTO16BIT_SIGNED" );
2145 } else {
2146 outline0("JSR CPUMATHDIV16BITTO16BIT" );
2147 }
2148 outline1("STX %s", _other_remainder );
2149 outline1("STD %s", _other );
2150
2151 done( )
2152
2153}
2154
2155void cpu_math_div_16bit_to_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _signed ) {
2156
2158
2160
2161 if ( _signed ) {
2162
2163 outline1("LDA %s", _source );
2164 outline1("EORA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2165 outline0("ANDA #$80" );
2166 outline0("PSHS A");
2167
2168 outline1("LDA %s", _source );
2169 outline0("ANDA #$80" );
2170 outline1("BEQ %ssecond", label );
2171 outline0("ANDCC #$FE" );
2172 outline1("LDA %s", _source );
2173 outline0("EORA #$ff" );
2174 outline0("STA <MATHPTR0" );
2175 outline1("LDA %s", address_displacement(_environment, _source, "1") );
2176 outline0("EORA #$ff" );
2177 outline0("STA <MATHPTR1" );
2178 outline0("ANDCC #$FE" );
2179 outline0("LDD <MATHPTR0" );
2180 outline0("ADDD #1" );
2181 outline0("STD <MATHPTR0" );
2182 outline1("JMP %ssecond2", label );
2183 outhead1("%ssecond", label );
2184 outline1("LDD %s", _source );
2185 outline0("STD <MATHPTR0");
2186 outline1("JMP %ssecond2", label );
2187
2188 outhead1("%ssecond2", label );
2189 outline1("LDA #$%2.2x", (unsigned char)((_destination)&0xff) );
2190 outline0("ANDA #$80" );
2191 outline1("BEQ %sthird", label );
2192 outline0("ANDCC #$FE" );
2193 outline1("LDA %s", _destination );
2194 outline0("EORA #$ff" );
2195 outline0("STA <MATHPTR2" );
2196 outline1("LDA #$%2.2x", (unsigned char)((_destination>>8)&0xff) );
2197 outline0("EORA #$ff" );
2198 outline0("STA <MATHPTR3" );
2199 outline0("ANDCC #$FE" );
2200 outline0("LDD <MATHPTR2" );
2201 outline0("ADDD #1" );
2202 outline0("STD <MATHPTR2" );
2203 outline1("JMP %sthird2", label );
2204 outhead1("%sthird", label );
2205 outline1("LDD #$%4.4x", _destination );
2206 outline0("STD <MATHPTR2");
2207 outline1("JMP %sthird2", label );
2208
2209 outhead1("%sthird2", label );
2210
2211 outline0("LDX <MATHPTR0" );
2212 outline0("LDY <MATHPTR2" );
2213
2214 outhead1("%sDIVXY", label);
2215 outline0("PSHS Y,X,D,CC" );
2216 outline0("LDB #$10" );
2217 outline0("PSHS B" );
2218 outline0("CLRB" );
2219 outline0("CLRA" );
2220 outhead1("%sDIVLP", label);
2221 outline0("ASL 5,S" );
2222 outline0("ROL 4,S" );
2223 outline0("ROLB" );
2224 outline0("ROLA" );
2225 outline0("CMPD 6,S" );
2226 outline1("BLO %sDIVLT", label );
2227 outline0("SUBD 6,S" );
2228 outline0("INC 5,S" );
2229 outhead1("%sDIVLT", label);
2230 outline0("DEC ,S" );
2231 outline1("BNE %sDIVLP", label );
2232 outline0("STD 6,S" );
2233 outline0("LEAS 1,S" );
2234 outline0("PULS Y,X,D,CC" );
2235
2236 outline1("STX %s", _other );
2237 outline1("STY %s", _other_remainder );
2238
2239 outline0("PULS A");
2240 outline0("ANDA #$80");
2241 outline1("BEQ %sdone", label);
2242 outline1("LDA %s", _other );
2243 outline0("EORA #$ff" );
2244 outline1("STA %s", _other );
2245 outline1("LDA %s", address_displacement(_environment, _other, "1") );
2246 outline0("EORA #$ff" );
2247 outline1("STA %s", address_displacement(_environment, _other, "1") );
2248 outline0("ANDCC #$FE" );
2249 outline1("LDD %s", _other );
2250 outline0("ADDD #1" );
2251 outline1("STD %s", _other );
2252 outhead1("%sdone", label );
2253
2254 } else {
2255
2256 outline1("LDX %s", _source );
2257 outline1("LDY #$%4.4x", _destination );
2258 outhead1("%sDIVXY", label);
2259 outline0("PSHS Y,X,D,CC" );
2260 outline0("LDB #$10" );
2261 outline0("PSHS B" );
2262 outline0("CLRB" );
2263 outline0("CLRA" );
2264 outhead1("%sDIVLP", label);
2265 outline0("ASL 5,S" );
2266 outline0("ROL 4,S" );
2267 outline0("ROLB" );
2268 outline0("ROLA" );
2269 outline0("CMPD 6,S" );
2270 outline1("BLO %sDIVLT", label );
2271 outline0("SUBD 6,S" );
2272 outline0("INC 5,S" );
2273 outhead1("%sDIVLT", label);
2274 outline0("DEC ,S" );
2275 outline1("BNE %sDIVLP", label );
2276 outline0("STD 6,S" );
2277 outline0("LEAS 1,S" );
2278 outline0("PULS Y,X,D,CC" );
2279 outline1("STX %s", _other );
2280 outline1("STY %s", _other_remainder );
2281 }
2282
2283 embedded( cpu_math_div_16bit_to_16bit, src_hw_6809_cpu_math_div_16bit_to_16bit_asm );
2284
2285 outline1("LDD %s", _source );
2286 outline1("LDX #$%4.4x", _destination );
2287 if ( _signed ) {
2288 outline0("JSR CPUMATHDIV16BITTO16BIT_SIGNED" );
2289 } else {
2290 outline0("JSR CPUMATHDIV16BITTO16BIT" );
2291 }
2292 outline1("STX %s", _other_remainder );
2293 outline1("STD %s", _other );
2294
2295 done( )
2296
2297}
2298
2307void cpu_math_sub_16bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
2308
2309 inline( cpu_math_sub_16bit )
2310
2311 outline1("LDD %s", _source );
2312 outline1("SUBD %s", _destination);
2313 outline1("STD %s", _other ? _other : _destination );
2314
2316
2317}
2318
2319void cpu_math_sub_16bit_with_8bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
2320
2322
2323 outline1("LDD %s", _source );
2324 outline1("SUBB %s", _destination);
2325 outline0("SBCA #0");
2326 outline1("STD %s", _other ? _other : _destination );
2327
2329
2330}
2331
2339void cpu_math_complement_const_16bit( Environment * _environment, char *_source, int _value ) {
2340
2342
2343 outline1("LDD #$%4.4x", _value);
2344 outline1("SUBD %s", _source );
2345 outline1("STD %s", _source);
2346
2348
2349}
2350
2358void cpu_math_div2_const_16bit( Environment * _environment, char *_source, int _steps, int _signed, char * _remainder ) {
2359
2361
2363
2364 if ( _signed ) {
2365
2366 if ( _remainder ) {
2367 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
2368 outline0("ANDA #$01");
2369 outline1("STA %s", address_displacement( _environment, _remainder, "1" ) );
2370 }
2371 outline1("LDA %s", _source);
2372 outline0("ANDA #$80");
2373 outline1("BEQ %spos", label );
2374
2375 outline1("LDD %s", _source );
2376 outline0("ANDCC #$FE" );
2377 outline0("EORA #$FF" );
2378 outline0("EORB #$FF" );
2379 outline0("ADDD #1" );
2380
2381 outline1("JMP %sdone", label );
2382
2383 outhead1("%spos", label );
2384 outline1("LDD %s", _source );
2385
2386 outhead1("%sdone", label );
2387
2388 outline1("LDX #$%4.4x", _steps );
2389 outhead1("%sloop", label );
2390 outline0("ANDCC #$FE" );
2391 outline0("ASRA" );
2392 outline0("RORB" );
2393 outline0("LEAX -1, X");
2394 outline0("CMPX #0");
2395 outline1("BNE %sloop", label );
2396
2397 outline0("STD <MATHPTR0");
2398
2399 outline1("LDA %s", _source);
2400 outline0("ANDA #$80");
2401 outline1("BEQ %spos2", label );
2402
2403 outline0("LDD <MATHPTR0");
2404 outline0("ANDCC #$FE" );
2405 outline0("EORA #$FF" );
2406 outline0("EORB #$FF" );
2407 outline0("ADDD #1" );
2408
2409 outline1("JMP %sdone2", label );
2410
2411 outhead1("%spos2", label );
2412 outline0("LDD <MATHPTR0");
2413 outhead1("%sdone2", label );
2414 outline1("STD %s", _source );
2415
2416 } else {
2417
2418 if ( _remainder ) {
2419 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
2420 outline0("ANDA #$01");
2421 outline1("STA %s", address_displacement( _environment, _remainder, "1" ) );
2422 }
2423 outline1("LDD %s", _source );
2424 outline1("LDX #$%4.4x", _steps );
2425 outhead1("%sloop", label );
2426 outline0("ANDCC #$FE" );
2427 outline0("ASRA" );
2428 outline0("RORB" );
2429 outline0("LEAX -1, X");
2430 outline0("CMPX #0");
2431 outline1("BNE %sloop", label );
2432 outline1("STD %s", _source );
2433
2434 }
2435
2436 embedded( cpu_math_div2_const_16bit, src_hw_6809_cpu_math_div2_const_16bit_asm );
2437
2438 if ( _remainder ) {
2439 outline1("LDA %s", address_displacement( _environment, _source, "1" ) );
2440 outline0("ANDA #$01");
2441 outline1("STA %s", address_displacement( _environment, _remainder, "1" ) );
2442 }
2443 outline1("LDD %s", _source );
2444 outline1("LDX #$%4.4x", _steps );
2445
2446 if ( _signed ) {
2447 outline0("JSR CPUMATHDIV2CONST16BIT_SIGNED");
2448 } else {
2449 outline0("JSR CPUMATHDIV2CONST16BIT");
2450 }
2451 outline1("STD %s", _source );
2452
2453 done( )
2454
2455}
2456
2464void cpu_math_mul2_const_16bit( Environment * _environment, char *_source, int _steps, int _signed ) {
2465 int i;
2466
2468
2469 outline1("LDD %s", _source );
2470 if ( !_environment->cpuOptimization.cpu_math_mul2_const_16bit_generated[_steps] ) {
2471
2472 _environment->cpuOptimization.cpu_math_mul2_const_16bit_generated[_steps] = 1;
2473
2474 MAKE_LABEL;
2475
2476 outline1("BRA %s", label);
2477 outhead1("cpu_math_mul2_const_16bit_%d", _steps);
2478 for(i=0; i<_steps; ++i) {
2479 outline0("LSLB" );
2480 outline0("ROLA" );
2481 }
2482 outline0("RTS");
2483 outhead1("%s", label);
2484
2485 }
2486 outline1("JSR cpu_math_mul2_const_16bit_%d", _steps);
2487 outline1("STD %s", _source );
2488
2490
2491}
2492
2500void cpu_math_and_const_16bit( Environment * _environment, char *_source, int _mask ) {
2501
2502 inline( cpu_math_and_const_16bit )
2503
2504 outline1("LDD %s", _source );
2505 outline1("ANDA #$%2.2x", ( _mask >> 8 ) & 0xff );
2506 outline1("ANDB #$%2.2x", ( _mask & 0xff ) );
2507 outline1("STD %s", _source );
2508
2510
2511}
2512
2513/*****************************************************************************
2514 * 32 BIT MANIPULATION
2515 ****************************************************************************/
2516
2524void cpu_move_32bit( Environment * _environment, char *_source, char *_destination ) {
2525
2526 inline( cpu_move_32bit )
2527
2528 outline1("LDD %s", _source );
2529 outline1("STD %s", _destination );
2530 outline1("LDD %s", address_displacement(_environment, _source, "2") );
2531 outline1("STD %s", address_displacement(_environment, _destination, "2") );
2532
2534
2535}
2536
2544void cpu_store_32bit( Environment * _environment, char *_destination, int _value ) {
2545
2546 inline( cpu_store_32bit )
2547
2548 outline1("LDD #$%4.4x", ( _value >> 16 ) & 0xffff );
2549 outline1("STD %s", _destination );
2550 if((( _value >> 16 ) & 0xffff) != ( _value & 0xffff ))
2551 outline1("LDD #$%4.4x", ( _value & 0xffff ) );
2552 outline1("STD %s", address_displacement(_environment, _destination, "2") );
2553
2555
2556}
2557
2558void cpu_math_div_32bit_to_16bit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _signed ) {
2559
2560 cpu_math_div_16bit_to_16bit( _environment, address_displacement( _environment, _source, "2" ), _destination, _other, _other_remainder, _signed );
2561
2562 // no_inline( cpu_math_div_32bit_to_16bit )
2563
2564 // embedded( cpu_math_div_32bit_to_16bit, src_hw_6809_cpu_math_div_32bit_to_16bit_asm );
2565
2566 // outline1("LDD %s", _source );
2567 // outline0("STD CPUMATHDIV32BITTO16DIVISOR" );
2568 // outline1("LDD %s", address_displacement( _environment, _source, "2"));
2569 // outline0("STD CPUMATHDIV32BITTO16DIVISOR+2" );
2570
2571 // outline1("LDD %s", _destination );
2572 // outline0("STD CPUMATHDIV32BITTO16DIVIDEND" );
2573 // outline1("LDD %s", address_displacement( _environment, _destination, "2"));
2574 // outline0("STD CPUMATHDIV32BITTO16DIVIDEND+2" );
2575
2576 // outline0("LDX CPUMATHDIV32BITTO16DIVISOR" );
2577 // outline0("LDY CPUMATHDIV32BITTO16DIVIDEND" );
2578 // outline0("LDA #4" );
2579 // outline0("PSHS A, X, Y" );
2580 // if ( _signed ) {
2581 // outline0("JSR CPUMATHDIV32BITTO16BIT_SIGNED" );
2582 // } else {
2583 // outline0("JSR CPUMATHDIV32BITTO16BIT" );
2584 // }
2585
2586 // if ( _other_remainder ) {
2587 // outline0("LDD ,X" );
2588 // outline1("STD %s", _other_remainder );
2589 // outline0("LDD 2,X" );
2590 // outline1("STD %s", address_displacement( _environment, _other_remainder, "2" ) );
2591 // }
2592
2593 // outline0("LDD CPUMATHDIV32BITTO16DIVIDEND" );
2594 // outline1("STD %s", _other );
2595
2596 // done( )
2597
2598}
2599
2600void cpu_math_div_nbit_to_nbit( Environment * _environment, char *_source, char *_destination, char *_other, char * _other_remainder, int _bits ) {
2601
2603
2604 int i;
2605
2607
2608 char afterLabel[MAX_TEMPORARY_STORAGE]; sprintf( afterLabel, "%safter", label );
2609 char skipLabel[MAX_TEMPORARY_STORAGE]; sprintf( skipLabel, "%sskip", label );
2610 char skip2Label[MAX_TEMPORARY_STORAGE]; sprintf( skip2Label, "%sskipb", label );
2611 char skip3Label[MAX_TEMPORARY_STORAGE]; sprintf( skip3Label, "%sskipc", label );
2612 char skip4Label[MAX_TEMPORARY_STORAGE]; sprintf( skip4Label, "%sskipd", label );
2613 char quotient[MAX_TEMPORARY_STORAGE]; sprintf( quotient, "CPUMATHDIVNBITTONBIT%d_QUOTIENT", _bits >> 3 );
2614 char divisor[MAX_TEMPORARY_STORAGE]; sprintf( divisor, "CPUMATHDIVNBITTONBIT%d_DIVISOR", _bits >> 3 );
2615 char dividend[MAX_TEMPORARY_STORAGE]; sprintf( dividend, "CPUMATHDIVNBITTONBIT%d_DIVIDEND", _bits >> 3 );
2616 char result1[MAX_TEMPORARY_STORAGE]; sprintf( result1, "CPUMATHDIVNBITTONBIT%d_RESULT1", _bits >> 3 );
2617 char result2[MAX_TEMPORARY_STORAGE]; sprintf( result2, "CPUMATHDIVNBITTONBIT%d_RESULT2", _bits >> 3 );
2618 char k[MAX_TEMPORARY_STORAGE]; sprintf( k, "CPUMATHDIVNBITTONBIT%d_K", _bits >> 3 );
2619
2620 if ( ! _environment->cpuOptimization.cpu_math_div_nbit_to_nbit[_bits>>3] ) {
2621
2622 cpu_jump( _environment, afterLabel );
2623
2624 outhead2("%s rzb %d", quotient, _bits>>3 );
2625 outhead2("%s rzb %d", divisor, _bits>>3 );
2626 outhead2("%s rzb %d", dividend, _bits>>3 );
2627 outhead1("%s fcb 0", k );
2628 outhead1("%s fcb 0", result1 );
2629 outhead1("%s fcb 0", result2 );
2630
2631 // public static long div(long dividend, long divisor) {
2632 // long quotient = 0;
2633
2634 outhead1("CPUMATHDIVNBITTONBIT%d", _bits>>3);
2635 outline0("LDA #$00");
2636 for( i=0; i<(_bits>>3); ++i ) {
2637 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2638 outline1("STA %s", address_displacement( _environment, quotient, offset ) );
2639 }
2640
2641 // int k = 0;
2642 cpu_store_8bit( _environment, k, 0 );
2643
2644 // while (divisor <= dividend && divisor > 0) {
2645
2646 cpu_label( _environment, label );
2647 cpu_less_than_nbit( _environment, divisor, dividend, result1, 1, _bits );
2648 cpu_greater_than_nbit_const( _environment, divisor, 0, result2, 0, _bits );
2649 cpu_and_8bit( _environment, result1, result2, result1 );
2650 cpu_compare_and_branch_8bit_const( _environment, result1, 0, skipLabel, 1 );
2651
2652 // divisor <<= 1;
2653
2654 cpu_math_mul2_const_nbit( _environment, divisor, 1, _bits );
2655
2656 // k++;
2657
2658 cpu_inc( _environment, k );
2659
2660 // }
2661
2662 cpu_jump( _environment, label );
2663
2664 cpu_label( _environment, skipLabel );
2665
2666 // while (k-- > 0) {
2667
2668 cpu_greater_than_8bit_const( _environment, k, 0, result1, 0, 1 );
2669 cpu_dec( _environment, k );
2670 cpu_compare_and_branch_8bit_const( _environment, result1, 0, skip2Label, 1 );
2671
2672 // divisor >>= 1;
2673
2674 cpu_math_div2_const_nbit( _environment, divisor, 1, _bits, NULL );
2675
2676 // if (divisor <= dividend) {
2677 cpu_less_than_nbit( _environment, divisor, dividend, result1, 1, _bits );
2678 cpu_compare_and_branch_8bit_const( _environment, result1, 0, skip3Label, 1 );
2679
2680 // dividend -= divisor;
2681
2682 cpu_math_sub_nbit( _environment, dividend, divisor, dividend, _bits );
2683
2684 // quotient = (quotient << 1) + 1;
2685 cpu_math_mul2_const_nbit( _environment, quotient, 1, _bits );
2686 cpu_inc_nbit( _environment, quotient, _bits );
2687
2688 // }
2689 cpu_jump( _environment, skip4Label );
2690 cpu_label( _environment, skip3Label );
2691 // else quotient <<= 1;
2692 cpu_math_mul2_const_nbit( _environment, quotient, 1, _bits );
2693 cpu_label( _environment, skip4Label );
2694 cpu_jump( _environment, skipLabel );
2695
2696 // }
2697 cpu_label( _environment, skip2Label );
2698 // return quotient;
2699 cpu_return( _environment );
2700
2701 cpu_label( _environment, afterLabel );
2702
2703 }
2704
2705 for( i=0; i<(_bits>>3); ++i ) {
2706 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2707 outline1("LDA %s", address_displacement( _environment, _source, offset ) );
2708 outline1("STA %s", address_displacement( _environment, dividend, offset ) );
2709 outline1("LDA %s", address_displacement( _environment, _destination, offset ) );
2710 outline1("STA %s", address_displacement( _environment, divisor, offset ) );
2711 }
2712 outline1("JSR CPUMATHDIVNBITTONBIT%d", _bits>>3);
2713
2714 for( i=0; i<(_bits>>3); ++i ) {
2715 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2716 if ( _other ) {
2717 outline1("LDA %s", address_displacement( _environment, quotient, offset ) );
2718 outline1("STA %s", address_displacement( _environment, _other, offset ) );
2719 } else {
2720 outline1("LDA %s", address_displacement( _environment, quotient, offset ) );
2721 outline1("STA %s", address_displacement( _environment, _destination, offset ) );
2722 }
2723 }
2724
2725 // }
2727
2728}
2729
2730void cpu_math_div_nbit_to_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _bits ) {
2731
2733
2734 int i;
2735
2737
2738 char afterLabel[MAX_TEMPORARY_STORAGE]; sprintf( afterLabel, "%safter", label );
2739 char data[MAX_TEMPORARY_STORAGE]; sprintf( data, "CPUMATHDIVNBITTONBITCONST%d_DATA", _bits >> 3 );
2740
2741 if ( ! _environment->cpuOptimization.cpu_math_div_nbit_to_nbit_const[_bits>>3] ) {
2742
2743 cpu_jump( _environment, afterLabel );
2744
2745 outhead2("%s: rzb %d", data, _bits>>3 );
2746
2747 cpu_label( _environment, afterLabel );
2748
2749 }
2750
2751 for( i=0; i<(_bits>>3); ++i ) {
2752 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2753 outline1("LDA #$%2.2x", (unsigned char)( (_destination >> (i*8)) & 0xff ) );
2754 outline1("STA %s", address_displacement( _environment, data, offset ) );
2755 }
2756 cpu_math_div_nbit_to_nbit( _environment, _source, data, _other, _other_remainder, _bits );
2757
2758 // }
2760
2761}
2762
2763void cpu_math_div_32bit_to_16bit_const( Environment * _environment, char *_source, int _destination, char *_other, char * _other_remainder, int _signed ) {
2764
2765 cpu_math_div_16bit_to_16bit_const( _environment, address_displacement( _environment, _source, "2" ), _destination, _other, _other_remainder, _signed );
2766
2767 // no_inline( cpu_math_div_32bit_to_16bit )
2768
2769 // embedded( cpu_math_div_32bit_to_16bit, src_hw_6809_cpu_math_div_32bit_to_16bit_asm );
2770
2771 // outline1("LDD %s", _source );
2772 // outline0("STD CPUMATHDIV32BITTO16DIVISOR" );
2773 // outline1("LDD %s", address_displacement( _environment, _source, "2"));
2774 // outline0("STD CPUMATHDIV32BITTO16DIVISOR+2" );
2775
2776 // outline1("LDD $%4.4x", ( ( _destination >> 2 ) & 0xffff ) );
2777 // outline0("STD CPUMATHDIV32BITTO16DIVIDEND" );
2778 // outline1("LDD $%4.4x", ( _destination & 0xffff ) );
2779 // outline0("STD CPUMATHDIV32BITTO16DIVIDEND+2" );
2780
2781 // outline0("LDX CPUMATHDIV32BITTO16DIVISOR" );
2782 // outline0("LDY CPUMATHDIV32BITTO16DIVIDEND" );
2783 // outline0("LDA #4" );
2784 // if ( _signed ) {
2785 // outline0("JSR CPUMATHDIV32BITTO16BIT_SIGNED" );
2786 // } else {
2787 // outline0("JSR CPUMATHDIV32BITTO16BIT" );
2788 // }
2789
2790 // if ( _other_remainder ) {
2791 // outline0("LDD ,X" );
2792 // outline1("STD %s", _other_remainder );
2793 // outline0("LDD 2,X" );
2794 // outline1("STD %s", address_displacement( _environment, _other_remainder, "2" ) );
2795 // }
2796
2797 // outline0("LDD CPUMATHDIV32BITTO16DIVIDEND" );
2798 // outline1("STD %s", _other );
2799
2800 // done( )
2801
2802}
2803
2813void cpu_compare_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive ) {
2814
2815 inline( cpu_compare_32bit )
2816
2818
2819 char sourceEffective[MAX_TEMPORARY_STORAGE]; sprintf(sourceEffective, "%s", address_displacement(_environment, _source, "2") );
2820 char destinationEffective[MAX_TEMPORARY_STORAGE]; sprintf(destinationEffective, "%s", address_displacement(_environment, _source, "2") );
2821
2822 if ( _positive ) {
2823
2824 cpu_compare_16bit( _environment, _source, _destination, _other, _positive );
2825
2826 outline1("LDB %s", _other );
2827 outline1("BEQ %sdone", label );
2828
2829 cpu_compare_16bit( _environment, sourceEffective, destinationEffective, _other, _positive );
2830
2831 } else {
2832
2833 cpu_compare_16bit( _environment, _source, _destination, _other, _positive );
2834
2835 outline1("LDB %s", _other );
2836 outline1("BNE %sdone", label );
2837
2838 cpu_compare_16bit( _environment, sourceEffective, destinationEffective, _other, _positive );
2839
2840 }
2841
2842 outhead1("%sdone", label );
2843
2845
2846}
2847
2848void cpu_compare_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _positive, int _bits ) {
2849
2851
2852 inline( cpu_compare_nbit )
2853
2854 for( int i=0; i<(_bits>>3); ++i ) {
2855 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2856 outline1("LDA %s", address_displacement(_environment, _source, offset));
2857 outline1("CMPA %s", address_displacement(_environment, _destination, offset));
2858 outline2("LBNE %s", label, i);
2859 }
2860 outline1("LDA #$%2.2x", 0xff*_positive);
2861 if ( _other ) {
2862 outline1("STA %s", _other);
2863 } else {
2864 outline1("STA %s", _destination);
2865 }
2866 outline1("JMP %s_2", label);
2867 outhead1("%s", label);
2868 outline1("LDA #$%2.2x", 0xff*(1-_positive));
2869 if ( _other ) {
2870 outline1("STA %s", _other);
2871 } else {
2872 outline1("STA %s", _destination);
2873 }
2874 outhead1("%s_2", label);
2875
2877
2878}
2879
2880void cpu_compare_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive, int _bits ) {
2881
2883
2884 int i;
2885
2886 inline( cpu_compare_nbit )
2887
2888 for( i=0; i<(_bits>>3); ++i ) {
2889 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
2890 outline1("LDA %s", address_displacement(_environment, _source, offset));
2891 outline1("CMPA #$%2.2x", (unsigned char) ( ( _destination >> (i*8) ) & 0xff ) );
2892 outline1("LBNE %s", label);
2893 }
2894 outline1("LDA #$%2.2x", 0xff*_positive);
2895 outline1("STA %s", _other);
2896 outline1("JMP %s_2", label);
2897 outhead1("%s", label);
2898 outline1("LDA #$%2.2x", 0xff*(1-_positive));
2899 outline1("STA %s", _other);
2900 outhead1("%s_2", label);
2901
2903
2904}
2905
2915void cpu_compare_32bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _positive ) {
2916
2917 inline( cpu_compare_32bit )
2918
2920
2921 char sourceEffective[MAX_TEMPORARY_STORAGE]; sprintf(sourceEffective, "%s", address_displacement(_environment, _source, "2") );
2922
2923 if ( _positive ) {
2924
2925 cpu_compare_16bit_const( _environment, _source, ((_destination>>16)&0xffff), _other, _positive );
2926
2927 outline1("LDB %s", _other );
2928 outline1("BEQ %sdone", label );
2929
2930 cpu_compare_16bit_const( _environment, sourceEffective, (_destination & 0xffff ), _other, _positive );
2931
2932 } else {
2933
2934 cpu_compare_16bit_const( _environment, _source, ((_destination>>16)&0xffff), _other, _positive );
2935
2936 outline1("LDB %s", _other );
2937 outline1("BNE %sdone", label );
2938
2939 cpu_compare_16bit_const( _environment, sourceEffective, (_destination&0xffff), _other, _positive );
2940
2941 }
2942
2943 outhead1("%sdone", label );
2944
2946
2947}
2948
2958void cpu_compare_and_branch_32bit_const( Environment * _environment, char *_source, int _destination, char *_label, int _positive ) {
2959
2961
2963
2964 outline1("LDX %s", _source);
2965 outline1("CMPX #$%4.4x", ( ( _destination >> 16 ) & 0xffff ) );
2966 if ( _positive ) {
2967 B(NE, label);
2968 } else {
2969 B(EQ, label);
2970 }
2971 outline1("LDX %s", address_displacement(_environment, _source, "2"));
2972 outline1("CMPX #$%4.4x", ( _destination & 0xffff ) );
2973 if ( _positive ) {
2974 B(EQ, _label);
2975 } else {
2976 B(NE, _label);
2977 }
2978 outhead1("%s", label);
2979
2981
2982}
2983
2993void cpu_less_than_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
2994
2995 inline( cpu_less_than_32bit )
2996
2998
2999 outline0("CLRA");
3000 outline1("LDX %s", _source);
3001 outline1("CMPX %s", _destination);
3002 outline1("BNE %shigh", label);
3003 outline1("LDX %s", address_displacement(_environment, _source, "2"));
3004 outline1("CMPX %s", address_displacement(_environment, _destination, "2"));
3005 outhead1("%shigh", label );
3006
3007 if ( _signed ) {
3008 if ( _equal ) {
3009 outline1("BGT %sdone", label);
3010 } else {
3011 outline1("BGE %sdone", label);
3012 }
3013 } else {
3014 if ( _equal ) {
3015 outline1("BHI %sdone", label);
3016 } else {
3017 outline1("BHS %sdone", label);
3018 }
3019 }
3020 outline0("DECA");
3021 outhead1("%sdone", label );
3022 outline1("STA %s", _other ? _other : _destination );
3023
3025
3026
3027}
3028
3029void cpu_less_than_32bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
3030
3032
3034
3035 outline0("CLRA");
3036 outline1("LDX %s", _source);
3037 outline1("CMPX #$%4.4x", ( ( _destination >> 16 ) & 0xffff ) );
3038 outline1("BNE %shigh", label);
3039 outline1("LDX %s", address_displacement(_environment, _source, "2"));
3040 outline1("CMPX #$%4.4x", ( _destination & 0xffff ) );
3041 outhead1("%shigh", label );
3042
3043 if ( _signed ) {
3044 if ( _equal ) {
3045 outline1("BGT %sdone", label);
3046 } else {
3047 outline1("BGE %sdone", label);
3048 }
3049 } else {
3050 if ( _equal ) {
3051 outline1("BHI %sdone", label);
3052 } else {
3053 outline1("BHS %sdone", label);
3054 }
3055 }
3056 outline0("DECA");
3057 outhead1("%sdone", label );
3058 outline1("STA %s", _other );
3059
3061
3062
3063}
3064
3065void cpu_less_than_nbit( Environment * _environment, char *_source, char * _destination, char *_other, int _equal, int _bits ) {
3066
3068
3069 int i;
3070
3071 inline( cpu_less_than_nbit )
3072
3073 for( i=0; i<(_bits>>3); ++i ) {
3074 char offset[MAX_TEMPORARY_STORAGE]; sprintf(offset, "%d", i );
3075 outline1("LDA %s", address_displacement(_environment, _destination, offset ) );
3076 outline1("LDB %s", address_displacement(_environment, _source, offset ) );
3077 outline1("CMPB %s", address_displacement(_environment, _destination, offset ) );
3078 outline1("LBCS %sbga", label );
3079 outline2("BEQ %snext%dx", label, i );
3080 outline1("JMP %sagb", label );
3081 outhead2("%snext%dx", label, i );
3082 }
3083
3084 outhead1("%sbge", label );
3085 if ( _equal ) {
3086 outline0("LDA #$ff" );
3087 } else {
3088 outline0("LDA #$00" );
3089 }
3090 outline1("STA %s", _other );
3091 outline1("BRA %sdone", label );
3092
3093 outhead1("%sbga", label );
3094 outline0("LDA #$ff" );
3095 outline1("STA %s", _other );
3096 outline1("BRA %sdone", label );
3097
3098 outhead1("%sagb", label );
3099 outline0("LDA #$00" );
3100 outline1("STA %s", _other );
3101 outline1("BRA %sdone", label );
3102
3103 outhead1("%sdone", label );
3104
3106
3107}
3108
3109void cpu_less_than_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _bits ) {
3110
3112
3113 int i;
3114
3115 inline( cpu_less_than_nbit_const )
3116
3117 for( i=0; i<(_bits>>3); ++i ) {
3118 char offset[MAX_TEMPORARY_STORAGE]; sprintf(offset, "%d", i );
3119 outline1("LDB %s", address_displacement(_environment, _source, offset ) );
3120 outline1("CMPB #$%2.2x", (unsigned char)((_destination>>(i*8))&0xff) );
3121 outline1("LBCS %sbga", label );
3122 outline2("BEQ %snext%dx", label, i );
3123 outline1("JMP %sagb", label );
3124 outhead2("%snext%dx", label, i );
3125 }
3126
3127 outhead1("%sbge", label );
3128 if ( _equal ) {
3129 outline0("LDA #$ff" );
3130 } else {
3131 outline0("LDA #$00" );
3132 }
3133 outline1("STA %s", _other );
3134 outline1("BRA %sdone", label );
3135
3136 outhead1("%sbga", label );
3137 outline0("LDA #$ff" );
3138 outline1("STA %s", _other );
3139 outline1("BRA %sdone", label );
3140
3141 outhead1("%sagb", label );
3142 outline0("LDA #$00" );
3143 outline1("STA %s", _other );
3144 outline1("BRA %sdone", label );
3145
3146 outhead1("%sdone", label );
3147
3149
3150}
3151
3161void cpu_greater_than_32bit( Environment * _environment, char *_source, char *_destination, char *_other, int _equal, int _signed ) {
3162
3163 inline( cpu_greater_than_32bit )
3164
3166
3167 outline0("CLRB");
3168 outline1("LDX %s", _source);
3169 outline1("CMPX %s", _destination);
3170 outline1("BNE %shigh", label);
3171 outline1("LDX %s", address_displacement(_environment, _source, "2"));
3172 outline1("CMPX %s", address_displacement(_environment, _destination, "2"));
3173 outhead1("%shigh", label );
3174
3175 if ( _signed ) {
3176 if ( _equal ) {
3177 outline1("BLT %sdone", label);
3178 } else {
3179 outline1("BLE %sdone", label);
3180 }
3181 } else {
3182 if ( _equal ) {
3183 outline1("BLO %sdone", label);
3184 } else {
3185 outline1("BLS %sdone", label);
3186 }
3187 }
3188
3189 outline0("DECB");
3190 outhead1("%sdone", label );
3191 outline1("STB %s", _other ? _other : _destination );
3192
3194
3195}
3196
3197void cpu_greater_than_32bit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _signed ) {
3198
3199 inline( cpu_greater_than_32bit )
3200
3202
3203 outline0("CLRB");
3204 outline1("LDX %s", _source);
3205 outline1("CMPX #$%4.4x", ( _destination >> 16 ) & 0xffff );
3206 outline1("BNE %shigh", label);
3207 outline1("LDX %s", address_displacement(_environment, _source, "2"));
3208 outline1("CMPX #$%4.4x", ( _destination & 0xffff ) );
3209 outhead1("%shigh", label );
3210
3211 if ( _signed ) {
3212 if ( _equal ) {
3213 outline1("BLT %sdone", label);
3214 } else {
3215 outline1("BLE %sdone", label);
3216 }
3217 } else {
3218 if ( _equal ) {
3219 outline1("BLO %sdone", label);
3220 } else {
3221 outline1("BLS %sdone", label);
3222 }
3223 }
3224
3225 outline0("DECB");
3226 outhead1("%sdone", label );
3227 outline1("STB %s", _other );
3228
3230
3231}
3232
3233void cpu_greater_than_nbit( Environment * _environment, char *_source, char * _destination, char *_other, int _equal, int _bits ) {
3234
3235 inline( cpu_greater_than_nbit )
3236
3237 cpu_less_than_nbit( _environment, _source, _destination, _other, !_equal, _bits );
3238 cpu_not_8bit( _environment, _other, _other );
3239
3241
3242}
3243
3244void cpu_greater_than_nbit_const( Environment * _environment, char *_source, int _destination, char *_other, int _equal, int _bits ) {
3245
3246 inline( cpu_greater_than_nbit )
3247
3248 cpu_less_than_nbit_const( _environment, _source, _destination, _other, !_equal, _bits );
3249 cpu_not_8bit( _environment, _other, _other );
3250
3252
3253}
3254
3263void cpu_math_add_32bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
3264
3265 inline( cpu_math_add_32bit )
3266
3268
3269 outline1("LDD %s", address_displacement(_environment, _source, "2"));
3270 outline1("LDX #%s", _destination);
3271 outline0("ADDD 2,X");
3272 if ( _other ) {
3273 outline1("STD %s", address_displacement(_environment, _other, "2"));
3274 } else {
3275 outline0("STD 2,X");
3276 }
3277 outline1("LDD %s", _source);
3278 outline0("ADCB 1,X");
3279 outline0("ADCA ,X");
3280 outline1("STD %s", _other ? _other : ",X" );
3281
3283
3284}
3285
3286void cpu_math_add_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _bits ) {
3287
3288 inline( cpu_math_add_nbit )
3289
3290 outline0("ANDCC #$FE");
3291 for( int i=0; i<(_bits>>3); ++i ) {
3292 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", (_bits>>3)-i-1 );
3293 outline1("LDA %s", address_displacement(_environment, _source, offset));
3294 outline1("ADCA %s", address_displacement(_environment, _destination, offset));
3295 if ( _other ) {
3296 outline1("STA %s", address_displacement(_environment, _other, offset));
3297 } else {
3298 outline1("STA %s", address_displacement(_environment, _destination, offset));
3299 }
3300 }
3302
3303}
3304
3305void cpu_math_add_32bit_const( Environment * _environment, char *_source, int _destination, char *_other ) {
3306
3307 inline( cpu_math_add_32bit_const )
3308
3310
3311 outline1("LDD %s", address_displacement(_environment, _source, "2"));
3312 outline1("ADDD #$%4.4x", ( _destination & 0xffff ) );
3313 outline1("STD %s", address_displacement(_environment, _other, "2"));
3314 outline1("LDD %s", _source);
3315 outline1("ADDD #$%4.4x", ( ( _destination >> 16 ) & 0xffff ) );
3316 if ( ( ( _destination >> 16 ) & 0x8000 ) ) {
3317 outline0("ADDD #1" );
3318 }
3319 outline1("STD %s", _other ? _other : ",X" );
3320
3322
3323}
3324
3332void cpu_math_double_32bit( Environment * _environment, char *_source, char *_other, int _signed ) {
3333
3334 inline( cpu_math_double_32bit )
3335
3336 if(_other) {
3337 outline1("LDD %s", address_displacement(_environment, _source, "2"));
3338 outline0("LSLB");
3339 outline0("ROLA");
3340 outline1("STD %s", address_displacement(_environment, _other, "2"));
3341 outline1("LDD %s", _source);
3342 outline0("ROLB");
3343 outline0("ROLA");
3344 outline1("STD %s", _other);
3345 } else {
3346 outline1("LSL %s", address_displacement(_environment, _source, "3"));
3347 outline1("ROL %s", address_displacement(_environment, _source, "2"));
3348 outline1("ROL %s", address_displacement(_environment, _source, "1"));
3349 outline1("ROL %s", _source);
3350 }
3351
3353
3354}
3355
3364void cpu_math_sub_32bit( Environment * _environment, char *_source, char *_destination, char *_other ) {
3365
3366 inline( cpu_math_sub_32bit )
3367
3368 outline1("LDD %s", address_displacement(_environment, _source, "2"));
3369 outline1("LDX #%s", _destination);
3370 outline0("SUBD 2,X");
3371 if ( _other ) {
3372 outline1("STD %s", address_displacement(_environment, _other, "2"));
3373 } else {
3374 outline0("STD 2,X");
3375 }
3376 outline1("LDD %s", _source);
3377 outline0("SBCB 1,X");
3378 outline0("SBCA ,X");
3379 outline1("STD %s", _other ? _other : ",X");
3380
3382
3383}
3384
3385void cpu_math_sub_nbit( Environment * _environment, char *_source, char *_destination, char *_other, int _bits ) {
3386
3387 inline( cpu_math_sub_nbit )
3388
3389 outline0("ANDCC #$FE");
3390 for( int i=0; i<(_bits)>>3; ++i ) {
3391 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", (_bits>>3)-i-1 );
3392 outline1("LDA %s", address_displacement(_environment, _source, offset));
3393 outline1("SBCA %s", address_displacement(_environment, _destination, offset));
3394 if ( _other ) {
3395 outline1("STA %s", address_displacement(_environment, _other, offset));
3396 } else {
3397 outline1("STA %s", address_displacement(_environment, _destination, offset));
3398 }
3399 }
3400
3402
3403}
3404
3412void cpu_math_complement_const_32bit( Environment * _environment, char *_source, int _value ) {
3413
3415
3416 outline1("LDX #%s", _source);
3417 outline1("LDD #$%4.4x", ( _value ) & 0xffff );
3418 outline0("SUBD 2,X");
3419 outline0("STD 2,X");
3420 outline1("LDD #$%4.4x", ( _value>>16 ) & 0xffff );
3421 outline0("SBCB 1,X");
3422 outline0("SBCA ,X");
3423 outline0("STD ,X");
3424
3426
3427}
3428
3436void cpu_math_div2_const_32bit( Environment * _environment, char *_source, int _steps, int _signed, char * _remainder ) {
3437
3439
3441
3442 if ( _signed ) {
3443
3444 if ( _remainder ) {
3445 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
3446 outline0("ANDA #$01");
3447 outline1("STA %s", address_displacement( _environment, _remainder, "3" ) );
3448 }
3449 outline1("LDA %s", _source);
3450 outline0("ANDA #$80");
3451 outline1("BEQ %spos", label );
3452
3453 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3454 outline0("ANDCC #$FE" );
3455 outline0("EORA #$FF" );
3456 outline0("EORB #$FF" );
3457 outline0("STD <MATHPTR2" );
3458 outline1("LDD %s", _source );
3459 outline0("ANDCC #$FE" );
3460 outline0("EORA #$FF" );
3461 outline0("EORB #$FF" );
3462 outline0("STD <MATHPTR0" );
3463 outline0("LDD <MATHPTR2" );
3464 outline0("ANDCC #$FE" );
3465 outline0("ADDD #1" );
3466 outline0("STD <MATHPTR2" );
3467 outline0("LDD <MATHPTR0" );
3468 outline0("ADDD #0" );
3469 outline0("STD <MATHPTR0" );
3470
3471 outline1("JMP %sdone", label );
3472
3473 outhead1("%spos", label );
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("ASR <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 outline1("LDA %s", _source);
3493 outline0("ANDA #$80");
3494 outline1("BEQ %spos2", label );
3495
3496 outline0("ANDCC #$FE" );
3497 outline0("LDD <MATHPTR2" );
3498 outline0("EORA #$FF" );
3499 outline0("EORB #$FF" );
3500 outline0("STD <MATHPTR2" );
3501 outline0("LDD <MATHPTR0" );
3502 outline0("EORA #$FF" );
3503 outline0("EORB #$FF" );
3504 outline0("STD <MATHPTR0" );
3505
3506 outline0("ANDCC #$FE" );
3507 outline0("LDD <MATHPTR2" );
3508 outline0("ADDD #1" );
3509 outline1("STD %s", address_displacement(_environment, _source, "2") );
3510 outline0("LDD <MATHPTR0" );
3511 outline0("ADDD #0" );
3512 outline1("STD %s", _source );
3513
3514 outline1("JMP %sdone2", label );
3515
3516 outhead1("%spos2", label );
3517 outline0("LDD <MATHPTR3" );
3518 outline1("STD %s", address_displacement(_environment, _source, "3") );
3519 outline0("LDD <MATHPTR2" );
3520 outline1("STD %s", address_displacement(_environment, _source, "2") );
3521 outline0("LDD <MATHPTR1" );
3522 outline1("STD %s", address_displacement(_environment, _source, "1") );
3523 outline0("LDD <MATHPTR0" );
3524 outline1("STD %s", _source );
3525 outhead1("%sdone2", label );
3526
3527 } else {
3528
3529 if ( _remainder ) {
3530 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
3531 outline0("ANDA #$01");
3532 outline1("STA %s", address_displacement( _environment, _remainder, "3" ) );
3533 }
3534 outline1("LDD %s", _source );
3535 outline0("STD <MATHPTR0" );
3536 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3537 outline0("STD <MATHPTR2" );
3538
3539 outhead1("%sdone", label );
3540
3541 outline1("LDX #$%4.4x", _steps );
3542 outhead1("%sloop", label );
3543 outline0("ANDCC #$FE" );
3544 outline0("LSR <MATHPTR0" );
3545 outline0("ROR <MATHPTR1" );
3546 outline0("ROR <MATHPTR2" );
3547 outline0("ROR <MATHPTR3" );
3548 outline0("LEAX -1, X");
3549 outline0("CMPX #0");
3550 outline1("BNE %sloop", label );
3551
3552 outline0("LDD <MATHPTR2" );
3553 outline1("STD %s", address_displacement(_environment, _source, "2") );
3554 outline0("LDD <MATHPTR0" );
3555 outline1("STD %s", _source );
3556
3557 }
3558
3560
3561}
3562
3563void cpu_math_div2_const_nbit( Environment * _environment, char *_source, int _steps, int _bits, char * _remainder ) {
3564
3565 inline( cpu_math_div2_const_nbit )
3566
3568
3569 if ( _remainder ) {
3570 outline1("LDA %s", _source);
3571 outline0("ANDA #$01" );
3572 outline1("STA %s", _remainder);
3573 }
3574 char offsetMsb[MAX_TEMPORARY_STORAGE]; sprintf( offsetMsb, "%d", 0 );
3575
3576 outline1("LDA %s", address_displacement(_environment, _source, offsetMsb));
3577 outline0("ANDA #$80");
3578 outline0("TFR A, B");
3579 outline1("LBEQ %snocomplement", label );
3580 cpu_complement2_nbit( _environment, _source, _source, _bits );
3581 outhead1("%snocomplement", label );
3582 while( _steps ) {
3583 outline0("ANDCC #$FE");
3584 outline1("LSR %s", address_displacement(_environment, _source, offsetMsb));
3585 for( int i=1; i<(_bits>>3); ++i ) {
3586 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
3587 outline1("ROR %s", address_displacement(_environment, _source, offset));
3588 }
3589 --_steps;
3590 }
3591 outline0("CMPB #0");
3592 outline1("LBEQ %snocomplement2", label );
3593 cpu_complement2_nbit( _environment, _source, _source, _bits );
3594 outhead1("%snocomplement2", label );
3595
3597
3598}
3599
3607void cpu_math_mul2_const_32bit( Environment * _environment, char *_source, int _steps, int _signed ) {
3608
3610
3612
3613 if ( _signed ) {
3614
3615 outline1("LDA %s", _source);
3616 outline0("ANDA #$80");
3617 outline1("BEQ %spos", label );
3618
3619 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3620 outline0("ANDCC #$FE" );
3621 outline0("EORA #$FF" );
3622 outline0("EORB #$FF" );
3623 outline0("STD <MATHPTR2" );
3624 outline1("LDD %s", _source );
3625 outline0("ANDCC #$FE" );
3626 outline0("EORA #$FF" );
3627 outline0("EORB #$FF" );
3628 outline0("STD <MATHPTR0" );
3629 outline0("LDD <MATHPTR2" );
3630 outline0("ANDCC #$FE" );
3631 outline0("ADDD #1" );
3632 outline0("STD <MATHPTR2" );
3633 outline0("LDD <MATHPTR0" );
3634 outline0("ADDD #0" );
3635 outline0("STD <MATHPTR0" );
3636
3637 outline1("JMP %sdone", label );
3638
3639 outhead1("%spos", label );
3640 outline1("LDD %s", _source );
3641 outline0("STD <MATHPTR0" );
3642 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3643 outline0("STD <MATHPTR2" );
3644
3645 outhead1("%sdone", label );
3646
3647 outline1("LDX #$%4.4x", _steps );
3648 outhead1("%sloop", label );
3649 outline0("ANDCC #$FE" );
3650 outline0("LSL <MATHPTR3" );
3651 outline0("ROL <MATHPTR2" );
3652 outline0("ROL <MATHPTR1" );
3653 outline0("ROL <MATHPTR0" );
3654 outline0("LEAX -1, X");
3655 outline0("CMPX #0");
3656 outline1("BNE %sloop", label );
3657
3658 outline1("LDA %s", _source);
3659 outline0("ANDA #$80");
3660 outline1("BEQ %spos2", label );
3661
3662 outline0("ANDCC #$FE" );
3663 outline0("LDD <MATHPTR2" );
3664 outline0("EORA #$FF" );
3665 outline0("EORB #$FF" );
3666 outline0("STD <MATHPTR2" );
3667 outline0("LDD <MATHPTR0" );
3668 outline0("EORA #$FF" );
3669 outline0("EORB #$FF" );
3670 outline0("STD <MATHPTR0" );
3671
3672 outline0("ANDCC #$FE" );
3673 outline0("LDD <MATHPTR2" );
3674 outline0("ADDD #1" );
3675 outline1("STD %s", address_displacement(_environment, _source, "2") );
3676 outline0("LDD <MATHPTR0" );
3677 outline0("ADDD #0" );
3678 outline1("STD %s", _source );
3679
3680 outline1("JMP %sdone2", label );
3681
3682 outhead1("%spos2", label );
3683 outline0("LDD <MATHPTR3" );
3684 outline1("STD %s", address_displacement(_environment, _source, "3") );
3685 outline0("LDD <MATHPTR2" );
3686 outline1("STD %s", address_displacement(_environment, _source, "2") );
3687 outline0("LDD <MATHPTR1" );
3688 outline1("STD %s", address_displacement(_environment, _source, "1") );
3689 outline0("LDD <MATHPTR0" );
3690 outline1("STD %s", _source );
3691 outhead1("%sdone2", label );
3692
3693 } else {
3694
3695 outline1("LDD %s", _source );
3696 outline0("STD <MATHPTR0" );
3697 outline1("LDD %s", address_displacement(_environment, _source, "2") );
3698 outline0("STD <MATHPTR2" );
3699
3700 outhead1("%sdone", label );
3701
3702 outline1("LDX #$%4.4x", _steps );
3703 outhead1("%sloop", label );
3704 outline0("ANDCC #$FE" );
3705 outline0("LSL <MATHPTR3" );
3706 outline0("ROL <MATHPTR2" );
3707 outline0("ROL <MATHPTR1" );
3708 outline0("ROL <MATHPTR0" );
3709 outline0("LEAX -1, X");
3710 outline0("CMPX #0");
3711 outline1("BNE %sloop", label );
3712
3713 outline0("LDD <MATHPTR2" );
3714 outline1("STD %s", address_displacement(_environment, _source, "2") );
3715 outline0("LDD <MATHPTR0" );
3716 outline1("STD %s", _source );
3717
3718 }
3719
3721
3722}
3723
3724void cpu_math_mul2_const_nbit( Environment * _environment, char *_source, int _steps, int _bits ) {
3725
3726 int i;
3727
3728 inline( cpu_math_mul2_const_nbit )
3729
3730 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", (_bits>>3)-1 );
3731 outline1("LDA %s", _source );
3732 outline0("ANDA #$80");
3733 outline0("TFR A, B");
3734 while( _steps ) {
3735 outline0("ANDCC #$FE");
3736 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", (_bits>>3)-1);
3737 outline1("ASL %s", address_displacement(_environment, _source, offset));
3738 for( i=(_bits>>3)-2; i>-1; --i ) {
3739 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i);
3740 outline1("ROL %s", address_displacement(_environment, _source, offset));
3741 }
3742 --_steps;
3743 }
3744 outline1("ORB %s", _source );
3745 outline1("STB %s", _source );
3746
3748
3749}
3750
3758void cpu_math_and_const_32bit( Environment * _environment, char *_source, int _mask ) {
3759
3760 inline( cpu_math_and_const_32bit )
3761
3762 outline1("LDX #%s", _source );
3763 if(_mask & 0xffff0000) {
3764 outline0("LDD ,X");
3765 outline1("ANDA #$%2.2x", ( _mask >> 24 ) & 0xff );
3766 outline1("ANDB #$%2.2x", ( _mask >> 16 ) & 0xff );
3767 } else {
3768 outline0("LDD #0");
3769 }
3770 outline0("STD ,X");
3771 if(_mask & 0x0000ffff) {
3772 outline0("LDD 2,X");
3773 outline1("ANDA #$%2.2x", ( _mask >> 8 ) & 0xff );
3774 outline1("ANDB #$%2.2x", ( _mask >> 0 ) & 0xff );
3775 } else {
3776 outline0("LDD #0");
3777 }
3778 outline0("STD 2,X");
3779
3781
3782}
3783
3784void cpu_combine_nibbles( Environment * _environment, char * _low_nibble, char * _hi_nibble, char * _byte ) {
3785
3787
3788 embedded( cpu_combine_nibbles, src_hw_6809_cpu_combine_nibbles_asm );
3789
3790 outline1("LDX #%s", _hi_nibble );
3791 outline1("LDY #%s", _low_nibble );
3792 outline1("LDU #%s", _byte );
3793 outline0("JSR CPUCOMBINENIBBLES" );
3794
3795 done( )
3796
3797}
3798
3799void cpu_jump( Environment * _environment, char * _label ) {
3800
3801 inline( cpu_jump )
3802
3803 B(RA, _label );
3804
3806
3807}
3808
3809void cpu_call_addr( Environment * _environment, int _address ) {
3810
3811 outline1( "JSR $%4.4x", _address );
3812
3813}
3814
3815void cpu_call( Environment * _environment, char * _label ) {
3816
3817 inline( cpu_call )
3818
3819 B(SR, _label );
3820
3822
3823}
3824
3825void cpu_call_indirect( Environment * _environment, char * _value ) {
3826
3827 inline( cpu_call_indirect )
3828
3830
3831 char indirectLabel[MAX_TEMPORARY_STORAGE]; sprintf( indirectLabel, "%sindirect", label );
3832
3833 cpu_jump( _environment, label );
3834 cpu_label( _environment, indirectLabel );
3835 outline1( "JMP [%s]", _value );
3836 cpu_label( _environment, label );
3837 cpu_call( _environment, indirectLabel );
3838
3840
3841}
3842
3843void cpu_jump_indirect( Environment * _environment, char * _value ) {
3844
3845 inline( cpu_jump_indirect )
3846
3847 outline1( "JMP [%s]", _value );
3848
3850
3851}
3852
3853int cpu_register_decode( Environment * _environment, char * _register ) {
3854
3856
3857 if ( !_environment->emptyProcedure ) {
3858
3859 if ( strcmp( _register, "A" ) == 0 ) {
3860 result = REGISTER_A;
3861 } else if ( strcmp( _register, "B" ) == 0 ) {
3862 result = REGISTER_B;
3863 } else if ( strcmp( _register, "CC" ) == 0 ) {
3864 if ( !_environment->emptyProcedure ) {
3866 }
3867 result = REGISTER_CC;
3868 } else if ( strcmp( _register, "DP" ) == 0 ) {
3869 if ( !_environment->emptyProcedure ) {
3871 }
3872 result = REGISTER_DP;
3873 } else if ( strcmp( _register, "X" ) == 0 ) {
3874 result = REGISTER_X;
3875 } else if ( strcmp( _register, "Y" ) == 0 ) {
3876 result = REGISTER_Y;
3877 } else if ( strcmp( _register, "U" ) == 0 ) {
3878 result = REGISTER_U;
3879 } else if ( strcmp( _register, "S" ) == 0 ) {
3880 result = REGISTER_S;
3881 } else if ( strcmp( _register, "PC" ) == 0 ) {
3882 if ( !_environment->emptyProcedure ) {
3884 }
3885 result = REGISTER_PC;
3886 } else if ( strcmp( _register, "D" ) == 0 ) {
3887 result = REGISTER_D;
3888 } else {
3889
3890 }
3891
3892 }
3893
3894 return (int)result;
3895
3896}
3897
3898void cpu_set_asmio( Environment * _environment, int _asmio, int _value ) {
3899
3900 if ( IS_REGISTER( _asmio ) ) {
3901
3902 CPU6809Register reg = (CPU6809Register) _asmio;
3903
3904 switch ( reg ) {
3905 case REGISTER_NONE:
3907 break;
3908 case REGISTER_CC:
3909 case REGISTER_DP:
3910 break;
3911 case REGISTER_A:
3912 outline1( "LDA #$%2.2x", (unsigned char)(_value & 0xff ) );
3913 break;
3914 case REGISTER_B:
3915 outline1( "LDB #$%2.2x", (unsigned char)(_value & 0xff ) );
3916 break;
3917 case REGISTER_X:
3918 outline1( "LDX #$%4.4x", (unsigned short)(_value & 0xffff ) );
3919 break;
3920 case REGISTER_Y:
3921 outline1( "LDY #$%4.4x", (unsigned short)(_value & 0xffff ) );
3922 break;
3923 case REGISTER_U:
3924 outline1( "LDU #$%4.4x", (unsigned short)(_value & 0xffff ) );
3925 break;
3926 case REGISTER_S:
3927 outline1( "LDS #$%4.4x", (unsigned short)(_value & 0xffff ) );
3928 break;
3929 case REGISTER_D:
3930 outline1( "LDD #$%4.4x", (unsigned short)(_value & 0xffff ) );
3931 break;
3932 default:
3934 break;
3935 }
3936
3937 } else {
3938
3939 CPU6809Stack stk = (CPU6809Stack) _asmio;
3940
3941 switch ( stk ) {
3942 case STACK_NONE:
3943 break;
3944 case STACK_BYTE:
3945 outline1( "LDA %2.2x", _value );
3946 outline0( "PSHS A" );
3947 break;
3948 case STACK_WORD:
3949 outline1( "LDD %4.4x", _value );
3950 outline0( "PSHS D" );
3951 break;
3952 case STACK_DWORD:
3953 outline1( "LDD %4.4x", ( _value & 0xffff ) );
3954 outline0( "PSHS D" );
3955 outline1( "LDD %4.4x", ( (_value >> 16 ) & 0xffff ) );
3956 outline0( "PSHS D" );
3957 break;
3958 }
3959
3960 }
3961
3962}
3963
3964void cpu_set_asmio_indirect( Environment * _environment, int _asmio, char * _value ) {
3965
3966 if ( IS_REGISTER( _asmio ) ) {
3967
3968 CPU6809Register reg = (CPU6809Register) _asmio;
3969
3970 switch ( reg ) {
3971 case REGISTER_NONE:
3973 break;
3974 case REGISTER_CC:
3975 case REGISTER_DP:
3976 break;
3977 case REGISTER_A:
3978 outline1( "LDA %s", _value );
3979 break;
3980 case REGISTER_B:
3981 outline1( "LDB %s", _value );
3982 break;
3983 case REGISTER_X:
3984 outline1( "LDX %s", _value );
3985 break;
3986 case REGISTER_Y:
3987 outline1( "LDY %s", _value );
3988 break;
3989 case REGISTER_U:
3990 outline1( "LDU %s", _value );
3991 break;
3992 case REGISTER_S:
3993 outline1( "LDS %s", _value );
3994 break;
3995 case REGISTER_D:
3996 outline1( "LDD %s", _value );
3997 break;
3998 }
3999
4000 } else {
4001
4002 CPU6809Stack stk = (CPU6809Stack) _asmio;
4003
4004 switch ( stk ) {
4005 case STACK_NONE:
4006 break;
4007 case STACK_BYTE:
4008 outline1( "LDA %s", address_displacement(_environment, _value, "0") );
4009 outline0( "PSHS A" );
4010 break;
4011 case STACK_WORD:
4012 outline1( "LDD %s", address_displacement(_environment, _value, "0") );
4013 outline0( "PSHS D" );
4014 break;
4015 case STACK_DWORD:
4016 outline1( "LDD %s", address_displacement(_environment, _value, "0") );
4017 outline0( "PSHS D" );
4018 outline1( "LDD %s", address_displacement(_environment, _value, "2") );
4019 outline0( "PSHS D" );
4020 break;
4021 }
4022
4023 }
4024
4025}
4026
4027void cpu_get_asmio_indirect( Environment * _environment, int _asmio, char * _value ) {
4028
4029 if ( IS_REGISTER( _asmio ) ) {
4030
4031 CPU6809Register reg = (CPU6809Register) _asmio;
4032
4033 switch ( reg ) {
4034 case REGISTER_NONE:
4036 break;
4037 case REGISTER_CC:
4038 case REGISTER_DP:
4039 break;
4040 case REGISTER_A:
4041 outline1( "STA %s", _value );
4042 break;
4043 case REGISTER_B:
4044 outline1( "STB %s", _value );
4045 break;
4046 case REGISTER_X:
4047 outline1( "STX %s", _value );
4048 break;
4049 case REGISTER_Y:
4050 outline1( "STY %s", _value );
4051 break;
4052 case REGISTER_U:
4053 outline1( "STU %s", _value );
4054 break;
4055 case REGISTER_S:
4056 outline1( "STS %s", _value );
4057 break;
4058 case REGISTER_D:
4059 outline1( "STD %s", _value );
4060 break;
4061 }
4062
4063 } else {
4064
4065 CPU6809Stack stk = (CPU6809Stack) _asmio;
4066
4067 switch ( stk ) {
4068 case STACK_NONE:
4069 break;
4070 case STACK_BYTE:
4071 outline0( "PULS A" );
4072 outline1( "STA %s", address_displacement(_environment, _value, "0") );
4073 break;
4074 case STACK_WORD:
4075 outline0( "PULS D" );
4076 outline1( "STD %s", address_displacement(_environment, _value, "0") );
4077 break;
4078 case STACK_DWORD:
4079 outline0( "PULS D" );
4080 outline1( "STD %s", address_displacement(_environment, _value, "0") );
4081 outline0( "PULS D" );
4082 outline1( "STD %s", address_displacement(_environment, _value, "2") );
4083 break;
4084 }
4085
4086 }
4087
4088}
4089
4090void cpu_return( Environment * _environment ) {
4091
4092 inline( cpu_return )
4093
4094 outline0( "RTS" );
4095
4097
4098}
4099
4100void cpu_pop( Environment * _environment ) {
4101
4102 inline( cpu_pop )
4103
4104 outline0( "LEAS 2,S" );
4105
4107
4108}
4109
4110void cpu_halt( Environment * _environment ) {
4111
4112 inline( cpu_halt )
4113
4115
4116 outline0( "; HALT" );
4117 outhead1("%s", label );
4118 B(RA, label);
4119
4121
4122}
4123
4124void cpu_end( Environment * _environment ) {
4125
4126 inline( cpu_end )
4127
4128 outline0( "ANDCC #$6f" );
4129 cpu_halt( _environment );
4130
4132
4133}
4134
4135void cpu_random( Environment * _environment, char * _entropy ) {
4136
4137 if ( ! _environment->deployed.random ) {
4138
4139 inline( cpu_random )
4140
4142
4143 srand( time( NULL ) );
4144
4145 if ( _entropy ) {
4146 outline0("LDD CPURANDOM_SEED");
4147 outline0("ASLB");
4148 outline0("ASLB");
4149 outline0("ROLA");
4150 outline0("ADDD CPURANDOM_SEED+2");
4151 outline0("LSR CPURANDOM_SEED");
4152 outline0("ROR CPURANDOM_SEED+1");
4153 outline0("ASLB");
4154 outline0("ROLA");
4155 outline1("ADDA %s", _entropy);
4156 outline0("ASLB");
4157 outline0("ROLA");
4158 outline0("ASLB");
4159 outline0("ROLA");
4160 outline0("ADDD CPURANDOM_SEED+1");
4161 outline0("STD CPURANDOM_SEED+1");
4162 }
4163
4164 embedded( cpu_random, src_hw_6809_cpu_random_asm );
4165
4166 _environment->deployed.random = 1;
4167
4168 if ( _entropy ) {
4169 outline1( "LDB %s", _entropy );
4170 outline0( "STB <PATTERN" );
4171 }
4172
4173 outline0( "JSR CPURANDOM" );
4174
4175 done( )
4176
4177 } else {
4178
4179 if ( _entropy ) {
4180 outline1( "LDB %s", _entropy );
4181 outline0( "STB <PATTERN" );
4182 }
4183
4184 outline0( "JSR CPURANDOM" );
4185
4186 }
4187}
4188
4189void cpu_random_8bit( Environment * _environment, char * _entropy, char * _result ) {
4190
4191 cpu_random( _environment, _entropy );
4192
4193 if ( _result ) {
4194 outline0("LDB CPURANDOM_SEED+3");
4195 outline1("STB %s", _result );
4196 }
4197
4198}
4199
4200void cpu_random_16bit( Environment * _environment, char * _entropy, char * _result ) {
4201
4202 cpu_random( _environment, _entropy );
4203
4204 if ( _result ) {
4205 outline0("LDD CPURANDOM_SEED+2");
4206 outline1("STD %s", _result );
4207 }
4208
4209}
4210
4211void cpu_random_32bit( Environment * _environment, char * _entropy, char * _result ) {
4212
4213 cpu_random( _environment, _entropy );
4214
4215 if ( _result ) {
4216 outline0("LDD CPURANDOM_SEED");
4217 outline1("STD %s", _result );
4218 outline0("LDD CPURANDOM_SEED+2");
4219 outline1("STD %s", address_displacement(_environment, _result, "2") );
4220 }
4221
4222}
4223
4224void cpu_limit_16bit( Environment * _environment, char * _variable, int _value ) {
4225
4226 inline( cpu_limit_16bit )
4227
4229
4230 outline0( "LDA #$0" );
4231 outline1( "STA %s", _variable );
4232 outline1( "LDA %s", address_displacement(_environment, _variable, "1") );
4233 outline1( "CMPA #$%2.2x", _value );
4234 outline1( "BCC %s", label );
4235 outline1( "SUBA #$%2.2x", _value );
4236 outline1( "STA %s", _variable );
4237 outhead1( "%s", label );
4238
4240
4241}
4242
4243void cpu_busy_wait( Environment * _environment, char * _timing ) {
4244
4245 inline( cpu_busy_wait )
4246
4248
4249 outline1("LDA %s", _timing );
4250 outhead1("%s", label );
4251 outline0("DECA");
4252 outline1("BNE %s", label);
4253
4255
4256}
4257
4258void cpu_logical_and_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4259
4260 inline( cpu_logical_and_8bit )
4261
4263
4264 outline1("LDB %s", _left );
4265 outline1("BEQ %s", label );
4266 outline1("LDB %s", _right );
4267 outline1("BEQ %s", label );
4268 outline0("LDB #$FF");
4269 outhead1("%s", label);
4270 outline1("STB %s", _result);
4271
4273
4274}
4275
4276void cpu_and_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4277
4278 inline( cpu_and_8bit )
4279
4281
4282 outline1("LDB %s", _right );
4283 outline1("ANDB %s", _left );
4284 outline1("STB %s", _result);
4285
4287
4288}
4289
4290void cpu_and_8bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
4291
4292 inline( cpu_and_8bit )
4293
4295
4296 outline1("LDB %s", _left );
4297 outline1("ANDB #$%2.2x", _right );
4298 outline1("STB %s", _result);
4299
4301
4302}
4303
4304void cpu_and_16bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4305
4306 inline( cpu_and_16bit )
4307
4309
4310 outline1("LDD %s", _right );
4311 outline1("ANDA %s", _left );
4312 outline1("ANDB %s", address_displacement(_environment, _left, "1") );
4313 outline1("STD %s", _result);
4314
4316
4317}
4318
4319void cpu_and_32bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4320
4321 inline( cpu_and_32bit )
4322
4324
4325 outline1("LDD %s", _left );
4326 outline1("ANDA %s", _right );
4327 outline1("ANDB %s", address_displacement(_environment, _right, "1") );
4328 outline1("STD %s", _result);
4329 outline1("LDD %s", address_displacement(_environment, _left, "2") );
4330 outline1("ANDA %s", address_displacement(_environment, _right, "2") );
4331 outline1("ANDB %s", address_displacement(_environment, _right, "3") );
4332 outline1("STD %s", address_displacement(_environment, _result, "2"));
4333
4335
4336}
4337
4338void cpu_logical_or_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4339
4340 inline( cpu_logical_or_8bit )
4341
4343
4344 outline1("LDB %s", _left );
4345 outline1("ORB %s", _right );
4346 outline1("BEQ %s", label);
4347 outline0("LDB #$FF");
4348 outhead1("%s", label);
4349 outline1("STB %s", _result);
4350
4352
4353}
4354
4355void cpu_or_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4356
4357 inline( cpu_or_8bit )
4358
4360
4361 outline1("LDB %s", _right );
4362 outline1("ORB %s", _left );
4363 outline1("STB %s", _result);
4364
4366
4367}
4368
4369void cpu_or_8bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
4370
4371 inline( cpu_or_8bit )
4372
4374
4375 outline1("LDB %s", _left );
4376 outline1("ORB #$%2.2x", _right );
4377 outline1("STB %s", _result);
4378
4380
4381}
4382
4383void cpu_or_16bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4384
4385 inline( cpu_or_16bit )
4386
4388
4389 outline1("LDD %s", _left );
4390 outline1("ORA %s", _right );
4391 outline1("ORB %s", address_displacement(_environment, _right, "1") );
4392 outline1("STD %s", _result);
4393
4395
4396}
4397
4398void cpu_or_32bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4399
4400 inline( cpu_or_32bit )
4401
4403
4404 outline1("LDD %s", _left );
4405 outline1("ORA %s", _right );
4406 outline1("ORB %s", address_displacement(_environment, _right, "1") );
4407 outline1("STD %s", _result);
4408 outline1("LDD %s", address_displacement(_environment, _left, "2") );
4409 outline1("ORA %s", address_displacement(_environment, _right, "2") );
4410 outline1("ORB %s", address_displacement(_environment, _right, "3") );
4411 outline1("STD %s", address_displacement(_environment, _result, "2"));
4412
4414
4415}
4416
4417void cpu_xor_8bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4418
4419 inline( cpu_xor_8bit )
4420
4422
4423 outline1("LDB %s", _right );
4424 outline1("EORB %s", _left );
4425 outline1("STB %s", _result);
4426
4428
4429}
4430
4431void cpu_xor_8bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
4432
4433 inline( cpu_xor_8bit )
4434
4436
4437 outline1("LDB %s", _left );
4438 outline1("EORB #$%2.2x", _right );
4439 outline1("STB %s", _result);
4440
4442
4443}
4444
4445void cpu_xor_16bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4446
4447 inline( cpu_xor_16bit )
4448
4450
4451 outline1("LDD %s", _left );
4452 outline1("EORA %s", _right );
4453 outline1("EORB %s", address_displacement(_environment, _right, "1") );
4454 outline1("STD %s", _result);
4455
4457
4458}
4459
4460void cpu_xor_16bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
4461
4462 inline( cpu_xor_16bit )
4463
4465
4466 outline1("LDD %s", _left );
4467 outline1("EORA #$%2.2x", (unsigned char)((_right >> 8) & 0xff ) );
4468 outline1("EORB #$%2.2x", (unsigned char)((_right) & 0xff ) );
4469 outline1("STD %s", _result);
4470
4472
4473}
4474
4475
4476void cpu_xor_32bit( Environment * _environment, char * _left, char * _right, char * _result ) {
4477
4478 inline( cpu_xor_32bit )
4479
4481
4482 outline1("LDD %s", _left );
4483 outline1("EORA %s", _right );
4484 outline1("EORB %s", address_displacement(_environment, _right, "1") );
4485 outline1("STD %s", _result);
4486 outline1("LDD %s", address_displacement(_environment, _left, "2") );
4487 outline1("EORA %s", address_displacement(_environment, _right, "2") );
4488 outline1("EORB %s", address_displacement(_environment, _right, "3") );
4489 outline1("STD %s", address_displacement(_environment, _result, "2"));
4490
4492
4493}
4494
4495void cpu_xor_32bit_const( Environment * _environment, char * _left, int _right, char * _result ) {
4496
4497 inline( cpu_xor_32bit )
4498
4500
4501 outline1("LDD %s", _left );
4502 outline1("EORA #$%2.2x", (unsigned char)( (_right >> 24) & 0xff ) );
4503 outline1("EORB #$%2.2x", (unsigned char)( (_right >> 16) & 0xff ) );
4504 outline1("STD %s", _result);
4505 outline1("LDD %s", address_displacement(_environment, _left, "2") );
4506 outline1("EORA #$%2.2x", (unsigned char)( (_right >> 8) & 0xff ) );
4507 outline1("EORB #$%2.2x", (unsigned char)( (_right) & 0xff ) );
4508 outline1("STD %s", address_displacement(_environment, _result, "2"));
4509
4511
4512}
4513
4514void cpu_swap_8bit( Environment * _environment, char * _left, char * _right ) {
4515
4517
4518 embedded( cpu_swap_8bit, src_hw_6809_cpu_swap_asm ); // it is not an error: swap 8/16/32 shares code
4519
4520 outline1("LDX #%s", _right );
4521 outline1("LDY #%s", _left );
4522 outline0("JSR CPUSWAP1" );
4523
4524 done( )
4525
4526}
4527
4528void cpu_swap_16bit( Environment * _environment, char * _left, char * _right ) {
4529
4531
4532 embedded( cpu_swap_8bit, src_hw_6809_cpu_swap_asm ); // it is not an error: swap 8/16/32 shares code
4533
4534 outline1("LDX #%s", _right );
4535 outline1("LDY #%s", _left );
4536 outline0("JSR CPUSWAP2" );
4537
4538 done( )
4539
4540}
4541
4542void cpu_swap_32bit( Environment * _environment, char * _left, char * _right ) {
4543
4545
4546 embedded( cpu_swap_8bit, src_hw_6809_cpu_swap_asm ); // it is not an error: swap 8/16/32 shares code
4547
4548 outline1("LDX #%s", _right );
4549 outline1("LDY #%s", _left );
4550 outline0("JSR CPUSWAP4" );
4551
4552 done( )
4553
4554}
4555
4556void cpu_logical_not_8bit( Environment * _environment, char * _value, char * _result ) {
4557
4558 inline( cpu_logical_not_8bit )
4559
4560 outline1("LDB %s", _value );
4561 outline0("COMA" );
4562 outline1("STB %s", _result );
4563
4565
4566}
4567
4568void cpu_not_8bit( Environment * _environment, char * _value, char * _result ) {
4569
4570 inline( cpu_not_8bit )
4571
4572 outline1("LDB %s", _value );
4573 outline0("COMB" );
4574 outline1("STB %s", _result );
4575
4577
4578}
4579
4580void cpu_not_16bit( Environment * _environment, char * _value, char * _result ) {
4581
4582 inline( cpu_not_16bit )
4583
4584 outline1("LDD %s", _value );
4585 outline0("COMA" );
4586 outline0("COMB" );
4587 outline1("STD %s", _result );
4588
4590
4591}
4592
4593void cpu_not_32bit( Environment * _environment, char * _value, char * _result ) {
4594
4595 inline( cpu_not_32bit )
4596
4597 outline1("LDD %s", _value );
4598 outline0("COMA" );
4599 outline0("COMB" );
4600 outline1("STD %s", _result );
4601 outline1("LDD %s", address_displacement(_environment, _value, "2") );
4602 outline0("COMA" );
4603 outline0("COMB" );
4604 outline1("STD %s", address_displacement(_environment, _result, "2") );
4605
4607
4608}
4609
4610void cpu_di( Environment * _environment ) {
4611 outline0( "ORCC #$50" );
4612}
4613
4614void cpu_ei( Environment * _environment ) {
4615 outline0( "ANDCC #$AF" );
4616}
4617
4618void cpu_inc( Environment * _environment, char * _variable ) {
4619
4620 inline( cpu_inc )
4621
4622 outline1("INC %s", _variable );
4623
4625
4626}
4627
4628void cpu_inc_16bit( Environment * _environment, char * _variable ) {
4629
4630 inline( cpu_inc_16bit )
4631
4632 // 16 cycles all times, but extra possibilites for peephole
4633 // outline0("LDD #1" );
4634 // outline1("ADDD %s", _variable );
4635 // outline1("STD %s", _variable );
4636
4638
4639 // 10 cycles 255 times out of 256 and 17 one out of 256
4640 outline1("INC %s", address_displacement(_environment, _variable, "1"));
4641 outline1("BNE %s", label);
4642 outline1("INC %s", _variable);
4643 outhead1("%s", label)
4644
4646
4647}
4648
4649void cpu_inc_32bit( Environment * _environment, char * _variable ) {
4650
4651 inline( cpu_inc_32bit )
4652
4653 // outline1("LDD %s", address_displacement(_environment, _variable, "2") );
4654 // outline0("ADDD #1" );
4655 // outline1("STD %s", address_displacement(_environment, _variable, "2") );
4656 // outline1("LDD %s", _variable );
4657 // outline0("ADCB #0" );
4658 // outline0("ADCA #0" );
4659 // outline1("STD %s", _variable );
4660
4662
4663 outline1("INC %s", address_displacement(_environment, _variable, "3"));
4664 outline1("BNE %s", label);
4665 outline1("INC %s", address_displacement(_environment, _variable, "2"));
4666 outline1("BNE %s", label);
4667 outline1("INC %s", address_displacement(_environment, _variable, "1"));
4668 outline1("BNE %s", label);
4669 outline1("INC %s", _variable);
4670 outhead1("%s", label)
4671
4673
4674}
4675
4676void cpu_inc_nbit( Environment * _environment, char * _variable, int _bits ) {
4677
4679
4680 inline( cpu_inc_nbit )
4681
4682 for( int i=(_bits>>3)-1; i>-1;--i ) {
4683 char offset[MAX_TEMPORARY_STORAGE]; sprintf(offset, "%d", i );
4684 outline1("INC %s", address_displacement(_environment, _variable, offset ) );
4685 outline1("BNE %s", label );
4686 }
4687 outhead1("%s", label );
4688
4690
4691}
4692
4693void cpu_dec( Environment * _environment, char * _variable ) {
4694
4695 inline( cpu_dec )
4696
4697 outline1("DEC %s", _variable );
4698
4700
4701}
4702
4703void cpu_dec_16bit( Environment * _environment, char * _variable ) {
4704
4705 inline( cpu_dec_16bit )
4706
4707 outline1("LDD %s", _variable );
4708 outline0("SUBD #1" );
4709 outline1("STD %s", _variable );
4710
4712
4713}
4714
4715void cpu_dec_32bit( Environment * _environment, char * _variable ) {
4716
4718
4719 inline( cpu_dec_32bit )
4720
4721 outline1("LDD %s", address_displacement( _environment, _variable, "2" ) );
4722 outline0("SUBD #1" );
4723 outline1("STD %s", address_displacement( _environment, _variable, "2" ) );
4724 outline0("CMPD #$FFFF" );
4725 outline1("BNE %s", label );
4726 outline1("LDD %s", _variable );
4727 outline0("SUBD #1" );
4728 outline1("STD %s", _variable );
4729 outhead1("%s", label );
4730
4732
4733}
4734
4735void cpu_dec_nbit( Environment * _environment, char * _variable, int _bits ) {
4736
4738
4739 inline( cpu_dec_32bit )
4740
4741 for( int i=(_bits>>3)-1; i>-1; --i ) {
4742 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
4743 outline1("DEC %s", address_displacement(_environment, _variable, offset) );
4744 outline1("LDA %s", address_displacement(_environment, _variable, offset) );
4745 outline0("CMPA #$FF" );
4746 outline1("BNE %s", label );
4747 }
4748 outhead1("%s", label );
4749
4751
4752}
4753
4754
4755void cpu_mem_move( Environment * _environment, char *_source, char *_destination, char *_size ) {
4756
4757 deploy_preferred( duff, src_hw_6809_duff_asm );
4758
4759 inline( cpu_mem_move )
4760
4762
4763 outline1("LDB %s", _size );
4764 outline1("BEQ %sdone", label );
4765
4766 outline1("LDY %s", _source );
4767 outline1("LDX %s", _destination );
4768
4769 outline0("ANDB #$80" );
4770 outline1("BEQ %sloop2", label );
4771 outline0("LDB #$7F" );
4772 outline0("DECB" );
4773 outhead1("%s", label );
4774 outline0("LDA B,Y" );
4775 outline0("STA B,X" );
4776 outline0("DECB" );
4777 outline0("CMPB #$FF" );
4778 outline1("BNE %s", label );
4779 outline0("LEAY 127,Y" );
4780 outline0("LEAX 127,X" );
4781 outline0("LEAY 1,Y" );
4782 outline0("LEAX 1,X" );
4783
4784 outhead1("%sloop2", label );
4785 outline1("LDB %s", _size );
4786 outline0("ANDB #$7F" );
4787 outline1("BEQ %sdone", label );
4788 outline0("DECB" );
4789 outhead1("%s_2", label );
4790 outline0("LDA B,Y" );
4791 outline0("STA B,X" );
4792 outline0("DECB" );
4793 outline0("CMPB #$FF" );
4794 outline1("BNE %s_2", label );
4795 outhead1("%sdone", label );
4796
4797 embedded( cpu_mem_move, src_hw_6809_cpu_mem_move_asm )
4798
4799 outline0("LDA #0" );
4800 outline1("LDB %s", _size );
4801 // outline0("TFR D, U" );
4802 outline1("LDY %s", _source );
4803 outline1("LDX %s", _destination );
4804 outline0("JSR DUFFDEVICE" );
4805
4806 done( )
4807
4808}
4809
4810void cpu_mem_move_16bit( Environment * _environment, char *_source, char *_destination, char *_size ) {
4811
4812 deploy_preferred( duff, src_hw_6809_duff_asm );
4813
4815
4816 embedded( cpu_mem_move, src_hw_6809_cpu_mem_move_asm )
4817
4818 outline1("LDD %s", _size );
4819 // outline0("TFR D, U" );
4820 outline1("LDY %s", _source );
4821 outline1("LDX %s", _destination );
4822 outline0("JSR DUFFDEVICE" );
4823
4824 done( )
4825
4826}
4827
4828void cpu_mem_move_direct( Environment * _environment, char *_source, char *_destination, char *_size ) {
4829
4830 deploy_preferred( duff, src_hw_6809_duff_asm );
4831
4832 inline( cpu_mem_move )
4833
4835
4836 outline1("LDB %s", _size );
4837 outline1("BEQ %sdone", label );
4838
4839 outline1("LDY #%s", _source );
4840 outline1("LDX #%s", _destination );
4841
4842 outline0("ANDA #$80" );
4843 outline1("BEQ %sloop2", label );
4844 outline0("LDB #$7F" );
4845 outline0("DECB" );
4846 outhead1("%s", label );
4847 outline0("LDA B,Y" );
4848 outline0("STA B,X" );
4849 outline0("DECB" );
4850 outline0("CMPB #$FF" );
4851 outline1("BNE %s", label );
4852 outline0("LEAY 127,Y" );
4853 outline0("LEAX 127,X" );
4854 outline0("LEAY 1,Y" );
4855 outline0("LEAX 1,X" );
4856
4857 outhead1("%sloop2", label );
4858 outline1("LDB %s", _size );
4859 outline0("ANDA #$7F" );
4860 outline1("BEQ %sdone", label );
4861 outline0("DECB" );
4862 outhead1("%s_2", label );
4863 outline0("LDA B,Y" );
4864 outline0("STA B,X" );
4865 outline0("DECB" );
4866 outline0("CMPB #$FF" );
4867 outline1("BNE %s_2", label );
4868 outhead1("%sdone", label );
4869
4870 embedded( cpu_mem_move, src_hw_6809_cpu_mem_move_asm )
4871
4872 outline0("LDA #0" );
4873 outline1("LDB %s", _size );
4874 // outline0("TFR D, U" );
4875 outline1("LDY #%s", _source );
4876 outline1("LDX #%s", _destination );
4877 outline0("JSR DUFFDEVICE" );
4878
4879 done( )
4880
4881}
4882
4883void cpu_mem_move_direct2_size( Environment * _environment, char *_source, char *_destination, int _size ) {
4884
4885 deploy_preferred( duff, src_hw_6809_duff_asm );
4886
4887 inline( cpu_mem_move )
4888
4890
4891 outline1("LDU #$%4.4x", _size );
4892 outline0("CMPU #$0" );
4893 outline1("BEQ %sdone", label );
4894
4895 outline1("LDY %s", _source );
4896 outline1("LDX #%s", _destination );
4897
4898 outhead1("%s", label );
4899 outline0("LDA ,Y+" );
4900 outline0("STA ,X+" );
4901 outline0("LEAU -1, U" );
4902 outline0("CMPU #$0" );
4903 outline1("BNE %s", label );
4904
4905 embedded( cpu_mem_move, src_hw_6809_cpu_mem_move_asm )
4906
4907 outline1("LDD #$%4.4x", _size );
4908 outline1("LDY %s", _source );
4909 outline1("LDX #%s", _destination );
4910 outline0("JSR DUFFDEVICE" );
4911
4912 done( )
4913
4914}
4915
4916void cpu_mem_move_direct2( Environment * _environment, char *_source, char *_destination, char *_size ) {
4917
4918 deploy_preferred( duff, src_hw_6809_duff_asm );
4919
4920 inline( cpu_mem_move )
4921
4923
4924 outline1("LDU %s", _size );
4925 outline0("CMPU #$0" );
4926 outline1("BEQ %sdone", label );
4927
4928 outline1("LDY %s", _source );
4929 outline1("LDX #%s", _destination );
4930
4931 outhead1("%s", label );
4932 outline0("LDA ,Y+" );
4933 outline0("STA ,X+" );
4934 outline0("LEAU -1, U" );
4935 outline0("CMPU #$0" );
4936 outline1("BNE %s", label );
4937
4938 embedded( cpu_mem_move, src_hw_6809_cpu_mem_move_asm )
4939
4940 outline1("LDD %s", _size );
4941 outline1("LDY %s", _source );
4942 outline1("LDX #%s", _destination );
4943 outline0("JSR DUFFDEVICE" );
4944
4945 done( )
4946
4947}
4948
4949void cpu_mem_move_size( Environment * _environment, char *_source, char *_destination, int _size ) {
4950
4951 deploy_preferred( duff, src_hw_6809_duff_asm );
4952
4953 inline( cpu_mem_move )
4954
4956
4957 if ( _size ) {
4958
4959 outline1("LDY %s", _source );
4960 outline1("LDX %s", _destination );
4961
4962 if ( _size >= 0x7f ) {
4963
4964 outline0("LDB #$7F" );
4965 outline0("DECB" );
4966 outhead1("%s", label );
4967 outline0("LDA B,Y" );
4968 outline0("STA B,X" );
4969 outline0("DECB" );
4970 outline0("CMPB #$FF" );
4971 outline1("BNE %s", label );
4972 outline0("LEAY 127,Y" );
4973 outline0("LEAX 127,X" );
4974 outline0("LEAY 1,Y" );
4975 outline0("LEAX 1,X" );
4976
4977 _size -= 0x7f;
4978
4979 }
4980
4981 if ( _size ) {
4982
4983 outline1("LDB #$%2.2x", (unsigned char)( _size & 0xff ) );
4984 outline0("DECB" );
4985 outhead1("%s_2", label );
4986 outline0("LDA B,Y" );
4987 outline0("STA B,X" );
4988 outline0("DECB" );
4989 outline0("CMPB #$FF" );
4990 outline1("BNE %s_2", label );
4991
4992 }
4993
4994 }
4995
4996 embedded( cpu_mem_move, src_hw_6809_cpu_mem_move_asm )
4997
4998 outline1("LDD #$%4.4x", _size );
4999 outline1("LDY %s", _source );
5000 outline1("LDX %s", _destination );
5001 outline0("JSR DUFFDEVICE" );
5002
5003 done( )
5004
5005}
5006
5007void cpu_mem_move_direct_size( Environment * _environment, char *_source, char *_destination, int _size ) {
5008
5009 deploy_preferred( duff, src_hw_6809_duff_asm );
5010
5011 inline( cpu_mem_move )
5012
5014
5015 if ( _size ) {
5016
5017 outline1("LDY #%s", _source );
5018 outline1("LDX #%s", _destination );
5019
5020 if ( _size >= 0x7f ) {
5021
5022 outline0("LDB #$7F" );
5023 outline0("DECB" );
5024 outhead1("%s", label );
5025 outline0("LDA B,Y" );
5026 outline0("STA B,X" );
5027 outline0("DECB" );
5028 outline0("CMPB #$FF" );
5029 outline1("BNE %s", label );
5030 outline0("LEAY 127,Y" );
5031 outline0("LEAX 127,X" );
5032 outline0("LEAY 1,Y" );
5033 outline0("LEAX 1,X" );
5034
5035 _size -= 0x7f;
5036
5037 }
5038
5039 if ( _size ) {
5040
5041 outline1("LDB #$%2.2x", (unsigned char)( _size & 0xff ) );
5042 outline0("DECB" );
5043 outhead1("%s_2", label );
5044 outline0("LDA B,Y" );
5045 outline0("STA B,X" );
5046 outline0("DECB" );
5047 outline0("CMPB #$FF" );
5048 outline1("BNE %s_2", label );
5049
5050 }
5051
5052 }
5053
5054 embedded( cpu_mem_move, src_hw_6809_cpu_mem_move_asm )
5055
5056 outline1("LDD #$%4.4x", _size );
5057 outline1("LDY #%s", _source );
5058 outline1("LDX #%s", _destination );
5059 outline0("JSR DUFFDEVICE" );
5060
5061 done( )
5062
5063}
5064
5065void cpu_mem_move_direct_indirect_size( Environment * _environment, char *_source, char *_destination, int _size ) {
5066
5067 deploy_preferred( duff, src_hw_6809_duff_asm );
5068
5069 inline( cpu_mem_move )
5070
5072
5073 if ( _size ) {
5074
5075 outline1("LDY #%s", _source );
5076 outline1("LDX %s", _destination );
5077
5078 if ( _size >= 0x7f ) {
5079
5080 outline0("LDB #$7F" );
5081 outline0("DECB" );
5082 outhead1("%s", label );
5083 outline0("LDA B,Y" );
5084 outline0("STA B,X" );
5085 outline0("DECB" );
5086 outline0("CMPB #$FF" );
5087 outline1("BNE %s", label );
5088 outline0("LEAY 127,Y" );
5089 outline0("LEAX 127,X" );
5090 outline0("LEAY 1,Y" );
5091 outline0("LEAX 1,X" );
5092
5093 _size -= 0x7f;
5094
5095 }
5096
5097 if ( _size ) {
5098
5099 outline1("LDB #$%2.2x", (unsigned char)( _size & 0xff ) );
5100 outline0("DECB" );
5101 outhead1("%s_2", label );
5102 outline0("LDA B,Y" );
5103 outline0("STA B,X" );
5104 outline0("DECB" );
5105 outline0("CMPB #$FF" );
5106 outline1("BNE %s_2", label );
5107
5108 }
5109
5110 }
5111
5112 embedded( cpu_mem_move, src_hw_6809_cpu_mem_move_asm )
5113
5114 outline1("LDD #$%4.4x", _size );
5115 outline1("LDY #%s", _source );
5116 outline1("LDX %s", _destination );
5117 outline0("JSR DUFFDEVICE" );
5118
5119 done( )
5120
5121}
5122
5123void cpu_mem_move_indirect_direct_size( Environment * _environment, char *_source, char *_destination, int _size ) {
5124
5125 deploy_preferred( duff, src_hw_6809_duff_asm );
5126
5127 inline( cpu_mem_move )
5128
5130
5131 if ( _size ) {
5132
5133 outline1("LDY %s", _source );
5134 outline1("LDX #%s", _destination );
5135
5136 if ( _size >= 0x7f ) {
5137
5138 outline0("LDB #$7F" );
5139 outline0("DECB" );
5140 outhead1("%s", label );
5141 outline0("LDA B,Y" );
5142 outline0("STA B,X" );
5143 outline0("DECB" );
5144 outline0("CMPB #$FF" );
5145 outline1("BNE %s", label );
5146 outline0("LEAY 127,Y" );
5147 outline0("LEAX 127,X" );
5148 outline0("LEAY 1,Y" );
5149 outline0("LEAX 1,X" );
5150
5151 _size -= 0x7f;
5152
5153 }
5154
5155 if ( _size ) {
5156
5157 outline1("LDB #$%2.2x", (unsigned char)( _size & 0xff ) );
5158 outline0("DECB" );
5159 outhead1("%s_2", label );
5160 outline0("LDA B,Y" );
5161 outline0("STA B,X" );
5162 outline0("DECB" );
5163 outline0("CMPB #$FF" );
5164 outline1("BNE %s_2", label );
5165
5166 }
5167
5168 }
5169
5170 embedded( cpu_mem_move, src_hw_6809_cpu_mem_move_asm )
5171
5172 outline1("LDD #$%4.4x", _size );
5173 outline1("LDY %s", _source );
5174 outline1("LDX #%s", _destination );
5175 outline0("JSR DUFFDEVICE" );
5176
5177 done( )
5178
5179}
5180
5181void cpu_compare_memory( Environment * _environment, char *_source, char *_destination, char *_size, char * _result, int _equal ) {
5182
5183 inline( cpu_compare_memory )
5184
5186
5187 outline1("LDA %s", _size );
5188 outline1("BEQ %sequal", label );
5189
5190 outline1("LDY %s", _source );
5191 outline1("LDX %s", _destination );
5192
5193 outline1("LDA %s", _size );
5194 outline0("ANDA #$80" );
5195 outline1("BEQ %ssecond", label );
5196
5197 outhead1("%sfirst", label );
5198 outline0("LDA #0" );
5199 outhead1("%sloop", label );
5200 outline0("LDB A,X" );
5201 outline0("CMPB A,Y" );
5202 outline1("BNE %sdiff", label );
5203 outline0("ADDA #1" );
5204 outline0("CMPA #$7F" );
5205 outline1("BNE %sloop", label );
5206 outline0("LEAY 127,Y" );
5207 outline0("LEAX 127,X" );
5208 outline0("LEAY 1,Y" );
5209 outline0("LEAX 1,X" );
5210
5211 outhead1("%ssecond", label );
5212 outline1("LDA %s", _size );
5213 outline0("ANDA #$7f" );
5214 outline0("STA <MATHPTR0" );
5215 outline0("LDA #0" );
5216 outhead1("%sloop2", label );
5217 outline0("LDB A,X" );
5218 outline0("CMPB A,Y" );
5219 outline1("BNE %sdiff", label );
5220 outline0("ADDA #1" );
5221 outline0("CMPA <MATHPTR0" );
5222 outline1("BNE %sloop2", label );
5223
5224 outhead1("%sequal", label );
5225 outline1("LDA #$%2.2x", _equal ? 0xff : 0x00 );
5226 outline1("STA %s", _result );
5227 outline1("JMP %sfinal", label );
5228
5229 outhead1("%sdiff", label );
5230 outline1("LDA #$%2.2x", _equal ? 0x00 : 0xff );
5231 outline1("STA %s", _result );
5232 outhead1("%sfinal", label );
5233
5235
5236}
5237
5238void cpu_compare_memory_size( Environment * _environment, char *_source, char *_destination, int _size, char * _result, int _equal ) {
5239
5240 inline( cpu_compare_memory_size )
5241
5243
5244 if ( _size ) {
5245
5246 outline1("LDY %s", _source );
5247 outline1("LDX %s", _destination );
5248
5249 if ( _size >= 0x7f ) {
5250
5251 outhead1("%sfirst", label );
5252 outline0("LDA #0" );
5253 outhead1("%sloop", label );
5254 outline0("LDB A,X" );
5255 outline0("CMPB A,Y" );
5256 outline1("BNE %sdiff", label );
5257 outline0("ADDA #1" );
5258 outline0("CMPA #$7F" );
5259 outline1("BNE %sloop", label );
5260 outline0("LEAY 127,Y" );
5261 outline0("LEAX 127,X" );
5262 outline0("LEAY 1,Y" );
5263 outline0("LEAX 1,X" );
5264
5265 _size -= 0x7f;
5266
5267 }
5268
5269 if ( _size ) {
5270
5271 outhead1("%ssecond", label );
5272 outline1("LDA #$%2.2x", _size );
5273 outline0("STA <MATHPTR0" );
5274 outline0("LDA #0" );
5275 outhead1("%sloop2", label );
5276 outline0("LDB A,X" );
5277 outline0("CMPB A,Y" );
5278 outline1("BNE %sdiff", label );
5279 outline0("ADDA #1" );
5280 outline0("CMPA <MATHPTR0" );
5281 outline1("BNE %sloop2", label );
5282
5283 }
5284
5285 outhead1("%sequal", label );
5286 outline1("LDA #$%2.2x", _equal ? 0xff : 0x00 );
5287 outline1("STA %s", _result );
5288 outline1("JMP %sfinal", label );
5289
5290 outhead1("%sdiff", label );
5291 outline1("LDA #$%2.2x", _equal ? 0x00 : 0xff );
5292 outline1("STA %s", _result );
5293 outhead1("%sfinal", label );
5294
5295 }
5296
5297 no_embedded( cpu_compare_memory_soze )
5298
5299}
5300
5301void cpu_less_than_memory( Environment * _environment, char *_source, char *_destination, char *_size, char * _result, int _equal ) {
5302
5303 inline( cpu_less_than_memory )
5304
5306
5307 outline1("LDA %s", _size );
5308 outline1("BEQ %sequal", label );
5309
5310 outline1("LDY %s", _destination );
5311 outline1("LDX %s", _source );
5312
5313 outline1("LDA %s", _size );
5314 outline0("ANDA #$80" );
5315 outline1("BEQ %ssecond", label );
5316
5317 outhead1("%sfirst", label );
5318 outline0("LDA #0" );
5319 outhead1("%sloop", label );
5320 outline0("LDB A,X" );
5321 outline0("CMPB A,Y" );
5322 if ( _equal ) {
5323 outline1("BHI %sdiff", label);
5324 } else {
5325 outline1("BHS %sdiff", label);
5326 }
5327 outline0("ADDA #1" );
5328 outline0("CMPA #$7F" );
5329 outline1("BNE %sloop", label );
5330 outline0("LEAY 127,Y" );
5331 outline0("LEAX 127,X" );
5332 outline0("LEAY 1,Y" );
5333 outline0("LEAX 1,X" );
5334
5335 outhead1("%ssecond", label );
5336 outline1("LDA %s", _size );
5337 outline0("ANDA #$7f" );
5338 outline0("STA <MATHPTR0" );
5339 outline0("LDA #0" );
5340 outhead1("%sloop2", label );
5341 outline0("LDB A,X" );
5342 outline0("CMPB A,Y" );
5343 if ( _equal ) {
5344 outline1("BHI %sdiff", label);
5345 } else {
5346 outline1("BHS %sdiff", label);
5347 }
5348 outline0("ADDA #1" );
5349 outline0("CMPA <MATHPTR0" );
5350 outline1("BNE %sloop2", label );
5351
5352 outhead1("%sequal", label );
5353 outline0("LDA #$FF");
5354 outline1("STA %s", _result );
5355 outline1("JMP %sfinal", label );
5356
5357 outhead1("%sdiff", label );
5358 outline0("LDA #$0");
5359 outline1("STA %s", _result );
5360 outhead1("%sfinal", label );
5361
5363
5364}
5365
5366void cpu_less_than_memory_size( Environment * _environment, char *_source, char *_destination, int _size, char * _result, int _equal ) {
5367
5369
5371
5372 if ( _size ) {
5373
5374 outline1("LDY %s", _destination );
5375 outline1("LDX %s", _source );
5376
5377 if ( _size >= 0x7f ) {
5378
5379 outhead1("%sfirst", label );
5380 outline0("LDA #0" );
5381 outhead1("%sloop", label );
5382 outline0("LDB A,X" );
5383 outline0("CMPB A,Y" );
5384 if ( _equal ) {
5385 outline1("BHI %sdiff", label);
5386 } else {
5387 outline1("BHS %sdiff", label);
5388 }
5389 outline0("ADDA #1" );
5390 outline0("CMPA #$7F" );
5391 outline1("BNE %sloop", label );
5392 outline0("LEAY 127,Y" );
5393 outline0("LEAX 127,X" );
5394 outline0("LEAY 1,Y" );
5395 outline0("LEAX 1,X" );
5396
5397 _size -= 0x7f;
5398
5399 }
5400
5401 if ( _size ) {
5402
5403 outhead1("%ssecond", label );
5404 outline1("LDA #$%2.2x", _size );
5405 outline0("STA <MATHPTR0" );
5406 outline0("LDA #0" );
5407 outhead1("%sloop2", label );
5408 outline0("LDB A,X" );
5409 outline0("CMPB A,Y" );
5410 if ( _equal ) {
5411 outline1("BHI %sdiff", label);
5412 } else {
5413 outline1("BHS %sdiff", label);
5414 }
5415 outline0("ADDA #1" );
5416 outline0("CMPA <MATHPTR0" );
5417 outline1("BNE %sloop2", label );
5418
5419 }
5420
5421 outhead1("%sequal", label );
5422 outline0("LDA #$FF");
5423 outline1("STA %s", _result );
5424 outline1("JMP %sfinal", label );
5425
5426 outhead1("%sdiff", label );
5427 outline0("LDA #$0");
5428 outline1("STA %s", _result );
5429 outhead1("%sfinal", label );
5430
5431 }
5432
5434
5435}
5436
5437void cpu_greater_than_memory( Environment * _environment, char *_source, char *_destination, char *_size, char * _result, int _equal ) {
5438
5439 inline( cpu_greater_than_memory )
5440
5442
5443 outline1("LDA %s", _size );
5444 outline1("BEQ %sequal", label );
5445
5446 outline1("LDY %s", _destination );
5447 outline1("LDX %s", _source );
5448
5449 outline1("LDA %s", _size );
5450 outline0("ANDA #$80" );
5451 outline1("BEQ %ssecond", label );
5452
5453 outhead1("%sfirst", label );
5454 outline0("LDA #0" );
5455 outhead1("%sloop", label );
5456 outline0("LDB A,X" );
5457 outline0("CMPB A,Y" );
5458 if ( _equal ) {
5459 outline1("BLO %sdiff", label);
5460 } else {
5461 outline1("BLS %sdiff", label);
5462 }
5463 outline0("ADDA #1" );
5464 outline0("CMPA #$7F" );
5465 outline1("BNE %sloop", label );
5466 outline0("LEAY 127,Y" );
5467 outline0("LEAX 127,X" );
5468 outline0("LEAY 1,Y" );
5469 outline0("LEAX 1,X" );
5470
5471 outhead1("%ssecond", label );
5472 outline1("LDA %s", _size );
5473 outline0("ANDA #$7f" );
5474 outline0("STA <MATHPTR0" );
5475 outline0("LDA #0" );
5476 outhead1("%sloop2", label );
5477 outline0("LDB A,X" );
5478 outline0("CMPB A,Y" );
5479 if ( _equal ) {
5480 outline1("BLO %sdiff", label);
5481 } else {
5482 outline1("BLS %sdiff", label);
5483 }
5484 outline0("ADDA #1" );
5485 outline0("CMPA <MATHPTR0" );
5486 outline1("BNE %sloop2", label );
5487
5488 outhead1("%sequal", label );
5489 outline0("LDA #$FF");
5490 outline1("STA %s", _result );
5491 outline1("JMP %sfinal", label );
5492
5493 outhead1("%sdiff", label );
5494 outline0("LDA #$0");
5495 outline1("STA %s", _result );
5496 outhead1("%sfinal", label );
5497
5499
5500}
5501
5502void cpu_greater_than_memory_size( Environment * _environment, char *_source, char *_destination, int _size, char * _result, int _equal ) {
5503
5505
5507
5508 if ( _size ) {
5509
5510 outline1("LDY %s", _destination );
5511 outline1("LDX %s", _source );
5512
5513 if ( _size >= 0x7f ) {
5514
5515 outhead1("%sfirst", label );
5516 outline0("LDA #0" );
5517 outhead1("%sloop", label );
5518 outline0("LDB A,X" );
5519 outline0("CMPB A,Y" );
5520 if ( _equal ) {
5521 outline1("BLO %sdiff", label);
5522 } else {
5523 outline1("BLS %sdiff", label);
5524 }
5525 outline0("ADDA #1" );
5526 outline0("CMPA #$7F" );
5527 outline1("BNE %sloop", label );
5528 outline0("LEAY 127,Y" );
5529 outline0("LEAX 127,X" );
5530
5531 _size -= 0x7f;
5532
5533 }
5534
5535 if ( _size ) {
5536
5537 outhead1("%ssecond", label );
5538 outline1("LDA #$%2.2x", _size );
5539 outline0("STA <MATHPTR0" );
5540 outline0("LDA #0" );
5541 outhead1("%sloop2", label );
5542 outline0("LDB A,X" );
5543 outline0("CMPB A,Y" );
5544 if ( _equal ) {
5545 outline1("BLO %sdiff", label);
5546 } else {
5547 outline1("BLS %sdiff", label);
5548 }
5549 outline0("ADDA #1" );
5550 outline0("CMPA <MATHPTR0" );
5551 outline1("BNE %sloop2", label );
5552
5553 }
5554
5555 outhead1("%sequal", label );
5556 outline0("LDA #$FF");
5557 outline1("STA %s", _result );
5558 outline1("JMP %sfinal", label );
5559
5560 outhead1("%sdiff", label );
5561 outline0("LDA #$0");
5562 outline1("STA %s", _result );
5563 outhead1("%sfinal", label );
5564
5565 }
5566
5568
5569}
5570
5571void cpu_move_8bit_indirect( Environment * _environment, char *_source, char * _value ) {
5572
5573 inline( cpu_move_8bit_indirect )
5574
5575 outline1("LDB %s", _source);
5576 outline1("STB [%s]", _value);
5577
5579
5580}
5581
5582void cpu_move_8bit_indirect_with_offset( Environment * _environment, char *_source, char * _value, int _offset ) {
5583
5584 inline( cpu_move_8bit_with_offset )
5585
5586 outline1("LDB %s", _source);
5587 outline1("LDX %s", _value);
5588 outline1("STB %d,X", _offset );
5589
5590 no_embedded( cpu_move_8bit_with_offset )
5591
5592}
5593
5594void cpu_move_8bit_indirect_with_offset2( Environment * _environment, char *_source, char * _value, char * _offset ) {
5595
5597
5599
5600 outline1("LDA %s", _source);
5601 outline1("LDX %s", _value);
5602 outline1("LDB %s", _offset);
5603 outline0("ABX");
5604 outline0("STA ,X");
5605
5607
5608}
5609
5610void cpu_move_8bit_with_offset2( Environment * _environment, char *_source, char * _value, char * _offset ) {
5611
5613
5615
5616 outline1("LDX #%s", _value);
5617 outline1("LDB %s", _offset);
5618 outline0("ABX");
5619 outline1("LDA %s", _source);
5620 outline0("STA ,X");
5621
5623
5624}
5625
5626void cpu_move_8bit_indirect2( Environment * _environment, char * _value, char *_source ) {
5627
5628 inline( cpu_move_8bit_indirect2 )
5629
5631
5632 outline1("LDB [%s]", _value);
5633 outline1("STB %s", _source );
5634
5636
5637}
5638
5639void cpu_move_8bit_indirect2_8bit( Environment * _environment, char * _value, char * _offset, char *_source ) {
5640
5642
5644
5645 outline1("LDX #%s", _value);
5646 outline1("LDB %s", _offset);
5647 outline0("ABX");
5648 outline0("LDB ,X");
5649 outline1("STB %s", _source);
5650
5652
5653}
5654
5655void cpu_move_8bit_indirect2_16bit( Environment * _environment, char * _value, char * _offset, char *_source ) {
5656
5658
5660
5661 outline1("LDX #%s", _value);
5662 outline1("LDD %s", _offset);
5663 outline0("LEAX D,X");
5664 outline0("LDA ,X");
5665 outline1("STA %s", _source);
5666
5668
5669}
5670
5671void cpu_move_16bit_indirect( Environment * _environment, char *_source, char * _value ) {
5672
5673 inline( cpu_move_16bit_indirect )
5674
5676
5677 outline1("LDD %s", _source);
5678 outline1("STD [%s]", _value);
5679
5681
5682}
5683
5684void cpu_move_16bit_indirect2( Environment * _environment, char * _value, char *_source ) {
5685
5686 inline( cpu_move_16bit_indirect2 )
5687
5689
5690 outline1("LDD [%s]", _value);
5691 outline1("STD %s", _source );
5692
5694
5695}
5696
5697void cpu_move_16bit_indirect2_8bit( Environment * _environment, char * _value, char * _offset, char *_source ) {
5698
5700
5702
5703 outline1("LDX #%s", _value);
5704 outline1("LDB %s", _offset);
5705 outline0("ABX");
5706 outline0("ABX");
5707 outline0("LDD ,X");
5708 outline1("STD %s", _source);
5709
5711
5712}
5713
5714void cpu_move_32bit_indirect( Environment * _environment, char *_source, char * _value ) {
5715
5716 inline( cpu_move_32bit_indirect )
5717
5719
5720 outline1("LDX %s", _value);
5721 outline0("LDD ,X");
5722 outline1("STD %s", _source );
5723 outline0("LDD 2,X");
5724 outline1("STD %s", address_displacement(_environment, _source, "2") );
5725
5727
5728}
5729
5730void cpu_move_32bit_indirect2( Environment * _environment, char * _value, char *_source ) {
5731
5732 inline( cpu_move_32bit_indirect2 )
5733
5735
5736 outline1("LDX %s", _value);
5737 outline0("LDD ,X");
5738 outline1("STD %s", _source );
5739 outline0("LDD 2,X");
5740 outline1("STD %s", address_displacement(_environment, _source, "2") );
5741
5743
5744}
5745
5746void cpu_uppercase( Environment * _environment, char *_source, char *_size, char *_result ) {
5747
5748 inline( cpu_uppercase )
5749
5751
5752 outline1("LDA %s ", _size );
5753 B(EQ, label);
5754 outline1("LDX %s", _source );
5755 if ( _result ) {
5756 outline1("LDU %s", _result );
5757 } else {
5758 outline1("LDU %s", _source );
5759 }
5760 outhead1("%supper", label );
5761 outline0("LDB ,X+" );
5762
5763 outline0("CMPB #97");
5764 outline1("BLO %snext", label);
5765
5766 outline0("CMPB #122");
5767 outline1("BHI %snext", label);
5768
5769 outline0("SUBB #32");
5770
5771 outhead1("%snext", label );
5772 outline0("STB ,U+" );
5773 outline0("DECA" );
5774 outline1("BNE %supper", label );
5775
5776 outhead1("%s", label );
5777
5779
5780
5781}
5782
5783void cpu_lowercase( Environment * _environment, char *_source, char *_size, char *_result ) {
5784
5785 inline( cpu_lowercase )
5786
5788
5789 outline1("LDA %s ", _size );
5790 B(EQ, label);
5791 outline1("LDX %s", _source );
5792 if ( _result ) {
5793 outline1("LDU %s", _result );
5794 } else {
5795 outline1("LDU %s", _source );
5796 }
5797 outhead1("%supper", label );
5798 outline0("LDB ,X+" );
5799
5800 outline0("CMPB #65");
5801 outline1("BLO %snext", label);
5802
5803 outline0("CMPB #90");
5804 outline1("BHI %snext", label);
5805
5806 outline0("ADDB #32");
5807
5808 outhead1("%snext", label );
5809 outline0("STB ,U+" );
5810 outline0("DECA" );
5811 outline1("BNE %supper", label );
5812
5813 outhead1("%s", label );
5814
5816
5817}
5818
5819void cpu_convert_string_into_8bit( Environment * _environment, char * _string, char * _len, char * _value ) {
5820
5822
5823 embedded( cpu_convert_string_into_16bit, src_hw_6809_cpu_convert_string_into_16bit_asm );
5824
5825 outline1("LDU %s", _string );
5826 outline1("LDB %s", _len );
5827 outline0("JSR CPUCONVERTSTRING8BIT" );
5828 outline1("STB %s", _value );
5829
5830 done( )
5831
5832}
5833
5834void cpu_convert_string_into_16bit( Environment * _environment, char * _string, char * _len, char * _value ) {
5835
5837
5838 embedded( cpu_convert_string_into_16bit, src_hw_6809_cpu_convert_string_into_16bit_asm );
5839
5840 outline1("LDU %s", _string );
5841 outline1("LDB %s", _len );
5842 outline0("JSR CPUCONVERTSTRING16BIT" );
5843 outline1("STX %s", _value );
5844
5845 done( )
5846
5847}
5848
5849void cpu_fill_indirect( Environment * _environment, char * _address, char * _size, char * _pattern, int _size_size ) {
5850
5851 inline( cpu_fill_indirect )
5852
5854
5855 if( _size_size >= 16 ) {
5856 outline1("LDD %s", _size);
5857 } else {
5858 outline1("LDB %s", _size);
5859 outline0("LDA #0");
5860 }
5861 outline0("TFR D,Y");
5862 outline1("LDX %s", _pattern );
5863 outline0("LDA ,X" );
5864 outline1("LDX %s", _address);
5865 outhead1("%s", label);
5866 outhead1("%sinner", label);
5867 outline0("STA ,X+");
5868 outline0("LEAY -1, Y");
5869 outline0("CMPY #$ffff");
5870 outline1("BNE %sinner", label);
5871
5873
5874}
5875
5876void cpu_flip_8bit( Environment * _environment, char * _source, char * _destination ) {
5877
5879
5880 embedded( cpu_flip, src_hw_6809_cpu_flip_asm );
5881
5882 outline1("LDA %s", _source);
5883 outline0("JSR CPUFLIP8");
5884 if ( _destination ) {
5885 outline1("STB %s", _destination);
5886 } else {
5887 outline1("STB %s", _source);
5888 }
5889
5890 done( )
5891
5892}
5893
5894void cpu_flip( Environment * _environment, char * _source, char * _size, char * _destination ) {
5895
5897
5898 embedded( cpu_flip, src_hw_6809_cpu_flip_asm );
5899
5900 outline1("LDU %s", _source);
5901 outline1("LDX %s", _destination);
5902 outline1("LDB %s", _size);
5903 outline0("JSR CPUFLIP");
5904
5905 done( )
5906
5907}
5908
5909void cpu_bit_check( Environment * _environment, char * _value, int _position, char *_result, int _bitwidth ) {
5910
5912
5913 embedded( cpu_bit_check_extended, src_hw_6809_cpu_bit_check_extended_asm );
5914
5915 switch( _bitwidth ) {
5916 case 8:
5917 outline1("LDX #%s", _value);
5918 break;
5919 case 16:
5920 outline1("LDX #%s", address_displacement( _environment, _value, "1" ) );
5921 break;
5922 case 32:
5923 outline1("LDX #%s", address_displacement( _environment, _value, "3" ) );
5924 break;
5925 }
5926 outline1("LDA #$%2.2x", _position );
5927 outline0("JSR CPUBITCHECKEXTENDED" );
5928
5929 if ( _result ) {
5930 outline1("STA %s", _result);
5931 }
5932
5933 done( )
5934
5935}
5936
5937void cpu_bit_check_extended( Environment * _environment, char * _value, char * _position, char *_result, int _bitwidth ) {
5938
5940
5941 embedded( cpu_bit_check_extended, src_hw_6809_cpu_bit_check_extended_asm );
5942
5943 switch( _bitwidth ) {
5944 case 8:
5945 outline1("LDX #%s", _value);
5946 break;
5947 case 16:
5948 outline1("LDX #(%s)", address_displacement( _environment, _value, "1" ) );
5949 break;
5950 case 32:
5951 outline1("LDX #(%s)", address_displacement( _environment, _value, "3" ) );
5952 break;
5953 }
5954 outline1("LDA %s", _position );
5955 outline0("JSR CPUBITCHECKEXTENDED" );
5956
5957 if ( _result ) {
5958 outline1("STA %s", _result);
5959 }
5960
5961 done( )
5962
5963}
5964
5965void cpu_bit_inplace_8bit( Environment * _environment, char * _value, int _position, int * _bit ) {
5966
5967 _environment->bitmaskNeeded = 1;
5968
5970
5971 no_inline( cpu_bit_inplace )
5972
5973 embedded( cpu_bit_inplace, src_hw_6809_cpu_bit_inplace_asm );
5974
5975 if ( ! _bit ) {
5976 outline0("PSHS CC");
5977 }
5978 outline1("LDX #%s", _value);
5979 outline1("LDA #$%2.2x", _position);
5980 if ( _bit ) {
5981 if ( *_bit ) {
5982 outline0("ORCC #$01");
5983 } else {
5984 outline0("ANDCC #$FE");
5985 }
5986 } else {
5987 outline0("PULS CC");
5988 }
5989 outline0("JSR CPUBITINPLACE");
5990
5991 done( )
5992
5993}
5994
5995void cpu_bit_inplace_8bit_extended_indirect( Environment * _environment, char * _address, char * _position, char * _bit ) {
5996
5997 _environment->bitmaskNeeded = 1;
5998
6000
6001 no_inline( cpu_bit_inplace )
6002
6003 embedded( cpu_bit_inplace, src_hw_6809_cpu_bit_inplace_asm );
6004
6005 outline1("LDX %s", _address);
6006 outline1("LDA %s", _position);
6007 if ( _bit ) {
6008 outline0("ANDCC #$FE");
6009 outline1("LDB %s", _bit);
6010 outline1("BEQ %s", label );
6011 outline0("ORCC #$01");
6012 outhead1("%s", label );
6013 }
6014 outline0("JSR CPUBITINPLACE");
6015
6016 done( )
6017
6018}
6019
6020void cpu_number_to_string( Environment * _environment, char * _number, char * _string, char * _string_size, int _bits, int _signed ) {
6021
6023
6024 deploy( numberToString, src_hw_6809_number_to_string_asm );
6025
6026
6027 switch( _bits ) {
6028 case 32:
6029 outline1("LDD %s", address_displacement(_environment, _number, "2") );
6030 outline1("STD N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 2 );
6031 outline1("LDD %s", _number );
6032 outline1("STD N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) );
6033 for( int i=(_environment->numberConfig.maxBytes - 4 ) - 2; i>0; i-=2 ) {
6034 outline0("LDD #0");
6035 outline1("STD N2STRINGNUMBER+%d", i );
6036 }
6037 if ( _signed ) {
6038 outline0("STA N2STRINGNUMBERSIGNED");
6039 outline1("BPL %spositive", label );
6040 char number[MAX_TEMPORARY_STORAGE];
6041 sprintf( number, "N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 2 );
6042 cpu_complement2_32bit( _environment, number, NULL);
6043 outhead1("%spositive", label );
6044 } else {
6045 outline0("CLR N2STRINGNUMBERSIGNED");
6046 }
6047 break;
6048 case 16:
6049 outline1("LDD %s", _number );
6050 outline1("STD N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 2 );
6051 for( int i=(_environment->numberConfig.maxBytes - 4 ); i>0; i-=2 ) {
6052 outline0("LDD #0");
6053 outline1("STD N2STRINGNUMBER+%d", i );
6054 }
6055 if ( _signed ) {
6056 outline0("STA N2STRINGNUMBERSIGNED");
6057 outline1("BPL %spositive", label );
6058 char number[MAX_TEMPORARY_STORAGE];
6059 sprintf( number, "N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 2 );
6060 cpu_complement2_16bit( _environment, number, NULL);
6061 outhead1("%spositive", label );
6062 }
6063 outline0("LDD #0");
6064 outline0("STD N2STRINGNUMBER");
6065 if ( !_signed ) outline0("STA N2STRINGNUMBERSIGNED");
6066 break;
6067 case 8:
6068 outline1("LDB %s", _number );
6069 outline0("CLRA");
6070 outline1("STD N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 2);
6071 for( int i=(_environment->numberConfig.maxBytes - 4 ); i>0; i-=2 ) {
6072 outline0("LDD #0");
6073 outline1("STD N2STRINGNUMBER+%d", i );
6074 }
6075 if ( _signed && _bits == 8 ) {
6076 outline0("STB N2STRINGNUMBERSIGNED");
6077 outline1("BPL %spositive", label );
6078 char number[MAX_TEMPORARY_STORAGE];
6079 sprintf( number, "N2STRINGNUMBER+%d", (_environment->numberConfig.maxBytes - 4 ) + 3 );
6080 cpu_complement2_8bit( _environment, number, NULL);
6081 outhead1("%spositive", label );
6082 }
6083 outline0("CLRB");
6084 outline0("STD N2STRINGNUMBER");
6085 if ( !_signed ) outline0("STA N2STRINGNUMBERSIGNED");
6086 break;
6087 default:
6088 cpu_mem_move_direct_size( _environment, _number, "N2STRINGNUMBER", _bits >> 3 );
6089 outline1("LDB %s", _number );
6090 outline0("ANDB #$80" );
6091 outline0("STB N2STRINGNUMBERSIGNED");
6092 outline1("LBPL %spositive", label );
6093 cpu_complement2_nbit( _environment, "N2STRINGNUMBER", NULL, _bits );
6094 outhead1("%spositive", label );
6095 break;
6096 case 0:
6097 CRITICAL_DEBUG_UNSUPPORTED( _number, "unknown");
6098 }
6099
6100
6101 outline1("LDX %s", _string );
6102 outline1("LDA #$%2.2X", _bits );
6103 outline0("JSR N2STRING");
6104
6105 outline1("STA %s", _string_size);
6106
6107}
6108
6109void cpu_bits_to_string( Environment * _environment, char * _number, char * _string, char * _string_size, int _bits, char * _zero, char * _one ) {
6110
6111 deploy( bitsToString, src_hw_6809_bits_to_string_asm );
6112
6113 if ( _zero ) {
6114 outline1("LDA %s", _zero);
6115 } else {
6116 outline0("LDA #'0'" );
6117 }
6118 outline0("STA BINSTRO0+1" );
6119
6120 if ( _one ) {
6121 outline1("LDA %s", _one);
6122 } else {
6123 outline0("LDA #'1'" );
6124 }
6125 outline0("STA BINSTRO1+1" );
6126
6127 switch( _bits ) {
6128 case 32:
6129 outline1("LDD %s", _number );
6130 outline0("STD <MATHPTR0" );
6131 outline1("LDD %s", address_displacement(_environment, _number, "2") );
6132 outline0("STD <MATHPTR2" );
6133 outline0("LDB #32" );
6134 outline1("STB %s", _string_size );
6135 break;
6136 case 16:
6137 outline0("LDD #0" );
6138 outline0("STD <MATHPTR0" );
6139 outline1("LDD %s", _number );
6140 outline0("STD <MATHPTR2" );
6141 outline0("LDB #16" );
6142 outline1("STB %s", _string_size );
6143 break;
6144 case 8:
6145 outline0("LDD #0" );
6146 outline0("STD <MATHPTR0" );
6147 outline0("LDA #0" );
6148 outline0("STA <MATHPTR2" );
6149 outline1("LDA %s", _number );
6150 outline0("STA <MATHPTR3" );
6151 outline0("LDB #8" );
6152 outline1("STB %s", _string_size );
6153 break;
6154 }
6155
6156 outline1("LDB #$%2.2x", (unsigned char)(_bits&0xff) );
6157 outline0("JSR BINSTR");
6158
6159 cpu_mem_move_direct_indirect_size( _environment, "BINSTRBUF", _string, _bits );
6160
6161}
6162
6163void cpu_hex_to_string_calc_string( Environment * _environment, char * _size, int _separator, char * _string_size ) {
6164
6166
6167 inline( cpu_hex_to_string )
6168
6169 embedded( cpu_hex_to_string, src_hw_6809_cpu_hex_to_string_asm );
6170
6171 outline1("LDA #$%2.2x", _separator?1:0 );
6172 outline1("LDB %s", _size );
6173 outline0("JSR H2STRINGCALCSIZE" );
6174 outline1("STB %s", _string_size );
6175
6176 done()
6177
6178}
6179
6180void cpu_hex_to_string_calc_string_size( Environment * _environment, int _size, int _separator, char * _string_size ) {
6181
6183
6184 inline( cpu_hex_to_string )
6185
6186 embedded( cpu_hex_to_string, src_hw_6809_cpu_hex_to_string_asm );
6187
6188 outline1("LDA #$%2.2x", _separator?1:0 );
6189 outline1("LDB #$%2.2x", (unsigned char)( _size & 0xff ) );
6190 outline0("JSR H2STRINGCALCSIZE" );
6191 outline1("STB %s", _string_size );
6192
6193 done()
6194
6195}
6196
6197void cpu_hex_to_string( Environment * _environment, char * _number, char * _string, char * _size, int _separator ) {
6198
6200
6201 inline( cpu_hex_to_string )
6202
6203 embedded( cpu_hex_to_string, src_hw_6809_cpu_hex_to_string_asm );
6204
6205 outline1("LDA #$%2.2x", (unsigned char)( _separator * 3 ) );
6206 outline1("LDB %s", _size);
6207 outline1("LDX %s", _number );
6208 outline1("LDY %s", _string );
6209
6210 outline0("JSR H2STRING" );
6211
6212 done()
6213
6214}
6215
6216void cpu_dsdefine( Environment * _environment, char * _string, char * _index ) {
6217
6218 deploy_preferred( duff, src_hw_6809_duff_asm );
6219 deploy( dstring, src_hw_6809_dstring_asm );
6220
6221 outline1( "LDY #%s", _string );
6222 outline0( "JSR DSDEFINE" );
6223 outline1( "STB %s", _index );
6224
6225}
6226
6227void cpu_dsalloc( Environment * _environment, char * _size, char * _index ) {
6228
6229 deploy_preferred( duff, src_hw_6809_duff_asm );
6230 deploy( dstring, src_hw_6809_dstring_asm );
6231
6232 outline1( "LDA %s", _size );
6233 outline0( "JSR DSALLOC" );
6234 outline1( "STB %s", _index );
6235
6236}
6237
6238void cpu_dsalloc_size( Environment * _environment, int _size, char * _index ) {
6239
6240 deploy_preferred( duff, src_hw_6809_duff_asm );
6241 deploy( dstring, src_hw_6809_dstring_asm );
6242
6243 outline1( "LDA #$%2.2x", _size );
6244 outline0( "JSR DSALLOC" );
6245 outline1( "STB %s", _index );
6246
6247}
6248
6249void cpu_dsfree( Environment * _environment, char * _index ) {
6250
6251 deploy_preferred( duff, src_hw_6809_duff_asm );
6252 deploy( dstring, src_hw_6809_dstring_asm );
6253
6254 outline1( "LDB %s", _index );
6255 outline0( "JSR DSFREE" );
6256
6257}
6258
6259void cpu_dswrite( Environment * _environment, char * _index ) {
6260
6261 deploy_preferred( duff, src_hw_6809_duff_asm );
6262 deploy( dstring, src_hw_6809_dstring_asm );
6263
6264 outline1( "LDB %s", _index );
6265 outline0( "JSR DSWRITE" );
6266
6267}
6268
6269void cpu_dsresize( Environment * _environment, char * _index, char * _resize ) {
6270
6271 deploy_preferred( duff, src_hw_6809_duff_asm );
6272 deploy( dstring, src_hw_6809_dstring_asm );
6273
6274 outline1( "LDB %s", _index );
6275 outline1( "LDA %s", _resize );
6276 outline0( "JSR DSRESIZE" );
6277
6278}
6279
6280void cpu_dsresize_size( Environment * _environment, char * _index, int _resize ) {
6281
6282 deploy_preferred( duff, src_hw_6809_duff_asm );
6283 deploy( dstring, src_hw_6809_dstring_asm );
6284
6285 outline1( "LDB %s", _index );
6286 outline1( "LDA #$%2.2X", _resize );
6287 outline0( "JSR DSRESIZE" );
6288
6289}
6290
6291void cpu_dsgc( Environment * _environment ) {
6292
6293 deploy_preferred( duff, src_hw_6809_duff_asm );
6294 deploy( dstring, src_hw_6809_dstring_asm );
6295
6296 outline0( "JSR DSGC" );
6297
6298}
6299
6300void cpu_dsinit( Environment * _environment ) {
6301
6302 deploy_preferred( duff, src_hw_6809_duff_asm );
6303 deploy( dstring, src_hw_6809_dstring_asm );
6304
6305 outline0( "JSR DSINIT" );
6306
6307}
6308
6309void cpu_dsdescriptor( Environment * _environment, char * _index, char * _address, char * _size ) {
6310
6311 deploy_preferred( duff, src_hw_6809_duff_asm );
6312 deploy( dstring,src_hw_6809_dstring_asm );
6313
6314 if ( _address || _size ) {
6315 outline1( "LDB %s", _index );
6316 outline0( "JSR DSDESCRIPTOR" );
6317 if ( _address ) {
6318 outline0( "LDD 1, X" );
6319 outline1( "STD %s", _address );
6320 }
6321 if ( _size ) {
6322 outline0( "LDA , X" );
6323 outline1( "STA %s", _size );
6324 }
6325 }
6326
6327}
6328
6329void cpu_dsassign( Environment * _environment, char * _original, char * _copy ) {
6330
6331 deploy_preferred( duff, src_hw_6809_duff_asm );
6332 deploy( dstring,src_hw_6809_dstring_asm );
6333
6334 outline1( "LDA %s", _original );
6335 outline1( "LDB %s", _copy );
6336 outline0( "JSR DSASSIGN" );
6337 outline1( "STB %s", _copy );
6338
6339}
6340
6341void cpu_dsassign_string( Environment * _environment, char * _string, char * _copy ) {
6342
6343 deploy_preferred( duff, src_hw_6809_duff_asm );
6344 deploy( dstring, src_hw_6809_dstring_asm );
6345
6346 outline1( "LDY #%s", _string );
6347 outline1( "LDB %s", _copy );
6348 outline0( "JSR DSASSIGNSTR" );
6349 outline1( "STB %s", _copy );
6350
6351}
6352
6353void cpu_store_8bit_with_offset( Environment * _environment, char *_destination, int _value, int _offset ) {
6354
6355 outline1("LDX %s", _destination);
6356 outline1("LDB #$%2.2x", (unsigned char)(_value & 0xff));
6357 outline1("STB $%2.2x,X", _offset);
6358
6359}
6360
6361void cpu_store_8bit_with_offset2( Environment * _environment, char * _source, char * _offset, int _value ) {
6362
6364
6366
6367 outline1("LDX #%s", _source);
6368 outline1("LDB %s", _offset);
6369 outline0("ABX");
6370 outline1("LDA #$%2.2x", _value);
6371 outline0("STA ,X");
6372
6374
6375}
6376
6377void cpu_complement2_8bit( Environment * _environment, char * _source, char * _destination ) {
6378
6379 if ( _destination ) {
6380 outline1( "LDB %s", _source );
6381 outline0( "NEGB");
6382 outline1( "STB %s", _destination );
6383 } else {
6384 outline1( "NEG %s", _source );
6385 }
6386
6387}
6388
6389void cpu_complement2_16bit( Environment * _environment, char * _source, char * _destination ) {
6390
6391 outline1( "LDD %s", _source );
6392 outline0( "NEGA" );
6393 outline0( "NEGB" );
6394 outline0( "SBCA #0" );
6395 if ( _destination ) {
6396 outline1( "STD %s", _destination );
6397 } else {
6398 outline1( "STD %s", _source );
6399 }
6400
6401}
6402
6403void cpu_complement2_32bit( Environment * _environment, char * _source, char * _destination ) {
6404 char *out = _destination ?_destination : _source;
6405
6407
6408 outline1( "LDD %s", _source );
6409 outline0( "COMA");
6410 outline0( "COMB");
6411 outline1( "STD %s", out );
6412
6413 outline1( "LDD %s", address_displacement(_environment, _source, "2") );
6414 outline0( "NEGA" );
6415 outline0( "NEGB" );
6416 outline0( "SBCA #0" );
6417 outline1( "STD %s", address_displacement(_environment, out, "2") );
6418
6419 outline1( "BNE %s", label);
6420 outline1( "INC %s", address_displacement(_environment, out, "1"));
6421 outline1( "BNE %s", label);
6422 outline1( "INC %s", out);
6423 outhead1( "%s", label);
6424
6425}
6426
6427void cpu_complement2_nbit( Environment * _environment, char * _source, char * _destination, int _bits ) {
6428
6429 for( int i=0; i<(_bits>>3); ++i ) {
6430 char offset[MAX_TEMPORARY_STORAGE]; sprintf( offset, "%d", i );
6431 outline1( "LDA %s", address_displacement(_environment, _source, offset) );
6432 outline0( "COMA" );
6433 if ( _destination ) {
6434 outline1( "STA %s", address_displacement(_environment, _destination, offset) );
6435 } else {
6436 outline1( "STA %s", address_displacement(_environment, _source, offset) );
6437 }
6438 }
6439 if ( _destination ) {
6440 cpu_inc_nbit( _environment, _destination, _bits );
6441 } else {
6442 cpu_inc_nbit( _environment, _source, _bits );
6443 }
6444
6445}
6446
6447void cpu_sqroot( Environment * _environment, char * _number, char * _result ) {
6448
6449 deploy( sqr, src_hw_6809_sqr_asm );
6450
6451 outline1("LDD %s", _number );
6452 outline0("STA <Numberh" );
6453 outline0("STB <Numberl" );
6454
6455 outline0("JSR SQROOT" );
6456
6457 outline0("LDB <Root" );
6458 outline1("STB %s", _result );
6459
6460}
6461
6462void cpu_dstring_vars( Environment * _environment ) {
6463
6464 int count = _environment->dstring.count == 0 ? DSTRING_DEFAULT_COUNT : _environment->dstring.count;
6465 int space = _environment->dstring.space == 0 ? DSTRING_DEFAULT_SPACE : _environment->dstring.space;
6466
6467 outhead1("stringscount equ %d", count );
6468 outhead1("stringsspace equ %d", (space-1) );
6469 outhead0("MAXSTRINGS equ stringscount" );
6470 outhead0("DESCRIPTORS rzb stringscount*4");
6471 outhead0("WORKING rzb stringsspace" );
6472 outhead0("TEMPORARY rzb stringsspace" );
6473 outhead0("FREE_STRING fdb stringsspace" );
6474
6475}
6476
6477void cpu_protothread_vars( Environment * _environment ) {
6478
6479 int count = _environment->protothreadConfig.count;
6480
6481 outhead1("PROTOTHREADLC rzb %d", count );
6482 outhead1("PROTOTHREADST rzb %d", count );
6483 outhead0("PROTOTHREADCT fcb 0" );
6484 outhead0("PROTOTHREADLOOP");
6485
6486 for( int i=0; i<count; ++i ) {
6487 outline1("LDB #%d-1", i+1 ); /* prevents optimizer changing code length */
6488 outline0("STB PROTOTHREADCT" );
6489 outline0("JSR PROTOTHREADVOID" );
6490 }
6491
6492 outline0("RTS" );
6493
6494}
6495
6496void cpu_protothread_loop( Environment * _environment ) {
6497
6498 deploy_with_vars( protothread, src_hw_6809_protothread_asm, cpu_protothread_vars );
6499
6500 outline0("JSR PROTOTHREADLOOP" );
6501
6502}
6503
6504void cpu_protothread_register_at( Environment * _environment, char * _index, char * _label ) {
6505
6506 deploy_with_vars( protothread, src_hw_6809_protothread_asm, cpu_protothread_vars );
6507
6508 outline1("LDY #%s", _label );
6509 outline1("LDB %s", _index );
6510
6511 outline0("JSR PROTOTHREADREGAT" );
6512
6513}
6514
6515void cpu_protothread_register( Environment * _environment, char * _label, char * _index ) {
6516
6517 deploy_with_vars( protothread, src_hw_6809_protothread_asm, cpu_protothread_vars );
6518
6519 outline1("LDY #%s", _label );
6520
6521 outline0("JSR PROTOTHREADREG" );
6522
6523 outline1("STB %s", _index );
6524
6525}
6526
6527void cpu_protothread_unregister( Environment * _environment, char * _index ) {
6528
6529 deploy_with_vars( protothread, src_hw_6809_protothread_asm, cpu_protothread_vars );
6530
6531 outline1("LDB %s", _index );
6532
6533 outline0("JSR PROTOTHREADUNREG" );
6534
6535}
6536
6537void cpu_protothread_save( Environment * _environment, char * _index, int _step ) {
6538
6539 deploy_with_vars( protothread, src_hw_6809_protothread_asm, cpu_protothread_vars );
6540
6541 outline1("LDB %s", _index );
6542 outline1("LDA #$%2.2x", _step );
6543
6544 outline0("JSR PROTOTHREADSAVE" );
6545
6546}
6547
6548void cpu_protothread_restore( Environment * _environment, char * _index, char * _step ) {
6549
6550 deploy_with_vars( protothread, src_hw_6809_protothread_asm, cpu_protothread_vars );
6551
6552 outline1("LDB %s", _index );
6553
6554 outline0("JSR PROTOTHREADRESTORE" );
6555
6556 outline1("STA %s", _step );
6557
6558}
6559
6560void cpu_protothread_set_state( Environment * _environment, char * _index, int _state ) {
6561
6562 deploy_with_vars( protothread, src_hw_6809_protothread_asm, cpu_protothread_vars );
6563
6564 outline1("LDB %s", _index );
6565 outline1("LDA #$%2.2x", _state );
6566
6567 outline0("JSR PROTOTHREADSETSTATE" );
6568
6569}
6570
6571void cpu_protothread_get_state( Environment * _environment, char * _index, char * _state ) {
6572
6573 deploy_with_vars( protothread, src_hw_6809_protothread_asm, cpu_protothread_vars );
6574
6575 outline1("LDB %s", _index );
6576
6577 outline0("JSR PROTOTHREADGETSTATE" );
6578
6579 outline1("STA %s", _state );
6580
6581}
6582
6583void cpu_protothread_current( Environment * _environment, char * _current ) {
6584
6585 deploy_with_vars( protothread, src_hw_6809_protothread_asm, cpu_protothread_vars );
6586
6587 outline0("LDB PROTOTHREADCT" );
6588 outline1("STB %s", _current );
6589
6590}
6591
6592void cpu_protothread_get_address( Environment * _environment, char * _index, char * _address ) {
6593
6594 deploy_with_vars( protothread, src_hw_6809_protothread_asm, cpu_protothread_vars );
6595
6596 outline1("LDB %s", _index );
6597
6598 outline0("JSR PROTOTHREADGETADDRESS" );
6599
6600 outline1("STY %s", _address );
6601
6602}
6603
6604void cpu_set_callback( Environment * _environment, char * _callback, char * _label ) {
6605
6606 outline1("LDY #%s", _label );
6607 outline1("LDU #%s", _callback );
6608 outline0("LEAU 1, U" );
6609 outline0("STY ,U" );
6610
6611}
6612
6613void cpu_msc1_uncompress_direct_direct( Environment * _environment, char * _input, char * _output ) {
6614
6616
6617 if ( ! _environment->deployed.msc1 ) {
6618
6619 inline( cpu_msc1_uncompress )
6620
6621 embedded( cpu_msc1_uncompress, src_hw_6809_msc1_asm );
6622
6623 outline1("LDX #%s", _input);
6624 outline1("LDY #%s", _output);
6625 outline0("JSR MSC1UNCOMPRESS");
6626
6627 done()
6628
6629 } else {
6630
6631 outline1("LDX #%s", _input);
6632 outline1("LDY #%s", _output);
6633 outline0("JSR MSC1UNCOMPRESS");
6634
6635 }
6636
6637}
6638
6639void cpu_msc1_uncompress_direct_indirect( Environment * _environment, char * _input, char * _output ) {
6640
6642
6643 inline( cpu_msc1_uncompress )
6644
6645 embedded( cpu_msc1_uncompress, src_hw_6809_msc1_asm );
6646
6647 outline1("LDX #%s", _input);
6648 outline1("LDY %s", _output);
6649 outline0("JSR MSC1UNCOMPRESS");
6650
6651 done()
6652
6653}
6654
6655void cpu_msc1_uncompress_indirect_direct( Environment * _environment, char * _input, char * _output ) {
6656
6658
6659 inline( cpu_msc1_uncompress )
6660
6661 embedded( cpu_msc1_uncompress, src_hw_6809_msc1_asm );
6662
6663 outline1("LDX %s", _input);
6664 outline1("LDY #%s", _output);
6665 outline0("JSR MSC1UNCOMPRESS");
6666
6667 done()
6668
6669}
6670
6671void cpu_msc1_uncompress_indirect_indirect( Environment * _environment, char * _input, char * _output ) {
6672
6674
6675 inline( cpu_msc1_uncompress )
6676
6677 embedded( cpu_msc1_uncompress, src_hw_6809_msc1_asm );
6678
6679 outline1("LDX %s", _input);
6680 outline1("LDY %s", _output);
6681 outline0("JSR MSC1UNCOMPRESS");
6682
6683 done()
6684
6685}
6686
6687void cpu_out( Environment * _environment, char * _port, char * _value ) {
6688
6689}
6690
6691void cpu_in( Environment * _environment, char * _port, char * _value ) {
6692
6693}
6694
6695void cpu_out_direct( Environment * _environment, char * _port, char * _value ) {
6696
6697}
6698
6699void cpu_in_direct( Environment * _environment, char * _port, char * _value ) {
6700
6701}
6702
6703
6704void cpu_string_sub( Environment * _environment, char * _source, char * _source_size, char * _pattern, char * _pattern_size, char * _destination, char * _destination_size ) {
6705
6707
6708 inline( cpu_string_sub )
6709
6710 embedded( cpu_string_sub, src_hw_6809_cpu_string_sub_asm );
6711
6712 outline1("LDY %s", _source);
6713 outline1("LDA %s", _source_size);
6714 outline0("STA <MATHPTR0");
6715 outline1("LDX %s", _pattern);
6716 outline1("LDA %s", _pattern_size);
6717 outline0("STA <MATHPTR1");
6718 outline1("LDU %s", _destination);
6719
6720 outline0("JSR CPUSTRINGSUB");
6721
6722 outline0("LDA <MATHPTR2");
6723 outline1("STA %s", _destination_size);
6724
6725 done()
6726}
6727
6728static char cpu_BLIT_REGISTER[][9] = {
6729 "BLITR0",
6730 "BLITR1",
6731 "BLITR2",
6732 "BLITR3"
6733};
6734
6735#define cpu_BLIT_REGISTER_COUNT ( sizeof( cpu_BLIT_REGISTER ) / 9 )
6736
6737void cpu_blit_initialize( Environment * _environment ) {
6738
6739 _environment->blit.freeRegisters = 0;
6740 _environment->blit.usedMemory = 0;
6741
6742}
6743
6744void cpu_blit_finalize( Environment * _environment ) {
6745
6746 _environment->blit.freeRegisters = 0;
6747 _environment->blit.usedMemory = 0;
6748
6749}
6750
6751char * cpu_blit_register_name( Environment * _environment, int _register ) {
6752
6753 if ( _register < cpu_BLIT_REGISTER_COUNT ) {
6754 return &cpu_BLIT_REGISTER[_register][0];
6755 } else {
6756 return &cpu_BLIT_REGISTER[ (_register & 0xff00) >> 8][0];
6757 }
6758}
6759
6761
6762 int reg = 0;
6763
6764 for( reg = 0; reg < cpu_BLIT_REGISTER_COUNT; ++reg ) {
6765 int registerMask = ( 0x01 << reg );
6766 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
6767 if ( ! isRegisterUsed ) {
6768 _environment->blit.freeRegisters |= registerMask;
6769 return reg;
6770 }
6771 }
6772
6773 int location = _environment->blit.usedMemory++;
6774
6775 if ( location > 0xff ) {
6777 }
6778
6779 for( reg = 0; reg < cpu_BLIT_REGISTER_COUNT; ++reg ) {
6780 int registerMask = ( 0x10 << reg );
6781 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
6782 if ( ! isRegisterUsed ) {
6783 outline1( "LDA %s", &cpu_BLIT_REGISTER[reg][0] );
6784 outline2( "STA %sbs+$%2.2x", _environment->blit.realName, location );
6785 _environment->blit.freeRegisters |= registerMask;
6786 return ( ( (reg+1) << 8 ) | location );
6787 }
6788 }
6789
6791
6792}
6793
6794void cpu_blit_free_register( Environment * _environment, int _register ) {
6795
6796 // printf( "z80_blit_free_register($%4.4x)\n", _register );
6797
6798 int location = _register & 0xff;
6799 int reg;
6800
6801 if ( _register < cpu_BLIT_REGISTER_COUNT ) {
6802 int registerMask = ( 0x01 << _register );
6803 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
6804 if ( isRegisterUsed ) {
6805 _environment->blit.freeRegisters &= ~registerMask;
6806 return;
6807 } else {
6808 CRITICAL_BLIT_INVALID_FREE_REGISTER( _environment->blit.name, _register );
6809 }
6810 } else {
6811 int registerMask = 0x10 << ( ( ( _register >> 8 ) & 0xff ) - 1 );
6812 int isRegisterUsed = _environment->blit.freeRegisters & registerMask;
6813 if ( isRegisterUsed ) {
6814 outline2( "LDA (%sbs+$%2.2x)", _environment->blit.realName, location );
6815 outline1( "LDA %s", &cpu_BLIT_REGISTER[reg][0] );
6816 _environment->blit.freeRegisters &= ~registerMask;
6817 return;
6818 }
6819 }
6820
6821 CRITICAL_BLIT_INVALID_FREE_REGISTER( _environment->blit.name, _register );
6822
6823}
6824
6833void cpu_store_nbit( Environment * _environment, char *_destination, int _n, int _value[] ) {
6834
6835 int n = _n >> 3;
6836 int i = 0;
6837 while( _n ) {
6838 char destinationAddress[MAX_TEMPORARY_STORAGE]; sprintf( destinationAddress, "%s+%d", _destination, i*4 );
6839 if ( _n <= 32 ) {
6840 switch( _n ) {
6841 case 1: case 2: case 3: case 4:
6842 case 5: case 6: case 7: case 8:
6843 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4)] & (0xff>>(8-_n)) ) );
6844 i+=1;
6845 break;
6846 case 9: case 10: case 11: case 12:
6847 case 13: case 14: case 15: case 16:
6848 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4)] & (0xff>>(16-_n)) ) );
6849 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6850 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+1)] & (0xff) ) );
6851 break;
6852 case 17: case 18: case 19: case 20:
6853 case 21: case 22: case 23: case 24:
6854 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4)] & (0xff>>(24-_n)) ) );
6855 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6856 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+1)] & (0xff) ) );
6857 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6858 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+2)] & (0xff) ) );
6859 break;
6860 case 25: case 26: case 27: case 28:
6861 case 29: case 30: case 31: case 32:
6862 default:
6863 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4)] & (0xff>>(32-_n)) ) );
6864 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6865 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+1)] & (0xff) ) );
6866 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6867 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+2)] & (0xff) ) );
6868 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
6869 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+3)] & (0xff) ) );
6870 break;
6871 }
6872 _n = 0;
6873 } else {
6874 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4)] & (0xff) ) );
6875 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6876 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+1)] & (0xff) ) );
6877 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6878 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+2)] & (0xff) ) );
6879 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
6880 cpu_store_8bit( _environment, destinationAddress, ( _value[n-1-(i*4+3)] & (0xff) ) );
6881 _n -= 32;
6882 }
6883 ++i;
6884 }
6885
6886
6887}
6888
6897void cpu_move_nbit( Environment * _environment, int _n, char * _source, char *_destination ) {
6898
6899 int i = 0;
6900 while( _n ) {
6901 char sourceAddress[MAX_TEMPORARY_STORAGE]; sprintf( sourceAddress, "%s+%d", _source, i*4 );
6902 char destinationAddress[MAX_TEMPORARY_STORAGE]; sprintf( destinationAddress, "%s+%d", _destination, i*4 );
6903 if ( _n <= 32 ) {
6904 switch( _n ) {
6905 case 1: case 2: case 3: case 4:
6906 case 5: case 6: case 7: case 8:
6907 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6908 break;
6909 case 9: case 10: case 11: case 12:
6910 case 13: case 14: case 15: case 16:
6911 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6912 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
6913 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6914 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6915 break;
6916 case 17: case 18: case 19: case 20:
6917 case 21: case 22: case 23: case 24:
6918 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6919 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
6920 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6921 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6922 sprintf( sourceAddress, "%s+%d", _source, i*4+2 );
6923 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6924 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6925 break;
6926 case 25: case 26: case 27: case 28:
6927 case 29: case 30: case 31: case 32:
6928 default:
6929 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6930 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
6931 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6932 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6933 sprintf( sourceAddress, "%s+%d", _source, i*4+2 );
6934 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6935 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6936 sprintf( sourceAddress, "%s+%d", _source, i*4+3 );
6937 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
6938 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6939 break;
6940 }
6941 _n = 0;
6942 } else {
6943 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6944 sprintf( sourceAddress, "%s+%d", _source, i*4+1 );
6945 sprintf( destinationAddress, "%s+%d", _destination, i*4+1 );
6946 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6947 sprintf( sourceAddress, "%s+%d", _source, i*4+2 );
6948 sprintf( destinationAddress, "%s+%d", _destination, i*4+2 );
6949 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6950 sprintf( sourceAddress, "%s+%d", _source, i*4+3 );
6951 sprintf( destinationAddress, "%s+%d", _destination, i*4+3 );
6952 cpu_move_8bit( _environment, sourceAddress, destinationAddress );
6953 _n -= 32;
6954 }
6955 ++i;
6956 }
6957
6958}
6959
6960void cpu_move_nbit_indirect( Environment * _environment, int _n, char *_source, char * _value ) {
6961
6962 outline1("LDX %s", _value);
6963
6964 char step[MAX_TEMPORARY_STORAGE];
6965 char step1[MAX_TEMPORARY_STORAGE];
6966 char step2[MAX_TEMPORARY_STORAGE];
6967 char step3[MAX_TEMPORARY_STORAGE];
6968
6969 int stepIndex = 0;
6970 while( _n ) {
6971 sprintf( step, "%d", stepIndex );
6972 sprintf( step1, "%d", stepIndex+1 );
6973 sprintf( step2, "%d", stepIndex+2 );
6974 sprintf( step3, "%d", stepIndex+3 );
6975 if ( _n >= 32 ) {
6976 outline1("LDD %s", address_displacement(_environment, _source, step) );
6977 outline1("STD %d,X", stepIndex);
6978 outline1("LDD %s", address_displacement(_environment, _source, step2) );
6979 outline1("STD %d,X", stepIndex+2);
6980 stepIndex += 4;
6981 _n -= 32;
6982 } else {
6983 switch( _n ) {
6984 case 32: case 31: case 30: case 29:
6985 case 28: case 27: case 26: case 25:
6986 outline1("LDD %s", address_displacement(_environment, _source, step) );
6987 outline1("STD %d,X", stepIndex);
6988 outline1("LDD %s", address_displacement(_environment, _source, step2) );
6989 outline1("STD %d,X", stepIndex+2);
6990 break;
6991 case 24: case 23: case 22: case 21:
6992 case 20: case 19: case 18: case 17:
6993 outline1("LDD %s", address_displacement(_environment, _source, step) );
6994 outline1("STD %d,X", stepIndex);
6995 outline1("LDA %s", address_displacement(_environment, _source, step2) );
6996 outline1("STA %d,X", stepIndex+2);
6997 break;
6998 case 16: case 15: case 14: case 13:
6999 case 12: case 11: case 10: case 9:
7000 outline1("LDD %s", address_displacement(_environment, _source, step) );
7001 outline1("STD %d,X", stepIndex);
7002 break;
7003 case 8: case 7: case 6: case 5:
7004 case 4: case 3: case 2: case 1:
7005 outline1("LDA %s", address_displacement(_environment, _source, step) );
7006 outline1("STA %d,X", stepIndex);
7007 break;
7008 }
7009 _n = 0;
7010 }
7011 }
7012
7013}
7014
7015void cpu_move_nbit_indirect2( Environment * _environment, int _n, char * _value, char *_source ) {
7016
7017 outline1("LDX %s", _value);
7018
7019 char step[MAX_TEMPORARY_STORAGE];
7020 char step1[MAX_TEMPORARY_STORAGE];
7021 char step2[MAX_TEMPORARY_STORAGE];
7022 char step3[MAX_TEMPORARY_STORAGE];
7023
7024 int stepIndex = 0;
7025 while( _n ) {
7026 sprintf( step, "%d", stepIndex );
7027 sprintf( step1, "%d", stepIndex+1 );
7028 sprintf( step2, "%d", stepIndex+2 );
7029 sprintf( step3, "%d", stepIndex+3 );
7030 if ( _n >= 32 ) {
7031 outline1("LDD %d,X", stepIndex);
7032 outline1("STD %s", address_displacement(_environment, _source, step) );
7033 outline1("LDD %d,X", stepIndex+2);
7034 outline1("STD %s", address_displacement(_environment, _source, step2) );
7035 stepIndex += 4;
7036 _n -= 32;
7037 } else {
7038 switch( _n ) {
7039 case 32: case 31: case 30: case 29:
7040 case 28: case 27: case 26: case 25:
7041 outline1("LDD %d,X", stepIndex);
7042 outline1("STD %s", address_displacement(_environment, _source, step) );
7043 outline1("LDD %d,X", stepIndex+2);
7044 outline1("STD %s", address_displacement(_environment, _source, step2) );
7045 break;
7046 case 24: case 23: case 22: case 21:
7047 case 20: case 19: case 18: case 17:
7048 outline1("LDD %d,X", stepIndex);
7049 outline1("STD %s", address_displacement(_environment, _source, step) );
7050 outline1("LDA %d,X", stepIndex+2);
7051 outline1("STA %s", address_displacement(_environment, _source, step2) );
7052 break;
7053 case 16: case 15: case 14: case 13:
7054 case 12: case 11: case 10: case 9:
7055 outline1("LDD %d,X", stepIndex);
7056 outline1("STD %s", address_displacement(_environment, _source, step) );
7057 break;
7058 case 8: case 7: case 6: case 5:
7059 case 4: case 3: case 2: case 1:
7060 outline1("LDA %d,X", stepIndex);
7061 outline1("STA %s", address_displacement(_environment, _source, step) );
7062 break;
7063 }
7064 _n = 0;
7065 }
7066 }
7067
7068}
7069
7070
7071
7072//
7073// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
7074// SINGLE (40) eeeeeeee smmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
7075//
7076
7077void cpu_float_fast_from_double_to_int_array( Environment * _environment, double _value, int _result[] ) {
7078 cpu_float_single_from_double_to_int_array( _environment, _value, _result );
7079}
7080
7081void cpu_float_single_from_double_to_int_array( Environment * _environment, double _value, int _result[] ) {
7082
7083 double value = 0.0;
7084 double integral = 0.0;
7085 double fractional = 0.0;
7086 int sign = 0;
7087 int left = 0;
7088 int right[4];
7089 int steps = 0;
7090 int exp = 0;
7091 int mantissa_bits = 31;
7092
7093 // printf("value = %f\n", _value );
7094
7095 memset( &right[0], 0, sizeof( int ) * 4 );
7096
7097 // Step 1: Determine Sign
7098 // If the number is positive, then the sign bit will be 0. If the number is negative, then the sign bit
7099 // will be 1. For the number zero, both positive and negative zero are possible, and these are considered
7100 // different values (a quirk of using sign bits).
7101
7102 if ( _value >= 0 ) {
7103 sign = 0;
7104 } else {
7105 sign = 1;
7106 }
7107
7108 value = fabs( _value );
7109 // Step 2: Convert the Integral Portion to Unsigned Binary
7110 // Convert the integral portion of the floating-point value to unsigned binary (not two's complement).
7111
7112 // The integral portion is the part of the number before the decimal point. For example, if the
7113 // number to convert is -0.75, then 0 is the integral portion, and it's unsigned binary representation
7114 // is simply 0. As another example, if the number to convert is 127.99, then the integral portion would
7115 // be 127, and it's unsigned binary representation is 1111111.
7116
7117 fractional = modf(value, &integral);
7118
7119 left = (unsigned int) integral;
7120
7121 // printf(" integral = %f (%d)\n", integral, left );
7122
7123 // Step 3: Convert the Fractional Portion to Binary
7124 // The fractional portion of the number must also be converted to binary, though the conversion process
7125 // is much different from what you're used to. The algorithm you'll used is based on performing repeated
7126 // multiplications by 2, and then checking if the result is >= 1.0. If the result is >= 1.0, then a 1 is
7127 // recorded for the binary fractional component, and the leading 1 is chopped of the result. If the
7128 // result is < 1.0, then a 0 is recorded for the binary fractional component, and the result is kept
7129 // as-is. The recorded builds are built-up left-to-right. The result keeps getting chained along in this
7130 // way until one of the following is true:
7131 // - The result is exactly 1.0
7132 // - 23 iterations of this process have occurred; i.e. the final converted binary value holds 23 bits
7133 // With the first possible terminating condition (the result is exactly 1.0), this means that the fractional
7134 // component has been represented without any loss of precision. With the second possible terminating
7135 // condition (23 iterations have passed), this means that we ran out of bits in the final result, which
7136 // can never exceed 23. In this case, precision loss occurs (an unfortunate consequence of using a finite
7137 // number of bits).
7138
7139 while( ( fractional != 1.0 ) && ( steps < mantissa_bits ) ) {
7140
7141 // 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] );
7142
7143 right[3] = right[3] << 1;
7144 right[2] = right[2] << 1;
7145 right[1] = right[1] << 1;
7146 right[0] = right[0] << 1;
7147 if ( ( right[3] & 0x100 ) ) {
7148 right[2] = right[2] | 0x1;
7149 }
7150 if ( ( right[2] & 0x100 ) ) {
7151 right[1] = right[1] | 0x1;
7152 }
7153 if ( ( right[1] & 0x100 ) ) {
7154 right[0] = right[0] | 0x1;
7155 }
7156 right[3] = right[3] & 0xff;
7157 right[2] = right[2] & 0xff;
7158 right[1] = right[1] & 0xff;
7159 right[0] = right[0] & 0x7f;
7160
7161 fractional = fractional * 2;
7162
7163 if ( fractional >= 1.0 ) {
7164 right[3] |= 1;
7165 fractional = modf(fractional, &integral);
7166 }
7167
7168 ++steps;
7169
7170 }
7171
7172 // Step 4: Normalize the Value via Adjusting the Exponent
7173 // A trick to encode an extra bit is to make it so that the binary scientific representation is always
7174 // of the form 1.XXXX * 2YYYY. That is, a 1 always leads, so there is no need to explicitly encode it.
7175 // In order to encode this properly, we need to move the decimal point to a position where it is
7176 // immediately after the first 1, and then record exactly how we moved it. To see this in action, consider
7177 // again the example of 0.75, which is encoded in binary as such (not IEEE-754 notation):
7178 // 0.11
7179 // 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:
7180 // 1.1
7181 // Most importantly, we need to record that we moved the decimal point by one position to the right.
7182 // Moves to the right result in negative exponents, and moves to the left result in positive exponents.
7183 // In this case, because we moved the decimal point one position to the right, the recorded exponent should be -1.
7184 // As another example, consider the following binary floating point representation (again, not IEEE-754):
7185 // 1111111.11100
7186 // 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:
7187 // 1.11111111100
7188 // Because this moves six positions to the left, the recorded exponent should be 6.
7189
7190 int mantissa_high_bit = 0x80000000 >> ( 32 - mantissa_bits);
7191 int mantissa_mask = 0xffffffff >> ( 32 - mantissa_bits);
7192
7193 if ( left == 0 ) {
7194
7195 if ( value != 0 ) {
7196
7197 while( left == 0 ) {
7198
7199 // 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] );
7200
7201 if ( ! right[0] && ! right[1] && ! right[2] && ! right[3] ) {
7202 left = 0x1;
7203 }
7204
7205 if ( right[0] & 0x40 ) {
7206 left = 0x1;
7207 }
7208
7209 right[0] = right[0] << 1;
7210 right[1] = right[1] << 1;
7211 right[2] = right[2] << 1;
7212 right[3] = right[3] << 1;
7213 if ( ( right[1] & 0x100 )) {
7214 right[0] = right[0] | 0x1;
7215 }
7216 if ( ( right[2] & 0x100 )) {
7217 right[1] = right[1] | 0x1;
7218 }
7219 if ( ( right[3] & 0x100 )) {
7220 right[2] = right[2] | 0x1;
7221 }
7222 right[0] = right[0] & 0x7f;
7223 right[1] = right[1] & 0xff;
7224 right[2] = right[2] & 0xff;
7225 right[3] = right[3] & 0xff;
7226
7227 --exp;
7228 }
7229
7230 ++exp;
7231
7232 } else {
7233
7234 exp = -128;
7235
7236 }
7237
7238 // 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] );
7239
7240 } else {
7241
7242 while( left ) {
7243
7244 // 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] );
7245
7246 if ( ( right[0] & 0x01 ) ) {
7247 right[1] = right[1] | 0x100;
7248 }
7249 if ( ( right[1] & 0x01 ) ) {
7250 right[2] = right[2] | 0x100;
7251 }
7252 if ( ( right[2] & 0x01 ) ) {
7253 right[3] = right[3] | 0x100;
7254 }
7255 right[0] = right[0] >> 1;
7256 right[1] = right[1] >> 1;
7257 right[2] = right[2] >> 1;
7258 right[3] = right[3] >> 1;
7259 if ( left & 0x1 ) {
7260 right[0] = right[0] | 0x40;
7261 }
7262 left = left >> 1;
7263 ++exp;
7264 }
7265 // --exp;
7266 left = 1;
7267 right[3] = right[3] << 1;
7268 right[2] = right[2] << 1;
7269 right[1] = right[1] << 1;
7270 right[0] = right[0] << 1;
7271 if ( right[3] & 0x100 ) {
7272 right[2] = right[2] | 0x01;
7273 }
7274 if ( right[2] & 0x100 ) {
7275 right[1] = right[1] | 0x01;
7276 }
7277 if ( right[1] & 0x100 ) {
7278 right[0] = right[0] | 0x01;
7279 }
7280 right[3] = right[3] & 0xff;
7281 right[2] = right[2] & 0xff;
7282 right[1] = right[1] & 0xff;
7283 right[0] = right[0] & 0x7f;
7284
7285 }
7286
7287 // Step 5: Add Bias to the Exponent
7288 // Internally, IEEE-754 values store their exponents in an unsigned representation, which may seem odd considering that
7289 // the exponent can be negative. Negative exponents are accomodated by using a biased representation, wherein a
7290 // pre-set number is always subtracted from the given unsigned number. Because the given unsigned number may be less
7291 // than this number, this allows for negative values to be effectively encoded without resorting to two's complement.
7292 // Specifically, for the binary32 representation, the number 127 will be subtracted from anything encoded in the
7293 // exponent field of the IEEE-754 number. As such, in this step, we need to add 127 to the normalized exponent value
7294 // from the previous step.
7295
7296 exp += 127;
7297
7298 // printf("exp = %2.2x\n", exp );
7299
7300 // Step 6: Convert the Biased Exponent to Unsigned Binary
7301 // The biased exponent value from the previous step must be converted into unsigned binary, using the usual process.
7302 // The result must be exactly 8 bits. It should not be possible to need more than 8 bits. If fewer than 8 bits are
7303 // needed in this conversion process, then leading zeros must be added to the front of the result to produce an
7304 // 8-bit value.
7305
7306 exp = exp & 0xff;
7307
7308 // printf("exp = %2.2x\n", exp );
7309
7310 // Step 7: Determine the Final Bits for the Mantissa
7311 // After step 4, there are a bunch of bits after the normalized decimal point. These bits will become the
7312 // mantissa (note that we ignore the bits to the left of the decimal point - normalization allows us to do this,
7313 // because it should always be just a 1). We need exactly 23 mantissa bits. If less than 23 mantissa bits follow the
7314 // decimal point, and the algorithm in step 3 ended with a result that wasn't 1.0, then follow the algorithm in step 3
7315 // until we can fill enough bits. If that's still not enough (eventually reaching 1.0 before we had enough bits, or
7316 // perhaps it had ended with 1.0 already), then the right side can be padded with zeros until 23 bits is reached.
7317 // If there are more than 23 bits after the decimal point in step 4, then these extra bits are simply cutoff from the
7318 // right. For example, if we had 26 bits to the right of the decimal point, then the last three would need to be cutoff
7319 // to get us to 23 bits. Note that in this case we will necessarily lose some precision.
7320
7321 if ( _value == 0.0f ) {
7322 exp = 0;
7323 }
7324
7325 // Step 8: Put it All Together
7326 // 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
7327 // step 6. The last 23 bits will be from the mantissa from step 7. The result will be a 32-bit number encoded in
7328 // IEEE-754 binary32 format, assuming no mistakes were made in the process.
7329
7330 // [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
7331 // SINGLE (32) seeeeeee emmmmmmm mmmmmmmm mmmmmmmm
7332
7333 _result[0] = exp & 0xff;
7334 _result[1] = ( sign << 7 ) | ( right[0] & 0x7f );
7335 _result[2] = ( right[1] );
7336 _result[3] = ( right[2] );
7337 _result[4] = ( right[3] );
7338
7339 int tmp;
7340
7341 tmp = _result[0];
7342 _result[0] = _result[4];
7343 _result[4] = tmp;
7344
7345 tmp = _result[1];
7346 _result[1] = _result[3];
7347 _result[3] = tmp;
7348
7349 // 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] );
7350
7351}
7352
7353void cpu_float_fast_to_string( Environment * _environment, char * _x, char * _string, char * _string_size ) {
7354 cpu_float_single_to_string( _environment, _x, _string, _string_size );
7355}
7356
7357void cpu_float_single_to_string( Environment * _environment, char * _x, char * _string, char * _string_size ) {
7358
7360
7361 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7362
7363 outline0( "LDU #FPSPAREA" );
7364 outline1( "LDX #%s",_x );
7365 outline0( "JSR FPLOD" );
7366
7367 outline1( "LDY %s", _string );
7368
7369 outline0( "JSR FPSCIENT" );
7370
7371 outline0( "TFR Y, D" );
7372 outline1( "SUBD %s", _string );
7373 outline1( "STB %s", _string_size );
7374
7375}
7376
7377void cpu_float_fast_from_8( Environment * _environment, char * _value, char * _result, int _signed ) {
7378 cpu_float_single_from_8( _environment, _value, _result, _signed );
7379}
7380
7381void cpu_float_single_from_8( Environment * _environment, char * _value, char * _result, int _signed ) {
7382
7383 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7384
7385 outline0( "CLRA" );
7386 outline1( "LDB %s", _value );
7387 outline0( "LDU #FPSPAREA" );
7388
7389 if ( _signed ) {
7390 outline0( "JSR INT2FP" );
7391 } else {
7392 outline0( "JSR UNINT2FP" );
7393 }
7394
7395 outline1( "LDX #%s", _result );
7396 outline0( "JSR FPSTO" );
7397
7398}
7399
7400void cpu_float_fast_from_16( Environment * _environment, char * _value, char * _result, int _signed ) {
7401 cpu_float_single_from_16( _environment, _value, _result, _signed );
7402}
7403
7404void cpu_float_single_from_16( Environment * _environment, char * _value, char * _result, int _signed ) {
7405
7406 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7407
7408 outline1( "LDD %s", _value );
7409 outline0( "LDU #FPSPAREA" );
7410
7411 if ( _signed ) {
7412 outline0( "JSR INT2FP" );
7413 } else {
7414 outline0( "JSR UNINT2FP" );
7415 }
7416
7417 outline1( "LDX #%s", _result );
7418 outline0( "JSR FPSTO" );
7419
7420}
7421
7422void cpu_float_fast_to_8( Environment * _environment, char * _value, char * _result, int _signed ) {
7423 cpu_float_single_to_8( _environment, _value, _result, _signed );
7424}
7425
7426void cpu_float_single_to_8( Environment * _environment, char * _value, char * _result, int _signed ) {
7427
7428 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7429
7430 outline0( "LDU #FPSPAREA" );
7431 outline1( "LDX #%s", _value );
7432 outline0( "JSR FPLOD" );
7433
7434 if ( _signed ) {
7435 outline0( "JSR FP2INT" );
7436 } else {
7437 outline0( "JSR FP2UINT" );
7438 }
7439 outline1( "STB %s", _result );
7440
7441}
7442
7443void cpu_float_fast_to_16( Environment * _environment, char * _value, char * _result, int _signed ) {
7444 cpu_float_single_to_16( _environment, _value, _result, _signed );
7445}
7446
7447void cpu_float_single_to_16( Environment * _environment, char * _value, char * _result, int _signed ) {
7448
7449 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7450
7451 outline0( "LDU #FPSPAREA" );
7452 outline1( "LDX #%s", _value );
7453 outline0( "JSR FPLOD" );
7454
7455 if ( _signed ) {
7456 outline0( "JSR FP2INT" );
7457 } else {
7458 outline0( "JSR FP2UINT" );
7459 }
7460 outline1( "STD %s", _result );
7461
7462}
7463
7464void cpu_float_fast_sub( Environment * _environment, char * _x, char * _y, char * _result ) {
7465 cpu_float_single_sub( _environment, _x, _y, _result );
7466}
7467
7468void cpu_float_single_sub( Environment * _environment, char * _x, char * _y, char * _result ) {
7469
7470 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7471
7472 outline0( "LDU #FPSPAREA" );
7473 outline1( "LDX #%s", _x );
7474 outline0( "JSR FPLOD" );
7475 outline1( "LDX #%s", _y );
7476 outline0( "JSR FPLOD" );
7477
7478 outline0( "JSR FPSUB" );
7479
7480 outline1( "LDX #%s", _result );
7481 outline0( "JSR FPSTO" );
7482
7483}
7484
7485void cpu_float_fast_add( Environment * _environment, char * _x, char * _y, char * _result ) {
7486 cpu_float_single_add( _environment, _x, _y, _result );
7487}
7488
7489void cpu_float_single_add( Environment * _environment, char * _x, char * _y, char * _result ) {
7490
7491 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7492
7493 outline0( "LDU #FPSPAREA" );
7494 outline1( "LDX #%s", _x );
7495 outline0( "JSR FPLOD" );
7496 outline1( "LDX #%s", _y );
7497 outline0( "JSR FPLOD" );
7498
7499 outline0( "JSR FPADD" );
7500
7501 outline1( "LDX #%s", _result );
7502 outline0( "JSR FPSTO" );
7503
7504}
7505
7506void cpu_float_fast_cmp( Environment * _environment, char * _x, char * _y, char * _result ) {
7507 cpu_float_single_cmp( _environment, _x, _y, _result );
7508}
7509
7510void cpu_float_single_cmp( Environment * _environment, char * _x, char * _y, char * _result ) {
7511
7513
7514 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7515
7516 outline0( "LDU #FPSPAREA" );
7517 outline1( "LDX #%s", _x );
7518 outline0( "JSR FPLOD" );
7519 outline1( "LDX #%s", _y );
7520 outline0( "JSR FPLOD" );
7521
7522 outline0( "JSR FPCMP" );
7523
7524 outline1( "BEQ %sequal", label );
7525 outline1( "BCS %sless", label );
7526 outline0( "LDA #$1" );
7527 outline1( "STA %s", _result );
7528 outline1( "JMP %sdone", label );
7529 outhead1( "%sequal", label );
7530 outline0( "LDA #$0" );
7531 outline1( "STA %s", _result );
7532 outline1( "JMP %sdone", label );
7533 outhead1( "%sless", label );
7534 outline0( "LDA #$ff" );
7535 outline1( "STA %s", _result );
7536 outline1( "JMP %sdone", label );
7537 outhead1( "%sdone", label );
7538
7539}
7540
7541void cpu_float_fast_mul( Environment * _environment, char * _x, char * _y, char * _result ) {
7542 cpu_float_single_mul( _environment, _x, _y, _result );
7543}
7544
7545void cpu_float_single_mul( Environment * _environment, char * _x, char * _y, char * _result ) {
7546
7547 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7548
7549 outline0( "LDU #FPSPAREA" );
7550 outline1( "LDX #%s", _x );
7551 outline0( "JSR FPLOD" );
7552 outline1( "LDX #%s", _y );
7553 outline0( "JSR FPLOD" );
7554
7555 outline0( "JSR FPMUL" );
7556
7557 outline1( "LDX #%s", _result );
7558 outline0( "JSR FPSTO" );
7559
7560}
7561
7562void cpu_float_fast_div( Environment * _environment, char * _x, char * _y, char * _result ) {
7563 cpu_float_single_div( _environment, _x, _y, _result );
7564}
7565
7566void cpu_float_single_div( Environment * _environment, char * _x, char * _y, char * _result ) {
7567
7568 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7569
7570 outline0( "LDU #FPSPAREA" );
7571 outline1( "LDX #%s", _x );
7572 outline0( "JSR FPLOD" );
7573 outline1( "LDX #%s", _y );
7574 outline0( "JSR FPLOD" );
7575
7576 outline0( "JSR FPDIV" );
7577
7578 outline1( "LDX #%s", _result );
7579 outline0( "JSR FPSTO" );
7580
7581}
7582
7583void cpu_float_fast_sin( Environment * _environment, char * _angle, char * _result ) {
7584 cpu_float_single_sin( _environment, _angle, _result );
7585}
7586
7587void cpu_float_single_sin( Environment * _environment, char * _angle, char * _result ) {
7588
7589 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7590
7591 outline0( "LDU #FPSPAREA" );
7592 outline1( "LDX #%s", _angle );
7593 outline0( "JSR FPLOD" );
7594
7595 outline0( "JSR FPSIN" );
7596
7597 outline1( "LDX #%s", _result );
7598 outline0( "JSR FPSTO" );
7599
7600}
7601
7602void cpu_float_fast_cos( Environment * _environment, char * _angle, char * _result ) {
7603 cpu_float_single_cos( _environment, _angle, _result );
7604}
7605
7606void cpu_float_single_cos( Environment * _environment, char * _angle, char * _result ) {
7607
7608 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7609
7610 outline0( "LDU #FPSPAREA" );
7611 outline1( "LDX #%s", _angle );
7612 outline0( "JSR FPLOD" );
7613
7614 outline0( "JSR FPCOS" );
7615
7616 outline1( "LDX #%s", _result );
7617 outline0( "JSR FPSTO" );
7618
7619}
7620
7621void cpu_float_fast_tan( Environment * _environment, char * _angle, char * _result ) {
7622 cpu_float_single_tan( _environment, _angle, _result );
7623}
7624
7625void cpu_float_single_tan( Environment * _environment, char * _angle, char * _result ) {
7626
7627 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7628
7629 outline0( "LDU #FPSPAREA" );
7630 outline1( "LDX #%s", _angle );
7631 outline0( "JSR FPLOD" );
7632
7633 outline0( "JSR FPTAN" );
7634
7635 outline1( "LDX #%s", _result );
7636 outline0( "JSR FPSTO" );
7637
7638}
7639
7640void cpu_float_fast_log( Environment * _environment, char * _value, char * _result ) {
7641 cpu_float_single_log( _environment, _value, _result );
7642}
7643
7644void cpu_float_single_log( Environment * _environment, char * _value, char * _result ) {
7645
7646 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7647
7648 outline0( "LDU #FPSPAREA" );
7649 outline1( "LDX #%s", _value );
7650 outline0( "JSR FPLOD" );
7651
7652 outline0( "JSR FPLN" );
7653
7654 outline1( "LDX #%s", _result );
7655 outline0( "JSR FPSTO" );
7656
7657}
7658
7659void cpu_float_fast_exp( Environment * _environment, char * _value, char * _result ) {
7660 cpu_float_single_exp( _environment, _value, _result );
7661}
7662
7663void cpu_float_single_exp( Environment * _environment, char * _value, char * _result ) {
7664
7665 deploy( fp_vars, src_hw_6809_fp_routines_asm );
7666
7667 outline0( "LDU #FPSPAREA" );
7668 outline1( "LDX #%s", _value );
7669 outline0( "JSR FPLOD" );
7670
7671 outline0( "JSR FPEXP" );
7672
7673 outline1( "LDX #%s", _result );
7674 outline0( "JSR FPSTO" );
7675
7676}
7677
7678void cpu_address_table_build( Environment * _environment, char * _table, int * _values, char *_address[], int _count ) {
7679
7680 outhead1("%s", _table );
7681 for( int i=0; i<_count; ++i ) {
7682 outline2("fdb $%4.4x, %s", _values[i], _address[i] );
7683 }
7684
7685}
7686
7687void cpu_address_table_lookup( Environment * _environment, char * _table, int _count ) {
7688
7689 outhead1("LOOKFOR%s", _table );
7690 if ( _count ) {
7691 outline1("LDX #%s", _table );
7692 outline0("LDU #0" );
7693 outhead1("LOOKFOR%sL1", _table );
7694 outline0("CMPD , X" );
7695 outline1("BNE LOOKFOR%sNEXT4", _table );
7696 outline0("LDD 2, X" );
7697 outline0("RTS" );
7698 outhead1("LOOKFOR%sNEXT4", _table );
7699 outline0("LEAX 4, X" );
7700 outline0("LEAU 4, U" );
7701 outline1("CMPU #$%4.4x", (_count+1) * 4 );
7702 outline1("BNE LOOKFOR%sL1", _table );
7703 }
7704 outline0("RTS" );
7705
7706}
7707
7708void cpu_address_table_call( Environment * _environment, char * _table, char * _value, char * _address ) {
7709
7710 outline1("LDD %s", _value );
7711 outline1("JSR LOOKFOR%s", _table );
7712 outline1("STD %s", _address );
7713
7714}
7715
7716void cpu_move_8bit_signed_16bit_signed( Environment * _environment, char *_source, char *_destination ) {
7717
7718 outline1("LDB %s", _source );
7719 outline0("SEX" );
7720 outline1("STD %s", _destination );
7721
7722}
7723
7724void cpu_move_8bit_signed_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7725
7726 outline1("LDB %s", _source );
7727 outline0("SEX" );
7728 outline1("STD %s", _destination );
7729
7730}
7731
7732void cpu_move_8bit_unsigned_16bit_signed( Environment * _environment, char *_source, char *_destination ){
7733
7734 outline1("LDB %s", _source );
7735 outline0("LDA #0" );
7736 outline1("STD %s", _destination );
7737
7738}
7739
7740void cpu_move_8bit_unsigned_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7741
7742 outline1("LDB %s", _source );
7743 outline0("LDA #0" );
7744 outline1("STD %s", _destination );
7745
7746}
7747
7748void cpu_move_8bit_signed_32bit_signed( Environment * _environment, char *_source, char *_destination ){
7749
7750 outline1("LDB %s", _source );
7751 outline0("SEX" );
7752 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7753 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
7754 outline1("STA %s", _destination );
7755
7756}
7757
7758void cpu_move_8bit_signed_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7759
7760 outline1("LDB %s", _source );
7761 outline0("SEX" );
7762 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7763 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
7764 outline1("STA %s", _destination );
7765
7766}
7767
7768void cpu_move_8bit_unsigned_32bit_signed( Environment * _environment, char *_source, char *_destination ){
7769
7770 outline1("LDB %s", _source );
7771 outline0("LDA #0" );
7772 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7773 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
7774 outline1("STA %s", _destination );
7775
7776}
7777void cpu_move_8bit_unsigned_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7778
7779 outline1("LDB %s", _source );
7780 outline0("LDA #0" );
7781 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7782 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
7783 outline1("STA %s", _destination );
7784
7785}
7786
7787void cpu_move_16bit_signed_8bit_signed( Environment * _environment, char *_source, char *_destination ){
7788
7789 outline1("LDD %s", _source );
7790 outline1("STB %s", _destination );
7791
7792}
7793void cpu_move_16bit_signed_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7794
7795 outline1("LDD %s", _source );
7796 outline1("STB %s", _destination );
7797
7798}
7799void cpu_move_16bit_unsigned_8bit_signed( Environment * _environment, char *_source, char *_destination ){
7800
7801 outline1("LDD %s", _source );
7802 outline1("STB %s", _destination );
7803
7804}
7805void cpu_move_16bit_unsigned_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7806
7807 outline1("LDD %s", _source );
7808 outline1("STB %s", _destination );
7809
7810}
7811
7812void cpu_move_16bit_signed_32bit_signed( Environment * _environment, char *_source, char *_destination ){
7813
7814 outline1("LDB %s", _source );
7815 outline0("SEX" );
7816 outline1("STA %s", address_displacement( _environment, _destination, "1" ) );
7817 outline1("STA %s", _destination );
7818 outline1("LDD %s", _source );
7819 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7820
7821}
7822void cpu_move_16bit_signed_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7823
7824 outline1("LDB %s", address_displacement( _environment, _source, "1" ) );
7825 outline0("SEX" );
7826 outline0("TFR A, B" );
7827 outline1("STD %s", _destination );
7828 outline1("LDD %s", _source );
7829 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7830
7831}
7832
7833void cpu_move_16bit_unsigned_32bit_signed( Environment * _environment, char *_source, char *_destination ){
7834
7835 outline0("LDD #0" );
7836 outline1("STD %s", _destination );
7837 outline1("LDD %s", _source );
7838 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7839
7840}
7841void cpu_move_16bit_unsigned_32bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7842
7843 outline0("LDD #0" );
7844 outline1("STD %s", _destination );
7845 outline1("LDD %s", _source );
7846 outline1("STD %s", address_displacement( _environment, _destination, "2" ) );
7847
7848}
7849
7850void cpu_move_32bit_signed_8bit_signed( Environment * _environment, char *_source, char *_destination ){
7851
7852 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
7853 outline1("STA %s", _destination );
7854
7855}
7856void cpu_move_32bit_signed_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7857
7858 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
7859 outline1("STA %s", _destination );
7860
7861}
7862void cpu_move_32bit_unsigned_8bit_signed( Environment * _environment, char *_source, char *_destination ){
7863
7864 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
7865 outline1("STA %s", _destination );
7866
7867}
7868void cpu_move_32bit_unsigned_8bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7869
7870 outline1("LDA %s", address_displacement( _environment, _source, "3" ) );
7871 outline1("STA %s", _destination );
7872
7873}
7874
7875void cpu_move_32bit_signed_16bit_signed( Environment * _environment, char *_source, char *_destination ){
7876
7877 outline1("LDD %s", address_displacement( _environment, _source, "2" ) );
7878 outline1("STD %s", _destination );
7879
7880}
7881
7882void cpu_move_32bit_signed_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7883
7884 outline1("LDD %s", address_displacement( _environment, _source, "2" ) );
7885 outline1("STD %s", _destination );
7886
7887}
7888
7889void cpu_move_32bit_unsigned_16bit_signed( Environment * _environment, char *_source, char *_destination ){
7890
7891 outline1("LDD %s", address_displacement( _environment, _source, "2" ) );
7892 outline1("STD %s", _destination );
7893
7894}
7895
7896void cpu_move_32bit_unsigned_16bit_unsigned( Environment * _environment, char *_source, char *_destination ){
7897
7898 outline1("LDD %s", address_displacement( _environment, _source, "2" ) );
7899 outline1("STD %s", _destination );
7900
7901}
7902
7903void cpu_encrypt( Environment * _environment, char * _data, char * _data_size, char * _key, char * _key_size, char * _output ) {
7904
7905 deploy( encrypt, src_hw_6809_encrypt_asm );
7906
7907 outline1("LDX %s", _data );
7908 outline1("LDU %s", _key );
7909 outline1("LDY %s", _output );
7910 outline1("LDA %s", _key_size );
7911 outline1("LDB %s", _data_size );
7912 outline0("JSR ENCRYPT" );
7913
7914}
7915
7916void cpu_decrypt( Environment * _environment, char * _data, char * _data_size, char * _key, char * _key_size, char * _output, char * _result ) {
7917
7918 deploy( decrypt, src_hw_6809_decrypt_asm );
7919
7920 outline1("LDX %s", _data );
7921 outline1("LDU %s", _key );
7922 outline1("LDY %s", _output );
7923 outline1("LDA %s", _key_size );
7924 outline1("LDB %s", _data_size );
7925 outline0("JSR DECRYPT" );
7926 cpu_ztoa( _environment );
7927 outline1("STA %s", _result );
7928
7929}
7930
7931void cpu_hex_to_bin( Environment * _environment, char * _value_address, char * _value_size, char * _variable_address, char * _variable_size, char * _result ) {
7932
7933 deploy( hex2bin, src_hw_6809_hex2bin_asm );
7934
7935 outline1("LDX %s", _value_address );
7936 outline1("LDA %s", _value_size );
7937 outline1("LDY %s", _variable_address );
7938 outline1("LDB %s", _variable_size );
7939 outline0("JSR HEX2BIN" );
7940 outline1("STA %s", _result );
7941
7942}
7943
7944void cpu_dsfill( Environment * _environment, char * _string, char * _value ) {
7945
7946 deploy_preferred( duff, src_hw_6809_duff_asm );
7947 deploy( dstring, src_hw_6809_dstring_asm );
7948
7949 outline1( "LDB %s", _string );
7950 outline1( "LDA %s", _value );
7951 outline0( "JSR DSFILL" );
7952
7953}
7954
7955void cpu_dsfill_value( Environment * _environment, char * _string, int _value ) {
7956
7957 deploy_preferred( duff, src_hw_6809_duff_asm );
7958 deploy( dstring, src_hw_6809_dstring_asm );
7959
7960 outline1( "LDB %s", _string );
7961 outline1( "LDA #$%2.2x", (unsigned char)(_value&0xff) );
7962 outline0( "JSR DSFILL" );
7963
7964}
7965
7966#endif
void cpu_and_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4258
void cpu_move_32bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6309.c:5398
void cpu_less_than_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6309.c:5034
void cpu_combine_nibbles(Environment *_environment, char *_low_nibble, char *_hi_nibble, char *_byte)
Definition 6309.c:3724
void cpu_math_double_32bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6309: emit code to double a 32 bit value
Definition 6309.c:3279
void cpu_not_16bit(Environment *_environment, char *_value, char *_result)
Definition 6309.c:4517
void cpu_math_mul2_const_16bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6309: emit code to halves for several times a 8 bit value
Definition 6309.c:2461
void cpu_math_div_16bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6309.c:2009
void cpu_math_mul_16bit_to_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _signed)
CPU 6309: emit code to multiply two 16 bit values in a 32 bit register
Definition 6309.c:1752
void cpu_bveq(Environment *_environment, char *_value, char *_label)
Definition 6309.c:334
void cpu_bit_check_extended(Environment *_environment, char *_value, char *_position, char *_result, int _bitwidth)
Definition 6309.c:5605
void cpu_math_mul2_const_8bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6309: emit code to double for several times a 8 bit value
Definition 6309.c:1397
void cpu_math_mul2_const_32bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6309: emit code to double for several times a 32 bit value
Definition 6309.c:3547
void cpu_uppercase(Environment *_environment, char *_source, char *_size, char *_result)
Definition 6309.c:5414
void cpu_math_add_16bit_with_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
Definition 6309.c:1708
void cpu_mem_move(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6309.c:4692
void cpu_math_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_math_add_32bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to add two 32 bit values
Definition 6309.c:3219
void cpu_store_char(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:785
void cpu_math_complement_const_32bit(Environment *_environment, char *_source, int _value)
CPU 6309: emit code to calculate a 32 bit complement of a number
Definition 6309.c:3352
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 16 bit
Definition 6309.c:1503
void cpu_math_double_16bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6309: emit code to double a 16 bit value
Definition 6309.c:1728
void cpu_math_sub_32bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to subtract two 32 bit values
Definition 6309.c:3304
void cpu_math_div2_const_8bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6309: emit code to halves for several times a 8 bit value
Definition 6309.c:1329
void cpu_less_than_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6309.c:4969
void cpu_math_div_nbit_to_nbit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _bits)
Definition 6309.c:2571
void cpu_math_add_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to add two 8 bit values
Definition 6309.c:1017
void cpu_move_8bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6309.c:5239
void cpu_string_sub(Environment *_environment, char *_source, char *_source_size, char *_pattern, char *_pattern_size, char *_destination, char *_destination_size)
Definition 6309.c:6370
void cpu_compare_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:811
void cpu_math_and_const_32bit(Environment *_environment, char *_source, int _mask)
CPU 6309: emit code to mask with "and" a value of 32 bit
Definition 6309.c:3698
void cpu_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_inc(Environment *_environment, char *_variable)
Definition 6309.c:4555
void cpu_jump_indirect(Environment *_environment, char *_value)
Definition 6309.c:3783
void cpu_math_complement_const_8bit(Environment *_environment, char *_source, int _value)
CPU 6309: emit code to calculate an 8 bit complement of a number
Definition 6309.c:1432
void cpu_math_complement_const_16bit(Environment *_environment, char *_source, int _value)
CPU 6309: emit code to calculate a 16 bit complement of a number
Definition 6309.c:2337
void cpu_math_mul2_const_nbit(Environment *_environment, char *_source, int _steps, int _bits)
Definition 6309.c:3664
void cpu_move_32bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 32 bit
Definition 6309.c:2520
void cpu_less_than_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:950
#define cpu_BLIT_REGISTER_COUNT
Definition 6309.c:6401
void cpu_dec_32bit(Environment *_environment, char *_variable)
Definition 6309.c:4652
void cpu_math_add_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to add two 16 bit values
Definition 6309.c:1661
void cpu_greater_than_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:1632
void cpu_math_add_16bit_const(Environment *_environment, char *_source, int _destination, char *_other)
Definition 6309.c:1674
void cpu_protothread_vars(Environment *_environment)
Definition 6309.c:6143
void cpu_math_add_16bit_with_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to add two 16 bit values
Definition 6309.c:1696
void cpu_compare_and_branch_16bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:1578
void cpu_move_32bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6309.c:5382
void cpu_greater_than_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:989
void cpu_or_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4320
void cpu_fill(Environment *_environment, char *_address, char *_bytes, int _bytes_width, char *_pattern)
CPU 6309: emit code to fill up a memory area
Definition 6309.c:534
void cpu_move_16bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6309.c:5339
void cpu_limit_16bit(Environment *_environment, char *_variable, int _value)
Definition 6309.c:4164
void cpu_move_8bit_indirect_with_offset2(Environment *_environment, char *_source, char *_value, char *_offset)
Definition 6309.c:5262
void cpu_less_than_32bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:2985
void cpu_and_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4216
void cpu_math_mul_8bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _signed)
CPU 6309: emit code to multiply two 8bit values in a 16 bit register
Definition 6309.c:1088
void cpu_math_sub_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to subtract two 16 bit values
Definition 6309.c:2305
void cpu_compare_and_branch_32bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 32 bit values and jump if they are equal/different
Definition 6309.c:2914
void cpu_math_and_const_16bit(Environment *_environment, char *_source, int _mask)
CPU 6309: emit code to mask with "and" a value of 16 bit
Definition 6309.c:2496
void cpu_move_8bit_indirect2_8bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6309.c:5307
void cpu_fill_indirect(Environment *_environment, char *_address, char *_size, char *_pattern, int _size_size)
Definition 6309.c:5517
void cpu_compare_and_branch_char_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:925
void cpu_less_than_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _bits)
Definition 6309.c:3065
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_dec(Environment *_environment, char *_variable)
Definition 6309.c:4630
void cpu_and_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4244
void cpu_logical_not_8bit(Environment *_environment, char *_value, char *_result)
Definition 6309.c:4493
void cpu_logical_and_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4198
void cpu_math_div2_const_32bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6309: emit code to halves for several times a 32 bit value
Definition 6309.c:3376
void cpu_halt(Environment *_environment)
Definition 6309.c:4050
void cpu_end(Environment *_environment)
Definition 6309.c:4064
void cpu_compare_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6309.c:4849
void cpu_xor_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4354
void cpu_lowercase(Environment *_environment, char *_source, char *_size, char *_result)
Definition 6309.c:5451
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 16 bit
Definition 6309.c:1474
void cpu_move_8bit_with_offset2(Environment *_environment, char *_source, char *_value, char *_offset)
Definition 6309.c:5278
void cpu_bneq(Environment *_environment, char *_label)
CPU 6309: emit code to make long conditional jump
Definition 6309.c:324
void cpu_move_16bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6309.c:5352
void cpu_less_than_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _bits)
Definition 6309.c:3021
void cpu_not_32bit(Environment *_environment, char *_value, char *_result)
Definition 6309.c:4530
void cpu_greater_than_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6309.c:5170
void cpu_hex_to_string(Environment *_environment, char *_number, char *_string, char *_size, int _separator)
Definition 6309.c:5865
void cpu_or_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4292
void cpu_move_8bit_indirect2_16bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6309.c:5323
void cpu_math_add_32bit_const(Environment *_environment, char *_source, int _destination, char *_other)
Definition 6309.c:3257
void cpu_greater_than_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:3117
void cpu_call_indirect(Environment *_environment, char *_value)
Definition 6309.c:3765
void cpu_call(Environment *_environment, char *_label)
Definition 6309.c:3755
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void cpu_swap_8bit(Environment *_environment, char *_left, char *_right)
Definition 6309.c:4451
void cpu_compare_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6309: emit code to compare two 32 bit values
Definition 6309.c:2769
void cpu_jump(Environment *_environment, char *_label)
Definition 6309.c:3739
void cpu_store_8bit_with_offset2(Environment *_environment, char *_source, char *_offset, int _value)
Definition 6309.c:6029
void cpu_fill_blocks(Environment *_environment, char *_address, char *_blocks, char *_pattern)
CPU 6309: emit code to fill up a memory area
Definition 6309.c:484
void cpu_bvneq(Environment *_environment, char *_value, char *_label)
Definition 6309.c:345
void cpu_compare_and_branch_16bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6309.c:1552
void cpu_poke(Environment *_environment, char *_address, char *_source)
Definition 6309.c:377
void cpu_less_than_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:960
void cpu_greater_than_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _bits)
Definition 6309.c:3189
void cpu_less_than_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:1603
void cpu_math_and_const_8bit(Environment *_environment, char *_source, int _mask)
CPU 6309: emit code to mask with "and" a value of 8 bit
Definition 6309.c:1451
void cpu_inc_32bit(Environment *_environment, char *_variable)
Definition 6309.c:4586
void cpu_xor_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4413
void cpu_return(Environment *_environment)
Definition 6309.c:4030
void cpu_move_8bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6309.c:5294
void cpu_inc_nbit(Environment *_environment, char *_variable, int _bits)
Definition 6309.c:4613
void cpu_pop(Environment *_environment)
Definition 6309.c:4040
void cpu_math_sub_16bit_with_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
Definition 6309.c:2317
void cpu_or_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4335
void cpu_math_div2_const_16bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6309: emit code to halves for several times a 16 bit value
Definition 6309.c:2356
void cpu_inc_16bit(Environment *_environment, char *_variable)
Definition 6309.c:4565
void cpu_logical_or_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4275
void cpu_compare_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive, int _bits)
Definition 6309.c:2804
void cpu_ztoa(Environment *_environment)
Definition 6309.c:262
void cpu_random(Environment *_environment, char *_entropy)
Definition 6309.c:4075
void cpu_compare_and_branch_8bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6309.c:851
void cpu_ctoa(Environment *_environment)
Definition 6309.c:279
void cpu_move_16bit_indirect2_8bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6309.c:5365
void cpu_math_sub_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6309.c:3325
void cpu_math_div2_const_nbit(Environment *_environment, char *_source, int _steps, int _bits, char *_remainder)
Definition 6309.c:3503
void cpu_busy_wait(Environment *_environment, char *_timing)
Definition 6309.c:4183
void cpu_greater_than_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6309.c:5105
void cpu_store_32bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 32 bit
Definition 6309.c:2540
void cpu_flip(Environment *_environment, char *_source, char *_size, char *_destination)
Definition 6309.c:5562
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
void cpu_beq(Environment *_environment, char *_label)
CPU 6309: emit code to make long conditional jump
Definition 6309.c:308
void cpu_compare_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6309: emit code to compare two 16 bit values
Definition 6309.c:1523
void cpu_peek(Environment *_environment, char *_address, char *_target)
Definition 6309.c:366
void cpu_convert_string_into_16bit(Environment *_environment, char *_string, char *_len, char *_value)
Definition 6309.c:5502
void cpu_not_8bit(Environment *_environment, char *_value, char *_result)
Definition 6309.c:4505
void cpu_math_div_8bit_to_8bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6309.c:1163
void cpu_math_add_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6309.c:3238
void cpu_xor_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6309.c:4382
void cpu_compare_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:876
void cpu_less_than_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6309: emit code to compare two 32 bit values
Definition 6309.c:2949
void cpu_compare_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6309.c:4906
void cpu_less_than_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6309.c:1613
#define IS_REGISTER(x)
Definition 6309.h:58
@ REGISTER_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
@ STACK_NONE
Definition 6309.h:78
@ STACK_BYTE
Definition 6309.h:79
@ STACK_WORD
Definition 6309.h:80
@ STACK_DWORD
Definition 6309.h:81
void cpu_and_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4319
void cpu_float_single_cos(Environment *_environment, char *_angle, char *_result)
Definition 6809.c:7606
void cpu_protothread_get_state(Environment *_environment, char *_index, char *_state)
Definition 6809.c:6571
void cpu_set_callback(Environment *_environment, char *_callback, char *_label)
Definition 6809.c:6604
void cpu_move_32bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6809.c:5730
void cpu_dsfree(Environment *_environment, char *_index)
Definition 6809.c:6249
void cpu_less_than_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6809.c:5366
void cpu_dsresize_size(Environment *_environment, char *_index, int _resize)
Definition 6809.c:6280
void cpu_less_than_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6809.c:969
void cpu_hex_to_string_calc_string(Environment *_environment, char *_size, int _separator, char *_string_size)
Definition 6809.c:6163
void cpu_move_8bit_signed_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7758
void cpu_float_fast_from_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6809.c:7377
void cpu_in(Environment *_environment, char *_port, char *_value)
Definition 6809.c:6691
void cpu_hex_to_string_calc_string_size(Environment *_environment, int _size, int _separator, char *_string_size)
Definition 6809.c:6180
void cpu_pokew(Environment *_environment, char *_address, char *_source)
Definition 6809.c:410
void cpu_move_32bit_signed_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7882
void cpu_combine_nibbles(Environment *_environment, char *_low_nibble, char *_hi_nibble, char *_byte)
Definition 6809.c:3784
char * cpu_blit_register_name(Environment *_environment, int _register)
Definition 6809.c:6751
void cpu_di(Environment *_environment)
Definition 6809.c:4610
#define B(code, label)
Definition 6809.c:47
void cpu_float_fast_tan(Environment *_environment, char *_angle, char *_result)
Definition 6809.c:7621
void cpu_math_double_32bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6809: emit code to double a 32 bit value
Definition 6809.c:3332
void cpu_protothread_restore(Environment *_environment, char *_index, char *_step)
Definition 6809.c:6548
void cpu_msc1_uncompress_indirect_indirect(Environment *_environment, char *_input, char *_output)
Definition 6809.c:6671
void cpu_not_16bit(Environment *_environment, char *_value, char *_result)
Definition 6809.c:4580
void cpu_move_8bit_unsigned_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7768
void cpu_math_mul2_const_16bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6809: emit code to halves for several times a 8 bit value
Definition 6809.c:2464
void cpu_math_div_16bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6809.c:2011
void cpu_move_16bit_signed_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7812
void cpu_move_8bit_unsigned_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7732
void cpu_compare_32bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive)
CPU 6809: emit code to compare two 32 bit values
Definition 6809.c:2915
void cpu_math_mul_16bit_to_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _signed)
CPU 6809: emit code to multiply two 16 bit values in a 32 bit register
Definition 6809.c:1754
void cpu_swap_32bit(Environment *_environment, char *_left, char *_right)
Definition 6809.c:4542
void cpu_float_fast_from_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6809.c:7400
void cpu_bveq(Environment *_environment, char *_value, char *_label)
Definition 6809.c:334
void cpu_dsresize(Environment *_environment, char *_index, char *_resize)
Definition 6809.c:6269
void cpu_move_nbit_indirect(Environment *_environment, int _n, char *_source, char *_value)
Definition 6809.c:6960
void cpu_math_div_8bit_to_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _signed)
Definition 6809.c:1242
void cpu_bit_check_extended(Environment *_environment, char *_value, char *_position, char *_result, int _bitwidth)
Definition 6809.c:5937
void cpu_math_div_32bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6809.c:2558
void cpu_math_mul2_const_8bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6809: emit code to double for several times a 8 bit value
Definition 6809.c:1397
void cpu_float_fast_div(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6809.c:7562
void cpu_move_32bit_signed_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7875
void cpu_move_32bit_unsigned_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7868
void cpu_math_mul2_const_32bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6809: emit code to double for several times a 32 bit value
Definition 6809.c:3607
void cpu_uppercase(Environment *_environment, char *_source, char *_size, char *_result)
Definition 6809.c:5746
void cpu_math_add_16bit_with_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
Definition 6809.c:1708
void cpu_address_table_build(Environment *_environment, char *_table, int *_values, char *_address[], int _count)
Definition 6809.c:7678
void cpu_mem_move(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6809.c:4755
void cpu_set_asmio_indirect(Environment *_environment, int _asmio, char *_value)
Definition 6809.c:3964
void cpu_msc1_uncompress_direct_indirect(Environment *_environment, char *_input, char *_output)
Definition 6809.c:6639
void cpu_math_sub_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6809: emit code to subtract two 8 bit values
Definition 6809.c:1048
void cpu_xor_32bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6809.c:4495
void cpu_math_add_32bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6809: emit code to add two 32 bit values
Definition 6809.c:3263
void cpu_protothread_save(Environment *_environment, char *_index, int _step)
Definition 6809.c:6537
void cpu_store_char(Environment *_environment, char *_destination, int _value)
CPU 6809: emit code to store 8 bit
Definition 6809.c:784
void cpu_math_complement_const_32bit(Environment *_environment, char *_source, int _value)
CPU 6809: emit code to calculate a 32 bit complement of a number
Definition 6809.c:3412
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6809: emit code to store 16 bit
Definition 6809.c:1503
void cpu_poked(Environment *_environment, char *_address, char *_source)
Definition 6809.c:445
void cpu_and_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6809.c:4290
void cpu_dsassign(Environment *_environment, char *_original, char *_copy)
Definition 6809.c:6329
void cpu_math_double_16bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6809: emit code to double a 16 bit value
Definition 6809.c:1728
void cpu_math_sub_32bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6809: emit code to subtract two 32 bit values
Definition 6809.c:3364
void cpu_complement2_8bit(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:6377
void cpu_msc1_uncompress_indirect_direct(Environment *_environment, char *_input, char *_output)
Definition 6809.c:6655
void cpu_math_div2_const_8bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6809: emit code to halves for several times a 8 bit value
Definition 6809.c:1329
void cpu_less_than_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6809.c:5301
void cpu_dsalloc_size(Environment *_environment, int _size, char *_index)
Definition 6809.c:6238
void cpu_get_asmio_indirect(Environment *_environment, int _asmio, char *_value)
Definition 6809.c:4027
void cpu_move_16bit_unsigned_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7805
void cpu_float_fast_cos(Environment *_environment, char *_angle, char *_result)
Definition 6809.c:7602
void cpu_protothread_set_state(Environment *_environment, char *_index, int _state)
Definition 6809.c:6560
void cpu_math_div_nbit_to_nbit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _bits)
Definition 6809.c:2600
void cpu_math_add_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6809: emit code to add two 8 bit values
Definition 6809.c:1016
void cpu_float_single_add(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6809.c:7489
void cpu_float_single_sub(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6809.c:7468
void cpu_bit_inplace_8bit_extended_indirect(Environment *_environment, char *_address, char *_position, char *_bit)
Definition 6809.c:5995
void cpu_move_8bit_unsigned_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7777
void cpu_move_8bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6809.c:5571
void cpu_string_sub(Environment *_environment, char *_source, char *_source_size, char *_pattern, char *_pattern_size, char *_destination, char *_destination_size)
Definition 6809.c:6704
void cpu_compare_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6809: emit code to compare two 8 bit values
Definition 6809.c:810
void cpu_math_and_const_32bit(Environment *_environment, char *_source, int _mask)
CPU 6809: emit code to mask with "and" a value of 32 bit
Definition 6809.c:3758
void cpu_fill_direct_size(Environment *_environment, char *_address, int _bytes, char *_pattern)
CPU 6809: emit code to fill up a memory area
Definition 6809.c:674
void cpu_addressof_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:1485
void cpu_dec_16bit(Environment *_environment, char *_variable)
Definition 6809.c:4703
void cpu_dsgc(Environment *_environment)
Definition 6809.c:6291
void cpu_move_16bit_signed_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7822
void cpu_inc(Environment *_environment, char *_variable)
Definition 6809.c:4618
void cpu_poke_const(Environment *_environment, char *_address, int _source)
Definition 6809.c:388
void cpu_fill_direct(Environment *_environment, char *_address, char *_bytes, char *_pattern)
CPU 6809: emit code to fill up a memory area
Definition 6809.c:642
void cpu_jump_indirect(Environment *_environment, char *_value)
Definition 6809.c:3843
void cpu_math_complement_const_8bit(Environment *_environment, char *_source, int _value)
CPU 6809: emit code to calculate an 8 bit complement of a number
Definition 6809.c:1432
void cpu_dsdefine(Environment *_environment, char *_string, char *_index)
Definition 6809.c:6216
void cpu_math_complement_const_16bit(Environment *_environment, char *_source, int _value)
CPU 6809: emit code to calculate a 16 bit complement of a number
Definition 6809.c:2339
void cpu_move_16bit_unsigned_32bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7841
void cpu_math_mul2_const_nbit(Environment *_environment, char *_source, int _steps, int _bits)
Definition 6809.c:3724
void cpu_float_single_exp(Environment *_environment, char *_value, char *_result)
Definition 6809.c:7663
void cpu_move_32bit(Environment *_environment, char *_source, char *_destination)
CPU 6809: emit code to move 32 bit
Definition 6809.c:2524
void cpu_fill_size(Environment *_environment, char *_address, int _bytes, char *_pattern)
CPU 6809: emit code to fill up a memory area
Definition 6809.c:574
void cpu_dsfill(Environment *_environment, char *_string, char *_value)
Definition 6809.c:7944
void cpu_less_than_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6809: emit code to compare two 8 bit values
Definition 6809.c:949
void cpu_fill_direct_size_value(Environment *_environment, char *_address, int _bytes, int _pattern)
CPU 6809: emit code to fill up a memory area
Definition 6809.c:711
void cpu_dec_32bit(Environment *_environment, char *_variable)
Definition 6809.c:4715
void cpu_greater_than_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6809.c:1642
void cpu_protothread_get_address(Environment *_environment, char *_index, char *_address)
Definition 6809.c:6592
void cpu_math_add_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6809: emit code to add two 16 bit values
Definition 6809.c:1661
void cpu_greater_than_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6809: emit code to compare two 8 bit values
Definition 6809.c:1632
void cpu_bit_inplace_8bit(Environment *_environment, char *_value, int _position, int *_bit)
Definition 6809.c:5965
void cpu_math_add_16bit_const(Environment *_environment, char *_source, int _destination, char *_other)
CPU 6502: emit code to add two 16 bit values
Definition 6809.c:1674
void cpu_protothread_vars(Environment *_environment)
Definition 6809.c:6477
void cpu_poked_const(Environment *_environment, char *_address, int _source)
Definition 6809.c:458
void cpu_math_add_16bit_with_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6809: emit code to add two 16 bit values
Definition 6809.c:1696
void cpu_compare_and_branch_16bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6809: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6809.c:1578
void cpu_move_32bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6809.c:5714
void cpu_dswrite(Environment *_environment, char *_index)
Definition 6809.c:6259
void cpu_complement2_nbit(Environment *_environment, char *_source, char *_destination, int _bits)
Definition 6809.c:6427
void cpu_greater_than_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6809: emit code to compare two 8 bit values
Definition 6809.c:988
void cpu_or_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4383
void cpu_fill(Environment *_environment, char *_address, char *_bytes, int _bytes_width, char *_pattern)
CPU 6809: emit code to fill up a memory area
Definition 6809.c:534
void cpu_move_16bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6809.c:5671
void cpu_limit_16bit(Environment *_environment, char *_variable, int _value)
Definition 6809.c:4224
void cpu_move_8bit_indirect_with_offset2(Environment *_environment, char *_source, char *_value, char *_offset)
Definition 6809.c:5594
void cpu_less_than_32bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6809.c:3029
void cpu_move_nbit_indirect2(Environment *_environment, int _n, char *_value, char *_source)
Definition 6809.c:7015
void cpu_and_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4276
void cpu_float_single_log(Environment *_environment, char *_value, char *_result)
Definition 6809.c:7644
void cpu_math_mul_8bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _signed)
CPU 6809: emit code to multiply two 8bit values in a 16 bit register
Definition 6809.c:1087
void cpu_compare_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive)
CPU 6809: emit code to compare two 16 bit values
Definition 6809.c:1542
void cpu_math_sub_16bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6809: emit code to subtract two 16 bit values
Definition 6809.c:2307
void cpu_compare_and_branch_32bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6809: emit code to compare two 32 bit values and jump if they are equal/different
Definition 6809.c:2958
void cpu_store_nbit(Environment *_environment, char *_destination, int _n, int _value[])
CPU 6809: emit code to store n bit
Definition 6809.c:6833
void cpu_mem_move_direct_indirect_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6809.c:5065
void cpu_dec_nbit(Environment *_environment, char *_variable, int _bits)
Definition 6809.c:4735
void cpu_math_and_const_16bit(Environment *_environment, char *_source, int _mask)
CPU 6809: emit code to mask with "and" a value of 16 bit
Definition 6809.c:2500
void cpu_move_8bit_indirect2_8bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6809.c:5639
void cpu_float_single_from_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6809.c:7404
void cpu_fill_indirect(Environment *_environment, char *_address, char *_size, char *_pattern, int _size_size)
Definition 6809.c:5849
void cpu_mem_move_indirect_direct_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6809.c:5123
void cpu_compare_and_branch_char_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6809: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6809.c:924
void cpu_less_than_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _bits)
Definition 6809.c:3109
void cpu_float_fast_sin(Environment *_environment, char *_angle, char *_result)
Definition 6809.c:7583
void cpu_math_mul_nbit_to_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6809.c:1888
void cpu_label(Environment *_environment, char *_label)
Definition 6809.c:356
void cpu_dec(Environment *_environment, char *_variable)
Definition 6809.c:4693
void cpu_and_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4304
void cpu_float_fast_log(Environment *_environment, char *_value, char *_result)
Definition 6809.c:7640
void cpu_move_nbit(Environment *_environment, int _n, char *_source, char *_destination)
CPU cpu6809: emit code to store n bit
Definition 6809.c:6897
void cpu_address_table_call(Environment *_environment, char *_table, char *_value, char *_address)
Definition 6809.c:7708
void cpu_logical_not_8bit(Environment *_environment, char *_value, char *_result)
Definition 6809.c:4556
void cpu_pokew_const(Environment *_environment, char *_address, int _source)
Definition 6809.c:421
void cpu_logical_and_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4258
void cpu_or_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6809.c:4369
void cpu_math_div2_const_32bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6809: emit code to halves for several times a 32 bit value
Definition 6809.c:3436
void cpu_halt(Environment *_environment)
Definition 6809.c:4110
void cpu_end(Environment *_environment)
Definition 6809.c:4124
void cpu_float_fast_from_double_to_int_array(Environment *_environment, double _value, int _result[])
Definition 6809.c:7077
void cpu_compare_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6809.c:5181
void cpu_greater_than_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6809.c:998
void cpu_complement2_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:6389
void cpu_dsinit(Environment *_environment)
Definition 6809.c:6300
void cpu_xor_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4417
void cpu_protothread_unregister(Environment *_environment, char *_index)
Definition 6809.c:6527
void cpu_decrypt(Environment *_environment, char *_data, char *_data_size, char *_key, char *_key_size, char *_output, char *_result)
Definition 6809.c:7916
void cpu_complement2_32bit(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:6403
void cpu_protothread_register_at(Environment *_environment, char *_index, char *_label)
Definition 6809.c:6504
void cpu_blit_free_register(Environment *_environment, int _register)
Definition 6809.c:6794
void cpu_lowercase(Environment *_environment, char *_source, char *_size, char *_result)
Definition 6809.c:5783
void cpu_float_single_to_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6809.c:7426
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6809: emit code to move 16 bit
Definition 6809.c:1474
void cpu_move_8bit_with_offset2(Environment *_environment, char *_source, char *_value, char *_offset)
Definition 6809.c:5610
void cpu_out(Environment *_environment, char *_port, char *_value)
Definition 6809.c:6687
void cpu_move_16bit_unsigned_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7799
void cpu_blit_finalize(Environment *_environment)
Definition 6809.c:6744
void cpu_encrypt(Environment *_environment, char *_data, char *_data_size, char *_key, char *_key_size, char *_output)
Definition 6809.c:7903
void cpu_bneq(Environment *_environment, char *_label)
CPU 6809: emit code to make long conditional jump
Definition 6809.c:324
void cpu_compare_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive, int _bits)
CPU 6502: emit code to compare two 32 bit values
Definition 6809.c:2880
void cpu_move_16bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6809.c:5684
void cpu_float_fast_cmp(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6809.c:7506
void cpu_math_double_8bit(Environment *_environment, char *_source, char *_other, int _signed)
CPU 6809: emit code to double a 8 bit value
Definition 6809.c:1067
void cpu_float_fast_mul(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6809.c:7541
void cpu_bits_to_string(Environment *_environment, char *_number, char *_string, char *_string_size, int _bits, char *_zero, char *_one)
Definition 6809.c:6109
void cpu_dsalloc(Environment *_environment, char *_size, char *_index)
Definition 6809.c:6227
void cpu_less_than_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _bits)
Definition 6809.c:3065
void cpu_not_32bit(Environment *_environment, char *_value, char *_result)
Definition 6809.c:4593
void cpu_float_single_from_double_to_int_array(Environment *_environment, double _value, int _result[])
Definition 6809.c:7081
void cpu_float_single_to_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6809.c:7447
void cpu_greater_than_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6809.c:5502
void cpu_hex_to_string(Environment *_environment, char *_number, char *_string, char *_size, int _separator)
Definition 6809.c:6197
void cpu_or_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4355
void cpu_move_8bit_indirect2_16bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6809.c:5655
void cpu_math_add_32bit_const(Environment *_environment, char *_source, int _destination, char *_other)
Definition 6809.c:3305
void cpu_move_8bit_indirect_with_offset(Environment *_environment, char *_source, char *_value, int _offset)
Definition 6809.c:5582
void cpu_sqroot(Environment *_environment, char *_number, char *_result)
Definition 6809.c:6447
void cpu_number_to_string(Environment *_environment, char *_number, char *_string, char *_string_size, int _bits, int _signed)
Definition 6809.c:6020
void cpu_greater_than_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6809: emit code to compare two 8 bit values
Definition 6809.c:3161
void cpu_peekd(Environment *_environment, char *_address, char *_target)
Definition 6809.c:432
void cpu_in_direct(Environment *_environment, char *_port, char *_value)
Definition 6809.c:6699
void cpu_call_indirect(Environment *_environment, char *_value)
Definition 6809.c:3825
void cpu_call(Environment *_environment, char *_label)
Definition 6809.c:3815
void cpu_random_8bit(Environment *_environment, char *_entropy, char *_result)
Definition 6809.c:4189
void cpu_xor_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6809.c:4431
void cpu_move_16bit_signed_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7793
void cpu_mem_move_direct(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6809.c:4828
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6809: emit code to store 8 bit
Definition 6809.c:760
void cpu_swap_8bit(Environment *_environment, char *_left, char *_right)
Definition 6809.c:4514
void cpu_float_fast_to_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6809.c:7422
void cpu_mem_move_direct2(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6809.c:4916
void cpu_init(Environment *_environment)
Definition 6809.c:62
void cpu_dstring_vars(Environment *_environment)
Definition 6809.c:6462
void cpu_protothread_loop(Environment *_environment)
Definition 6809.c:6496
void cpu_float_single_div(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6809.c:7566
void cpu_hex_to_bin(Environment *_environment, char *_value_address, char *_value_size, char *_variable_address, char *_variable_size, char *_result)
Definition 6809.c:7931
void cpu_out_direct(Environment *_environment, char *_port, char *_value)
Definition 6809.c:6695
void cpu_greater_than_32bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6809.c:3197
void cpu_protothread_current(Environment *_environment, char *_current)
Definition 6809.c:6583
void cpu_float_fast_to_16(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6809.c:7443
void cpu_mem_move_16bit(Environment *_environment, char *_source, char *_destination, char *_size)
Definition 6809.c:4810
void cpu_compare_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6809: emit code to compare two 32 bit values
Definition 6809.c:2813
void cpu_set_asmio(Environment *_environment, int _asmio, int _value)
Definition 6809.c:3898
void cpu_jump(Environment *_environment, char *_label)
Definition 6809.c:3799
void cpu_store_8bit_with_offset2(Environment *_environment, char *_source, char *_offset, int _value)
Definition 6809.c:6361
void cpu_move_16bit_unsigned_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7833
int cpu_blit_alloc_register(Environment *_environment)
Definition 6809.c:6760
void cpu_move_32bit_signed_8bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7856
void cpu_mem_move_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6809.c:4949
void cpu_fill_blocks(Environment *_environment, char *_address, char *_blocks, char *_pattern)
CPU 6809: emit code to fill up a memory area
Definition 6809.c:484
void cpu_bvneq(Environment *_environment, char *_value, char *_label)
Definition 6809.c:345
void cpu_float_single_mul(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6809.c:7545
void cpu_float_fast_exp(Environment *_environment, char *_value, char *_result)
Definition 6809.c:7659
void cpu_move_16bit_signed_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7787
void cpu_compare_and_branch_16bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6809.c:1552
void cpu_fill_size_value(Environment *_environment, char *_address, int _bytes, int _pattern)
CPU 6809: emit code to fill up a memory area
Definition 6809.c:610
void cpu_call_addr(Environment *_environment, int _address)
Definition 6809.c:3809
void cpu_math_div_16bit_to_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _signed)
Definition 6809.c:2155
void cpu_poke(Environment *_environment, char *_address, char *_source)
Definition 6809.c:377
void cpu_bit_check(Environment *_environment, char *_value, int _position, char *_result, int _bitwidth)
Definition 6809.c:5909
void cpu_protothread_register(Environment *_environment, char *_label, char *_index)
Definition 6809.c:6515
void cpu_move_32bit_signed_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7850
void cpu_float_single_to_string(Environment *_environment, char *_x, char *_string, char *_string_size)
Definition 6809.c:7357
void cpu_math_div_nbit_to_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _bits)
Definition 6809.c:2730
void cpu_float_single_tan(Environment *_environment, char *_angle, char *_result)
Definition 6809.c:7625
void cpu_nop(Environment *_environment)
Definition 6809.c:256
void cpu_random_32bit(Environment *_environment, char *_entropy, char *_result)
Definition 6809.c:4211
void cpu_move_32bit_unsigned_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7896
void cpu_less_than_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6809.c:959
void cpu_greater_than_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _bits)
Definition 6809.c:3233
void cpu_prepare_for_compare_and_branch_8bit(Environment *_environment, char *_source)
Definition 6809.c:840
void cpu_less_than_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6809: emit code to compare two 8 bit values
Definition 6809.c:1603
void cpu_mem_move_direct2_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6809.c:4883
void cpu_math_and_const_8bit(Environment *_environment, char *_source, int _mask)
CPU 6809: emit code to mask with "and" a value of 8 bit
Definition 6809.c:1451
void cpu_move_32bit_unsigned_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7889
void cpu_msc1_uncompress_direct_direct(Environment *_environment, char *_input, char *_output)
Definition 6809.c:6613
void cpu_inc_32bit(Environment *_environment, char *_variable)
Definition 6809.c:4649
void cpu_move_8bit_signed_16bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7716
void cpu_mem_move_direct_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6809.c:5007
void cpu_float_fast_sub(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6809.c:7464
void cpu_xor_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4476
void cpu_return(Environment *_environment)
Definition 6809.c:4090
void cpu_move_8bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6809.c:5626
void cpu_inc_nbit(Environment *_environment, char *_variable, int _bits)
Definition 6809.c:4676
void cpu_pop(Environment *_environment)
Definition 6809.c:4100
void cpu_math_sub_16bit_with_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
Definition 6809.c:2319
void cpu_random_16bit(Environment *_environment, char *_entropy, char *_result)
Definition 6809.c:4200
void cpu_ei(Environment *_environment)
Definition 6809.c:4614
int cpu_register_decode(Environment *_environment, char *_register)
Definition 6809.c:3853
void cpu_or_32bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4398
void cpu_math_div2_const_16bit(Environment *_environment, char *_source, int _steps, int _signed, char *_remainder)
CPU 6809: emit code to halves for several times a 16 bit value
Definition 6809.c:2358
void cpu_convert_string_into_8bit(Environment *_environment, char *_string, char *_len, char *_value)
Definition 6809.c:5819
void cpu_inc_16bit(Environment *_environment, char *_variable)
Definition 6809.c:4628
void cpu_logical_or_8bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4338
void cpu_compare_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive, int _bits)
Definition 6809.c:2848
void cpu_address_table_lookup(Environment *_environment, char *_table, int _count)
Definition 6809.c:7687
void cpu_ztoa(Environment *_environment)
Definition 6809.c:262
void cpu_random(Environment *_environment, char *_entropy)
Definition 6809.c:4135
void cpu_move_32bit_unsigned_8bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7862
void cpu_compare_and_branch_8bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6809.c:850
void cpu_execute_compare_and_branch_8bit_const(Environment *_environment, int _destination, char *_label, int _positive)
CPU 6809: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6809.c:900
void cpu_ctoa(Environment *_environment)
Definition 6809.c:279
void cpu_move_16bit_indirect2_8bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6809.c:5697
void cpu_float_single_from_8(Environment *_environment, char *_value, char *_result, int _signed)
Definition 6809.c:7381
void cpu_math_sub_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6809.c:3385
void cpu_float_single_cmp(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6809.c:7510
void cpu_move_8bit_signed_32bit_signed(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7748
void cpu_math_div2_const_nbit(Environment *_environment, char *_source, int _steps, int _bits, char *_remainder)
Definition 6809.c:3563
void cpu_store_8bit_with_offset(Environment *_environment, char *_destination, int _value, int _offset)
Definition 6809.c:6353
void cpu_busy_wait(Environment *_environment, char *_timing)
Definition 6809.c:4243
void cpu_greater_than_memory(Environment *_environment, char *_source, char *_destination, char *_size, char *_result, int _equal)
Definition 6809.c:5437
void cpu_store_32bit(Environment *_environment, char *_destination, int _value)
CPU 6809: emit code to store 32 bit
Definition 6809.c:2544
void cpu_peekw(Environment *_environment, char *_address, char *_target)
Definition 6809.c:399
void cpu_flip(Environment *_environment, char *_source, char *_size, char *_destination)
Definition 6809.c:5894
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6809: emit code to move 8 bit
Definition 6809.c:742
void cpu_beq(Environment *_environment, char *_label)
CPU 6809: emit code to make long conditional jump
Definition 6809.c:308
void cpu_compare_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6809: emit code to compare two 16 bit values
Definition 6809.c:1523
void cpu_peek(Environment *_environment, char *_address, char *_target)
Definition 6809.c:366
void cpu_float_fast_add(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6809.c:7485
void cpu_convert_string_into_16bit(Environment *_environment, char *_string, char *_len, char *_value)
Definition 6809.c:5834
void cpu_float_single_sin(Environment *_environment, char *_angle, char *_result)
Definition 6809.c:7587
void cpu_not_8bit(Environment *_environment, char *_value, char *_result)
Definition 6809.c:4568
void cpu_math_div_8bit_to_8bit(Environment *_environment, char *_source, char *_destination, char *_other, char *_other_remainder, int _signed)
Definition 6809.c:1162
void cpu_dsdescriptor(Environment *_environment, char *_index, char *_address, char *_size)
Definition 6809.c:6309
void cpu_math_add_nbit(Environment *_environment, char *_source, char *_destination, char *_other, int _bits)
Definition 6809.c:3286
void cpu_compare_8bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _positive)
CPU 6809: emit code to compare two 8 bit values
Definition 6809.c:830
void cpu_xor_16bit(Environment *_environment, char *_left, char *_right, char *_result)
Definition 6809.c:4445
void cpu_xor_16bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6809.c:4460
void cpu_swap_16bit(Environment *_environment, char *_left, char *_right)
Definition 6809.c:4528
void cpu_compare_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6809: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6809.c:875
void cpu_math_div_32bit_to_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, char *_other_remainder, int _signed)
Definition 6809.c:2763
void cpu_greater_than_nbit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _bits)
Definition 6809.c:3244
void cpu_float_fast_to_string(Environment *_environment, char *_x, char *_string, char *_string_size)
Definition 6809.c:7353
void cpu_less_than_32bit(Environment *_environment, char *_source, char *_destination, char *_other, int _equal, int _signed)
CPU 6809: emit code to compare two 32 bit values
Definition 6809.c:2993
void cpu_dsfill_value(Environment *_environment, char *_string, int _value)
Definition 6809.c:7955
void cpu_dsassign_string(Environment *_environment, char *_string, char *_copy)
Definition 6809.c:6341
void cpu_move_8bit_signed_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7724
void cpu_move_8bit_unsigned_16bit_unsigned(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:7740
void cpu_compare_memory_size(Environment *_environment, char *_source, char *_destination, int _size, char *_result, int _equal)
Definition 6809.c:5238
void cpu_math_add_8bit_const(Environment *_environment, char *_source, int _destination, char *_other)
CPU 6502: emit code to add two 8 bit values
Definition 6809.c:1028
void cpu_flip_8bit(Environment *_environment, char *_source, char *_destination)
Definition 6809.c:5876
void cpu_blit_initialize(Environment *_environment)
Definition 6809.c:6737
void cpu_less_than_16bit_const(Environment *_environment, char *_source, int _destination, char *_other, int _equal, int _signed)
Definition 6809.c:1613
enum _CPU6809Register CPU6809Register
enum _CPU6809Stack CPU6809Stack
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