-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser.y
17485 lines (15881 loc) · 550 KB
/
parser.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%{
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <ctype.h>
#include <cctype>
#include <vector>
#include <stack>
#include <sstream>
#include <cmath>
#include "lex.yy.c"
using namespace std;
string str_ADC;
string str_AND;
string str_ASL;
string str_ALR; // undocumented
string str_BCC;
string str_BCS;
string str_BEQ;
string str_BIT;
string str_BMI;
string str_BNE;
string str_BPL;
string str_BRK;
string str_BVC;
string str_BVS;
string str_CLC;
string str_CLD;
string str_CLI;
string str_CLV;
string str_CMP;
string str_CPX;
string str_CPY;
string str_DCP;
string str_DEC;
string str_DEX;
string str_DEY;
string str_EOR;
string str_INC;
string str_INX;
string str_INY;
string str_JMP;
string str_JSR;
string str_LAX;
string str_LDA;
string str_LDX;
string str_LDY;
string str_LSR;
string str_NOP;
string str_ORA;
string str_PHA;
string str_PHP;
string str_PLA;
string str_PLP;
string str_ROL;
string str_ROR;
string str_RTI;
string str_RTS;
string str_SBC;
string str_SEC;
string str_SED;
string str_SEI;
string str_STA;
string str_STX;
string str_STY;
string str_TAX;
string str_TAY;
string str_TSX;
string str_TXA;
string str_TXS;
string str_TYA;
string str_XAA;
string str_BYTE;
string commentmarker;
void setKickDialect()
{
str_ADC = string( "adc " );
str_AND = string( "and " );
str_ASL = string( "asl " );
str_ALR = string( "alr " );
str_BCC = string( "bcc " );
str_BCS = string( "bcs " );
str_BEQ = string( "beq " );
str_BIT = string( "bit " );
str_BMI = string( "bmi " );
str_BNE = string( "bne " );
str_BPL = string( "bpl " );
str_BRK = string( "brk " );
str_BVC = string( "bvc " );
str_BVS = string( "bvs " );
str_CLC = string( "clc " );
str_CLD = string( "cld " );
str_CLI = string( "cli " );
str_CLV = string( "clv " );
str_CMP = string( "cmp " );
str_CPX = string( "cpx " );
str_CPY = string( "cpy " );
str_DCP = string( "dcp " );
str_DEC = string( "dec " );
str_DEX = string( "dex " );
str_DEY = string( "dey " );
str_EOR = string( "eor " );
str_INC = string( "inc " );
str_INX = string( "inx " );
str_INY = string( "iny " );
str_JMP = string( "jmp " );
str_JSR = string( "jsr " );
str_LAX = string( "lax " );
str_LDA = string( "lda " );
str_LDX = string( "ldx " );
str_LDY = string( "ldy " );
str_LSR = string( "lsr " );
str_NOP = string( "nop " );
str_ORA = string( "ora " );
str_PHA = string( "pha " );
str_PHP = string( "php " );
str_PLA = string( "pla " );
str_PLP = string( "plp " );
str_ROL = string( "rol " );
str_ROR = string( "ror " );
str_RTI = string( "rti " );
str_RTS = string( "rts " );
str_SBC = string( "sbc " );
str_SEC = string( "sec " );
str_SED = string( "sed " );
str_SEI = string( "sei " );
str_STA = string( "sta " );
str_STX = string( "stx " );
str_STY = string( "sty " );
str_TAX = string( "tax " );
str_TAY = string( "tay " );
str_TSX = string( "tsx " );
str_TXA = string( "txa " );
str_TXS = string( "txs " );
str_TYA = string( "tya " );
str_XAA = string( "xaa " );
str_BYTE = string( ".byte " );
commentmarker = " // ";
return;
}
void setWebDialect()
{
str_ADC = string( "ADC " );
str_AND = string( "AND " );
str_ALR = string( "ALR " );
str_ASL = string( "ASL " );
str_BCC = string( "BCC " );
str_BCS = string( "BCS " );
str_BEQ = string( "BEQ " );
str_BIT = string( "BIT " );
str_BMI = string( "BMI " );
str_BNE = string( "BNE " );
str_BPL = string( "BPL " );
str_BRK = string( "BRK" );
str_BVC = string( "BVC " );
str_BVS = string( "BVS " );
str_CLC = string( "CLC" );
str_CLD = string( "CLD " );
str_CLI = string( "CLI" );
str_CLV = string( "CLV " );
str_CMP = string( "CMP " );
str_CPX = string( "CPX " );
str_CPY = string( "CPY " );
str_DCP = string( "DCP " );
str_DEC = string( "DEC " );
str_DEX = string( "DEX" );
str_DEY = string( "DEY" );
str_EOR = string( "EOR " );
str_INC = string( "INC " );
str_INX = string( "INX" );
str_INY = string( "INY" );
str_JMP = string( "JMP " );
str_JSR = string( "JSR " );
str_LAX = string( "LAX " );
str_LDA = string( "LDA " );
str_LDX = string( "LDX " );
str_LDY = string( "LDY " );
str_LSR = string( "LSR " );
str_NOP = string( "NOP" );
str_ORA = string( "ORA " );
str_PHA = string( "PHA" );
str_PHP = string( "PHP" );
str_PLA = string( "PLA" );
str_PLP = string( "PLP" );
str_ROL = string( "ROL " );
str_ROR = string( "ROR " );
str_RTI = string( "RTI " );
str_RTS = string( "RTS" );
str_SBC = string( "SBC " );
str_SEC = string( "SEC " );
str_SED = string( "SED " );
str_SEI = string( "SEI" );
str_STA = string( "STA " );
str_STX = string( "STX " );
str_STY = string( "STY " );
str_TAX = string( "TAX" );
str_TAY = string( "TAY" );
str_TSX = string( "TSX" );
str_TXA = string( "TXA" );
str_TXS = string( "TXS" );
str_TYA = string( "TYA " );
str_XAA = string( "XAA " ); // OPDCODE: $8B IMM : 2 cycles
str_BYTE = string( ".BYTE " );
commentmarker = " ; ";
return;
}
/* The extra parameter is also given to yyerror */
void yyerror(FILE* fp, const char* msg);
/* forward declarations */
void addAsm( string s, int instruction_size, bool l);
void addDebugComment( string s );
string getNameOf( int a );
void addComment( string s );
string stripFirst( string s );
bool isWordID( string s );
// compiler internal flags
bool kick=false;
int function_argument_count = 0;
// parameter booleans
bool p0=false;
bool p1=false;
bool p2=false;
bool p3=false;
bool load_is_needed=false;
bool load16_is_needed=false;
bool save_is_needed=false;
bool sid_was_imported=false;
bool basic_upstart=false;
bool function_labels_are_still_needed=true;
bool stack_is_needed=false;
bool illegal_operations_are_needed=false;
bool sidirq_is_needed=false;
bool bnkmem_is_needed=false;
bool scrmem_is_needed=false;
bool chrmem_is_needed=false;
bool bmpmem_is_needed=false;
bool bin2bit_is_needed=false;
bool word2dec_is_needed=false;
bool plot_is_needed=false;
bool multicolour_plot_is_needed=false;
bool getplot_is_needed=false;
bool unsigned_signed_cmp_is_needed=false;
bool split_byte_is_needed=false;
bool decimal_digit_is_needed=false;
bool modulus_is_needed=false;
bool div10_is_needed=false;
bool return_addresses_needed=true;
bool umul_is_needed=false;
bool mul16_is_needed=false;
bool div16_is_needed=false;
bool cls_is_needed=false;
bool memcpy_is_needed=false;
bool mobcpy_is_needed=false;
bool signed_comparison_is_needed=false;
bool twos_complement_is_needed = false;
bool byte2hex_is_needed = false;
bool byt2str_is_needed = false;
bool printf_is_needed = false;
bool scanf_is_needed = false;
bool getkey_is_needed = false;
bool symbol_table_is_needed = false;
bool sidrnd_is_needed = false;
bool sidrnd_is_initialised = false;
bool long_branches = true;
bool arg_debug_comments = false;
bool debug_flag_is_on = false;
int label=0;
int label_major=0;
// command line arguments
bool arg_memory_locations=false;
bool arg_unsafe_ifs=false;
bool arg_show_labels=true;
bool arg_asm_comments=true;
bool arg_show_cycles=false;
bool arg_optimize=true;
bool arg_parser_comments=false;
int scanf_buffer_size=16;
string current_state;
int data_start=828; // 98 2 byte variables
int code_start=2049;
int current_code_location=0;
int byte_count=0;
int string_number=0;
int data_number=0;
int kbd_bfr_addr = 0xCFE0;
int current_variable_type=-1;
int current_variable_base_address=-1;
int jump_start = 0;
int jump_end = 0;
int nl = 0; // node_level node level
// helper functions
int music_init_addr = 0;
int music_play_addr = 0;
stack <string> scope_stack;
stack <string> var_scope_stack;
stack <int> label_stack;
vector <int> label_vector;
vector <int> mob_vector;
vector <string> mobs;
vector <string> include_file_vector;
stack <string> rnd_str_vector;
//stack <string> iterator_stack;
vector <string> node_vector;
// taken from: https://stackoverflow.com/questions/440133/how-do-i-create-a-random-alpha-numeric-string-in-c
bool cmpstr( string a, string b )
{
bool return_value = false;
if( memcmp( a.data(), b.data(), b.length() ) == 0 )
{
return_value = true;
}
return return_value;
}
string gen_random_str(const int len) {
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
std::string tmp_s;
tmp_s.reserve(len);
for (int i = 0; i < len; ++i) {
tmp_s += alphanum[rand() % (sizeof(alphanum) - 1)];
}
return tmp_s;
}
void addNode( string s )
{
string n = string("");
for( int l = 0; l < nl; l++ )
{
n = n + string(" ");
}
n=n +s;
node_vector.push_back(n);
return;
}
int getDataTypeValue( string s )
{
if( s == string("UINT")) return 0;
if( s == string("BYTE")) return 0;
if( s == string("INT")) return 1;
if( s == string("WORD")) return 2;
if( s == string("DOUBLE")) return 4;
if( s == string("FLOAT")) return 8;
if( s == string("MOB")) return 16;
if( s == string("VOID")) return 32;
return -1;
}
string stripFirst( string s )
{
return s.substr( 1, s.length()-1);
}
int hexToDecimal( string s )
{
if( s[0] == '$' ) s[0] = ' ';
if( s[0] == '#' ) s[0] = ' ';
if( s[1] == '$' ) s[1] = ' ';
int return_value = 0;
std::stringstream ss;
ss << std::hex << s;
ss >> return_value;
return return_value;
}
bool isMob( string s )
{
bool return_value = false;
if( s[0] == 'm' ) return_value = true;
//if( return_value ) cerr << "isMob" << endl;
return return_value;
}
bool isFloatIMM( string s )
{
bool return_value = false;
if( s[0] == 'f' ) return_value = true;
return return_value;
}
bool isUintIMM( string s )
{
bool return_value = false;
if( s[0] == 'u' ) return_value = true;
return return_value;
}
bool isWordIMM( string s )
{
bool return_value = false;
if( s[0] == 'w' ) return_value = true;
return return_value;
}
bool isAddress( string s )
{
bool return_value = false;
if( s[0] == '$' ) return_value = true;
return return_value;
}
bool isDoubleIMM( string s )
{
bool return_value = false;
if( s[0] == 'd' ) return_value = true;
return return_value;
}
bool isByte( string s )
{
bool return_value = false;
if( s[0] == '#' && s[1] == '$' ) return_value = true;
return return_value;
}
bool isIntIMM( string s )
{
bool return_value = false;
//if( s[0] != '#' && s[0] != '$' ) return_value = true;
if( s[0] == 'i' ) return_value = true;
return return_value;
}
bool isWordDT(string s)
{
bool return_value = false;
if(s == string("WORD")) return_value = true;
return return_value;
}
bool isUintDT(string s)
{
bool return_value = false;
if(s==string("UINT") || s==string("BYTE")) return_value = true;
return return_value;
}
bool isIntDT(string s)
{
bool return_value = false;
if(s == string("INT")) return_value = true;
return return_value;
}
bool isFloatDT(string s)
{
bool return_value = false;
if(s == string("FLOAT")) return_value = true;
return return_value;
}
bool isDoubleDT(string s)
{
bool return_value = false;
if(s == string("DOUBLE")) return_value = true;
return return_value;
}
bool isVoidDT(string s)
{
bool return_value = false;
if(s == string("VOID")) return_value = true;
return return_value;
}
void addCompilerMessage(string msg, int level = 0)
{
/* level 0 - info */
/* level 1 - warning */
/* level 2 - error */
/* level 3 - critical */
switch( level )
{
case 0:
cerr << "*** message *** line: " << countn+1 << " *** " << msg << " ***" << endl;
break;
case 1:
cerr << "*** warning *** line: " << countn+1 << " *** " << msg << " ***" << endl;
break;
case 2:
cerr << "*** ERROR *** line: " << countn+1 << " *** " << msg << " ***" << endl;
break;
case 3:
cerr << "*** C R I T I C A L E R R O R *** line: " << countn+1 << " *** " << msg << " ***" << endl;
exit(-1);
break;
}
return;
}
void addOptimizationMessage(string msg, int linen, int level = 0)
{
/* level 0 - info */
/* level 1 - warning */
/* level 2 - error */
/* level 3 - critical */
switch( level )
{
case 0:
cerr << "*** message *** asm instruction number: " << linen << " *** " << msg << " ***" << endl;
break;
case 1:
cerr << "*** warning *** asm instruction number: " << linen << " *** " << msg << " ***" << endl;
break;
case 2:
cerr << "*** ERROR *** asm instruction number: " << linen << " *** " << msg << " ***" << endl;
break;
case 3:
cerr << "*** C R I T I C A L E R R O R *** asm instruction number: " << linen << " *** " << msg << " ***" << endl;
exit(-1);
break;
}
return;
}
int get_word_H(int x )
{
int return_value = 0;
if( x > 65535 )
{
addCompilerMessage( "value too large for type", 2 );
return (-1);
}
return_value = ( x & 0xFF00 )/0x100;
return return_value;
}
int get_word_L(int x )
{
int return_value = 0;
if( x > 65535 )
{
addCompilerMessage( "value too large for type", 2 );
return (-1);
}
return_value = ( x & 0x00FF );
return return_value;
}
/* void dumpA() */
/* { */
/* if( debug_flag_is_on ) */
/* { */
/* byte2hex_is_needed = true; */
/* /\* DEBUG *\/ */
/* addAsm( "PHA" + commentmarker + "DEBUG", 1, false); */
/* addAsm( "PHA" + commentmarker + "DEBUG", 1, false); */
/* addAsm( str_JSR + "BYTE2HEX" + commentmarker + "DEBUG", 3, false ); */
/* addAsm( "PLA" + commentmarker + "DEBUG", 1, false); */
/* /\* DEBUG *\/ */
/* } */
/* return; */
/* } */
int twos_complement( int x )
{
// for an 8 bit byte
return ( abs( x ) ^ 255 ) + 1;
}
// converts an integer into a string
string itos( int i )
{
char buffer[10];
sprintf( buffer, "%d", i );
return string( buffer );
}
string toString( int i )
{
return std::to_string(i);
}
string generateNewLabel(bool colon=true)
{
string return_value = ( string( "LBL" ) + itos( label_major ) + "L" + itos(label_vector[label_major]));
if( colon )
{
return_value += string( ":" );
label_vector[label_major] = label_vector[label_major]+1;
}
return return_value;
}
string getSpecificLabel( int MAJOR, int MINOR, bool colon=true )
{
string return_value = string( "LBL" ) + itos( MAJOR ) + "L" + itos( MINOR );
if( colon ) return_value += string( ":" );
return return_value;
}
string getLabel( char* s, bool colon=true )
{
string return_value = string( "LBL" ) + itos( label_major ) + "L" + string( s );
if( colon ) return_value += string( ":" );
return return_value;
}
string getLabel( int i, bool colon=true )
{
string return_value = string( "LBL" ) + itos( label_major ) + "L" + itos( i );
if( colon ) return_value += string( ":" );
return return_value;
}
string binaryToHex( string s )
{
string return_value;
string b;
for( int i = 0; i < s.length(); i+=4 )
{
b = s.substr( i, 4 );
if( b == "0000" ) return_value+="0";
if( b == "0001" ) return_value+="1";
if( b == "0010" ) return_value+="2";
if( b == "0011" ) return_value+="3";
if( b == "0100" ) return_value+="4";
if( b == "0101" ) return_value+="5";
if( b == "0110" ) return_value+="6";
if( b == "0111" ) return_value+="7";
if( b == "1000" ) return_value+="8";
if( b == "1001" ) return_value+="9";
if( b == "1010" ) return_value+="A";
if( b == "1011" ) return_value+="B";
if( b == "1100" ) return_value+="C";
if( b == "1101" ) return_value+="D";
if( b == "1110" ) return_value+="E";
if( b == "1111" ) return_value+="F";
}
return return_value;
}
string fractionalToBinary( double value )
{
string binary_value;
int count=0;
while( count < 31 )
{
value*=2;
if( value >= 1 )
{
binary_value = binary_value + string("1");
value = value - 1;
}
else
{
binary_value = binary_value + string("0");
}
count++;
}
return binary_value;
}
string integerToBinary( int value, int s = 8)
{
value = abs(value);
string binary_value;
while( value > 0 )
{
if( (value % 2) == 1 )
{
binary_value = string("1")+ binary_value;
}
else
{
binary_value = string("0")+ binary_value;
}
value /= 2;
}
while( binary_value.length() < s )
{
binary_value = string("0")+ binary_value;
}
return binary_value;
}
string toBinaryFloat( double value )
{
if( value == 0 ) return string( "0000000000" );
string sign;
string exponent;
string return_value;
if( value < 0 )
{
sign="1";
}
else
{
sign="0";
}
value = abs(value);
double integral_part = floor(value);
double fractional_part = value - integral_part;
int l2 = 1+floor(log2( value )); // 1023 is the bias for 64 bit fp numbers
int exp = 128 + l2; // on C64 FP's the bias is 63
exponent = integerToBinary( exp );
string nmb = integerToBinary(integral_part) + fractionalToBinary(fractional_part);
int first_one = nmb.length();
for( int i = 0; i < nmb.length(); i++ )
{
if( nmb[i] == '1' )
{
first_one = i;
break;
}
}
first_one++;
nmb = nmb.substr( first_one, nmb.length() );
nmb = exponent + sign + nmb;
while( nmb.length() < 40 )
{
nmb+="0";
}
while( nmb.length() > 40 )
{
nmb = nmb.substr(0, nmb.length()-1);
}
return_value = binaryToHex( nmb );
return return_value;
}
string stripQuotes( string s )
{
return string(s).substr(1,string(s).length()-2);
}
// converts an integer into a string (in Hexadecimal)
// (the hard way)
string toHex( int i )
{
if( i == 0 ) return string( "00" );
int l=0;
string return_value = string("");
float f = (float)i;
while( f > 0 )
{
float tmp1=f/16;
float tmp2=(int) tmp1;
float rem=16*(tmp1-tmp2);
if (rem == 0) return_value = string("0") + return_value;
if (rem == 1) return_value = string("1") + return_value;
if (rem == 2) return_value = string("2") + return_value;
if (rem == 3) return_value = string("3") + return_value;
if (rem == 4) return_value = string("4") + return_value;
if (rem == 5) return_value = string("5") + return_value;
if (rem == 6) return_value = string("6") + return_value;
if (rem == 7) return_value = string("7") + return_value;
if (rem == 8) return_value = string("8") + return_value;
if (rem == 9) return_value = string("9") + return_value;
if (rem == 10) return_value = string("A") + return_value;
if (rem == 11) return_value = string("B") + return_value;
if (rem == 12) return_value = string("C") + return_value;
if (rem == 13) return_value = string("D") + return_value;
if (rem == 14) return_value = string("E") + return_value;
if (rem == 15) return_value = string("F") + return_value;
f=tmp2; l++;
}
if( l == 1 || l == 3) return_value = string("0") + return_value;
return return_value;
}
void inlineFloatPush( string s, int addr=105)
{
addDebugComment( "FloatIMM -> Stack" );
string sign;
addDebugComment( string("Base address: ") + toHex(addr) );
string stripped_float= stripFirst( s.c_str() );
string fp_in_hex = toBinaryFloat( atof( stripped_float.c_str() ) );
if( atof( stripped_float.c_str() ) == 0 ) fp_in_hex=string("0000000000");
int size_of_instruction=3;
if( addr < 255 ) size_of_instruction-=1;
int v=0;
for( int i=0; i<5; i++ )
{
addAsm( str_LDA + "#$" + fp_in_hex[v] + fp_in_hex[v+1], 2, false );
addAsm( str_PHA, 1, false );
v+=2;
}
return;
}
// convert a string to an inline-float
void inlineFloat( string s, int addr=105)
{
addComment( "inline float: " + stripFirst(s) );
addDebugComment( "=========== IMM -> FAC ==========" );
string sign;
addDebugComment( string("Base address: ") + toHex(addr) );
string stripped_float= stripFirst( s.c_str() );
string fp_in_hex = toBinaryFloat( atof( stripped_float.c_str() ) );
if( atof( stripped_float.c_str() ) == 0 ) fp_in_hex=string("0000000000");
int size_of_instruction=3;
if( addr < 255 ) size_of_instruction-=1;
int v=0;
for( int i=0; i<5; i++ )
{
if( addr <= 255 )
{ size_of_instruction = 2; }
else
{ size_of_instruction = 3; }
addAsm( str_LDA + "#$" + fp_in_hex[v] + fp_in_hex[v+1], 2, false );
if( getNameOf(addr) != "" )
{
if( i == 0 )
{
addAsm( str_STA + getNameOf(addr), size_of_instruction, false );
}
else
{
addAsm( str_STA + getNameOf(addr) + "+" + itos(i), size_of_instruction, false );
}
}
else
{
addAsm( str_STA + "$" + toHex(addr+i), size_of_instruction, false );
//addAsm( str_STA + getNameOf(addr) + "+" + itos(i), size_of_instruction, false );
}
v+=2;
}
if( addr == 105 )
{
addAsm( str_LDA + "#$69", 2, false );
addAsm( str_LDY + "#$00", 2, false );
addAsm( str_JSR + "$BBA2" + commentmarker + "RAM -> FAC", 3, false );
}
addDebugComment( "=================================" );
return;
}
class id_and_line
{
public:
id_and_line( string s, int l )
{
name = s;
line_number = l;
}
string getName(){ return name; };
int getLine(){ return line_number; };
private:
string name;
int line_number;
};
vector<id_and_line*> id_vector;
vector <id_and_line*> proposed_ids_vector;
vector <id_and_line*> defined_ids_vector;
class asm_function
{
public:
asm_function( string identifier, string l, int t )
{
name=identifier;
label = l;
address=0000;
type=t;
}
asm_function( string identifier, string l )
{
name=identifier;
label = l;
address=0000;
type=1;
}
string getIdentifier(){ return name; };
int getAddressInt(){ return address; };
string getAddress(){ return toHex( address ); };
void setAddress( int i ){ address=i; };
string getLabel(){ return label; };
int getType(){ return type; };
void setType( int i ){ type = i; };
private:
int address;
string name;
string label;
int type; // (return type)
};
vector<asm_function*> asm_functions;
asm_function * getAsmFunction( string s )
{
for( int i=0; i<asm_functions.size(); i++ )
{
if( asm_functions[i]->getIdentifier() == s )
{
return asm_functions[i];
}
}
return NULL;
}
string getLabelOfFunction( int i )
{
return asm_functions[i]->getLabel();
}
string getLabelOfFunction( string s )
{
for( int i=0; i<asm_functions.size(); i++ )
{
if( asm_functions[i]->getIdentifier() == s )
{
return asm_functions[i]->getLabel();
}
}
return NULL;
}
int getAddressOfFunction( string s )
{
for( int i=0; i<asm_functions.size(); i++ )
{
if( asm_functions[i]->getIdentifier() == s )
{
return asm_functions[i]->getAddressInt();
}
}
return 0;
}
int getTypeOfFunction( string s )
{
for( int i=0; i<asm_functions.size(); i++ )
{
if( asm_functions[i]->getIdentifier() == s )
{
return asm_functions[i]->getType();
}
}
return 0;
}
void addIncludeFile( string s )
{
include_file_vector.push_back( s );
}
//