-
Notifications
You must be signed in to change notification settings - Fork 1
/
rasm.c
14604 lines (13619 loc) · 497 KB
/
rasm.c
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
#define PROGRAM_NAME "RASM"
#define PROGRAM_VERSION "0.99"
#define PROGRAM_DATE "xx/07/2018"
#define PROGRAM_COPYRIGHT "© 2017 BERGE Edouard / roudoudou from Resistance"
#define RASM_VERSION PROGRAM_NAME" v"PROGRAM_VERSION
#define DEBUG_PREPRO 0
/***
Rasm (roudoudou assembler) Z80 assembler
doc & latest official release at: http://www.cpcwiki.eu/forum/programming/rasm-z80-assembler-in-beta/
You may send requests/bugs in the same topic
-----------------------------------------------------------------------------------------------------
This software is using MIT "expat" license
« Copyright © BERGE Edouard (roudoudou)
Permission is hereby granted, free of charge,to any person obtaining a copy of this software
and associated documentation/source files of RASM, to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
The Software is provided "as is", without warranty of any kind, express or implied,
including but not limited to the warranties of merchantability, fitness for a particular
purpose and noninfringement. In no event shall the authors or copyright holders be liable for
any claim, damages or other liability, whether in an action of contract, tort or otherwise,
arising from, out of or in connection with the software or the use or other dealings in the
Software. »
-----------------------------------------------------------------------------------------------------
Linux compilation with GCC or Clang:
cc rasm_v099.c -O2 -lm -lrt -march=native -o rasm
strip rasm
Windows compilation with Visual studio:
cl.exe rasm_v099.c -O2
DOS (windows compatible) 32 bits compilation with Watcom:
wcl386 rasm_v099.c -6r -6s -fp6 -d0 -k4000000 -ox /bt=DOS /l=dos4g
MorphOS compilation (ixemul):
ppc-morphos-gcc-5 -O2 -c -o rasm rasm_v099.c
strip rasm
*/
#ifdef __WATCOMC__
#define OS_WIN 1
#endif
#ifdef _WIN32
#define OS_WIN 1
#endif
#ifdef _WIN64
#define OS_WIN 1
#endif
#ifndef RDD
/* public lib */
#include"minilib.h"
#else
/* private dev lib wont be published */
#include"../tools/library.h"
#define TxtSplitWithChar _internal_TxtSplitWithChar
#endif
#ifndef NO_3RD_PARTIES
#define __FILENAME__ "3rd parties"
/* 3rd parties compression */
#include"zx7.h"
#include"lz4.h"
#include"exomizer.h"
#endif
#ifdef __MORPHOS__
/* Add standard version string to executable */
const char __attribute__((section(".text"))) ver_version[]={ "\0$VER: "PROGRAM_NAME" "PROGRAM_VERSION" ("PROGRAM_DATE") "PROGRAM_COPYRIGHT"" };
#endif
#undef __FILENAME__
#define __FILENAME__ "rasm.c"
/*******************************************************************
c o m m a n d l i n e p a r a m e t e r s
*******************************************************************/
enum e_dependencies_type {
E_DEPENDENCIES_NO=0,
E_DEPENDENCIES_LIST,
E_DEPENDENCIES_MAKE
};
struct s_parameter {
char **labelfilename;
char *filename;
char *outputfilename;
int export_local;
int export_var;
int export_equ;
int export_sym;
int export_sna;
int export_snabrk;
int export_brk;
int verbose;
int nowarning;
int checkmode;
int dependencies;
int maxerr;
int extended_error;
int edskoverwrite;
float rough;
int as80,dams;
int v2;
char *symbol_name;
char *binary_name;
char *cartridge_name;
char *snapshot_name;
char *breakpoint_name;
char **symboldef;
int nsymb,msymb;
char **pathdef;
int npath,mpath;
};
/*******************************************************************
c o m p u t e o p e r a t i o n s f o r c a l c u l a t o r
*******************************************************************/
enum e_compute_operation_type {
E_COMPUTE_OPERATION_PUSH_DATASTC=0,
E_COMPUTE_OPERATION_OPEN=1,
E_COMPUTE_OPERATION_CLOSE=2,
E_COMPUTE_OPERATION_ADD=3,
E_COMPUTE_OPERATION_SUB=4,
E_COMPUTE_OPERATION_DIV=5,
E_COMPUTE_OPERATION_MUL=6,
E_COMPUTE_OPERATION_AND=7,
E_COMPUTE_OPERATION_OR=8,
E_COMPUTE_OPERATION_MOD=9,
E_COMPUTE_OPERATION_XOR=10,
E_COMPUTE_OPERATION_NOT=11,
E_COMPUTE_OPERATION_SHL=12,
E_COMPUTE_OPERATION_SHR=13,
E_COMPUTE_OPERATION_BAND=14,
E_COMPUTE_OPERATION_BOR=15,
E_COMPUTE_OPERATION_LOWER=16,
E_COMPUTE_OPERATION_GREATER=17,
E_COMPUTE_OPERATION_EQUAL=18,
E_COMPUTE_OPERATION_NOTEQUAL=19,
E_COMPUTE_OPERATION_LOWEREQ=20,
E_COMPUTE_OPERATION_GREATEREQ=21,
/* math functions */
E_COMPUTE_OPERATION_SIN=22,
E_COMPUTE_OPERATION_COS=23,
E_COMPUTE_OPERATION_INT=24,
E_COMPUTE_OPERATION_FLOOR=25,
E_COMPUTE_OPERATION_ABS=26,
E_COMPUTE_OPERATION_LN=27,
E_COMPUTE_OPERATION_LOG10=28,
E_COMPUTE_OPERATION_SQRT=29,
E_COMPUTE_OPERATION_ASIN=30,
E_COMPUTE_OPERATION_ACOS=31,
E_COMPUTE_OPERATION_ATAN=32,
E_COMPUTE_OPERATION_EXP=33,
E_COMPUTE_OPERATION_LOW=34,
E_COMPUTE_OPERATION_HIGH=35,
E_COMPUTE_OPERATION_PSG=36,
E_COMPUTE_OPERATION_END=37
};
struct s_compute_element {
enum e_compute_operation_type operator;
double value;
int priority;
};
struct s_compute_core_data {
/* evaluator v3 may be recursive */
char *varbuffer;
int maxivar;
struct s_compute_element *tokenstack;
int maxtokenstack;
struct s_compute_element *operatorstack;
int maxoperatorstack;
};
/***********************************************************
w a v h e a d e r f o r a u d i o i m p o r t
***********************************************************/
struct s_wav_header {
unsigned char ChunkID[4];
unsigned char ChunkSize[4];
unsigned char Format[4];
unsigned char SubChunk1ID[4];
unsigned char SubChunk1Size[4];
unsigned char AudioFormat[2];
unsigned char NumChannels[2];
unsigned char SampleRate[4];
unsigned char ByteRate[4];
unsigned char BlockAlign[2];
unsigned char BitsPerSample[2];
unsigned char SubChunk2ID[4];
unsigned char SubChunk2Size[4];
};
enum e_audio_sample_type {
AUDIOSAMPLE_SMP,
AUDIOSAMPLE_SM2,
AUDIOSAMPLE_SM4,
AUDIOSAMPLE_DMA,
AUDIOSAMPLE_END
};
/***********************************************************************
e x p r e s s i o n t y p e s f o r d e l a y e d w r i t e
***********************************************************************/
enum e_expression {
E_EXPRESSION_J8, /* relative 8bits jump */
E_EXPRESSION_0V8, /* 8 bits value to current adress */
E_EXPRESSION_V8, /* 8 bits value to current adress+1 */
E_EXPRESSION_V16, /* 16 bits value to current adress+1 */
E_EXPRESSION_0V16, /* 16 bits value to current adress */
E_EXPRESSION_0V32, /* 32 bits value to current adress */
E_EXPRESSION_0VR, /* AMSDOS real value (5 bytes) to current adress */
E_EXPRESSION_IV8, /* 8 bits value to current adress+2 */
E_EXPRESSION_IV81, /* 8 bits value+1 to current adress+2 */
E_EXPRESSION_3V8, /* 8 bits value to current adress+3 used with LD (IX+n),n */
E_EXPRESSION_IV16, /* 16 bits value to current adress+2 */
E_EXPRESSION_RST, /* the offset of RST is translated to the opcode */
E_EXPRESSION_IM /* the interrupt mode is translated to the opcode */
};
struct s_expression {
char *reference; /* backup when used inside loop (or macro?) */
int iw; /* word index in the main wordlist */
int o; /* offset de depart 0, 1 ou 3 selon l'opcode */
int ptr; /* offset courant pour calculs relatifs */
int wptr; /* where to write the result */
enum e_expression zetype; /* type of delayed write */
int lz; /* lz zone */
int ibank; /* ibank of expression */
int iorgzone; /* org of expression */
};
struct s_expr_dico {
char *name;
int crc;
double v;
};
struct s_label {
char *name; /* is alloced for local repeat or struct -> in this case iw=-1 */
int iw; /* index of the word of label name */
int crc; /* crc of the label name */
int ptr; /* "physical" adress */
int lz; /* is the label in a crunched section (or after)? */
int iorgzone; /* org of label */
int ibank; /* current CPR bank / always zero in classic mode */
/* errmsg */
int fileidx;
int fileline;
};
struct s_alias {
char *alias;
char *translation;
int crc,len;
};
/***********************************************************************
m e r k e l t r e e s f o r l a b e l, v a r, a l i a s
***********************************************************************/
struct s_crclabel_tree {
struct s_crclabel_tree *radix[256];
struct s_label *label;
int nlabel,mlabel;
};
struct s_crcdico_tree {
struct s_crcdico_tree *radix[256];
struct s_expr_dico *dico;
int ndico,mdico;
};
struct s_crcused_tree {
struct s_crcused_tree *radix[256];
char **used;
int nused,mused;
};
struct s_crcstring_tree {
struct s_crcstring_tree *radix[256];
char **text;
int ntext,mtext;
char **replace;
int nreplace,mreplace;
};
/*************************************************
m e m o r y s e c t i o n
*************************************************/
struct s_lz_section {
int iw;
int memstart,memend;
int lzversion; /* 4 -> LZ4 / 7 -> ZX7 / 48 -> LZ48 / 49 -> LZ49 / 8 -> Exomizer */
int iorgzone;
int ibank;
/* idx backup */
int iexpr;
int ilabel;
};
struct s_orgzone {
int ibank,protect;
int memstart,memend;
int ifile,iline;
int nocode;
};
/**************************************************
i n c b i n s t o r a g e
**************************************************/
struct s_hexbin {
unsigned char *data;
int datalen,rawlen;
char *filename;
};
/**************************************************
e d s k m a n a g e m e n t
**************************************************/
struct s_edsk_sector_global_struct {
unsigned char track;
unsigned char side;
unsigned char id;
unsigned char size;
unsigned char st1;
unsigned char st2;
unsigned short int length;
unsigned char *data;
};
struct s_edsk_track_global_struct {
int sectornumber;
/* information purpose */
int sectorsize;
int gap3length;
int fillerbyte;
int datarate;
int recordingmode;
struct s_edsk_sector_global_struct *sector;
};
struct s_edsk_global_struct {
int tracknumber;
int sidenumber;
int tracksize; /* DSK legacy */
struct s_edsk_track_global_struct *track;
};
struct s_edsk_wrapper_entry {
unsigned char user;
unsigned char filename[11];
unsigned char subcpt;
unsigned char extendcounter;
unsigned char reserved;
unsigned char rc;
unsigned char blocks[16];
};
struct s_edsk_wrapper {
char *edsk_filename;
struct s_edsk_wrapper_entry entry[64];
int nbentry;
unsigned char blocks[178][1024]; /* DATA format */
int face;
};
struct s_save {
int ibank;
int ioffset;
int isize;
int iw;
int amsdos;
int dsk,face,iwdskname;
};
/********************
L O O P S
********************/
enum e_loop_style {
E_LOOPSTYLE_REPEATN,
E_LOOPSTYLE_REPEATUNTIL,
E_LOOPSTYLE_WHILE
};
struct s_repeat {
int start;
int cpt;
int value;
int maxim;
int repeat_counter;
char *repeatvar;
int repeatcrc;
};
struct s_whilewend {
int start;
int cpt;
int value;
int maxim;
int while_counter;
};
struct s_switchcase {
int refval;
int execute;
int casematch;
};
struct s_repeat_index {
int ifile;
int ol,oidx;
int cl,cidx;
};
enum e_ifthen_type {
E_IFTHEN_TYPE_IF=0,
E_IFTHEN_TYPE_IFNOT=1,
E_IFTHEN_TYPE_IFDEF=2,
E_IFTHEN_TYPE_IFNDEF=3,
E_IFTHEN_TYPE_ELSE=4,
E_IFTHEN_TYPE_ELSEIF=5,
E_IFTHEN_TYPE_IFUSED=6,
E_IFTHEN_TYPE_IFNUSED=7,
E_IFTHEN_TYPE_END
};
struct s_ifthen {
char *filename;
int line,v;
enum e_ifthen_type type;
};
/**************************************************
w o r d p r o c e s s i n g
**************************************************/
struct s_wordlist {
char *w;
int l,t,e; /* e=1 si egalite dans le mot */
int ifile;
};
struct s_macro {
char *mnemo;
int crc;
/* une macro concatene des chaines et des parametres */
struct s_wordlist *wc;
int nbword,maxword;
/**/
char **param;
int nbparam;
};
struct s_macro_position {
int start,end,value;
};
/* preprocessing only */
struct s_macro_fast {
char *mnemo;
int crc;
};
struct s_math_keyword {
char *mnemo;
int crc;
enum e_compute_operation_type operation;
};
struct s_expr_word {
char *w;
int aw;
int op;
int comma;
int fct;
double v;
};
struct s_listing {
char *listing;
int ifile;
int iline;
};
enum e_tagtranslateoption {
E_TAGOPTION_NONE=0,
E_TAGOPTION_REMOVESPACE
};
#ifdef RASM_THREAD
struct s_rasm_thread {
pthread_t thread;
int lz;
unsigned char *datain;
int datalen;
unsigned char *dataout;
int lenout;
int status;
};
#endif
/*********************************************************
S N A P S H O T E X P O R T
*********************************************************/
struct s_snapshot_symbol {
unsigned char size;
unsigned char name[256];
unsigned char reserved[6];
unsigned char bigendian_adress[2];
};
struct s_snapshot {
char idmark[8];
char unused1[8];
unsigned char version; /* 3 */
struct {
struct {
unsigned char F;
unsigned char A;
unsigned char C;
unsigned char B;
unsigned char E;
unsigned char D;
unsigned char L;
unsigned char H;
}general;
unsigned char R;
unsigned char regI; /* I incompatible with tgmath.h */
unsigned char IFF0;
unsigned char IFF1;
unsigned char LX;
unsigned char HX;
unsigned char LY;
unsigned char HY;
unsigned char LSP;
unsigned char HSP;
unsigned char LPC;
unsigned char HPC;
unsigned char IM; /* 0,1,2 */
struct {
unsigned char F;
unsigned char A;
unsigned char C;
unsigned char B;
unsigned char E;
unsigned char D;
unsigned char L;
unsigned char H;
}alternate;
}registers;
struct {
unsigned char selectedpen;
unsigned char palette[17];
unsigned char multiconfiguration;
}gatearray;
unsigned char ramconfiguration;
struct {
unsigned char selectedregister;
unsigned char registervalue[18];
}crtc;
unsigned char romselect;
struct {
unsigned char portA;
unsigned char portB;
unsigned char portC;
unsigned char control;
}ppi;
struct {
unsigned char selectedregister;
unsigned char registervalue[16];
}psg;
unsigned char dumpsize[2]; /* 64 then use extended memory chunks */
unsigned char CPCType; /* 0=464 / 1=664 / 2=6128 / 4=6128+ / 5=464+ / 6=GX4000 */
unsigned char interruptnumber;
unsigned char multimodebytes[6];
unsigned char unused2[0x9C-0x75];
/* offset #9C */
struct {
unsigned char motorstate;
unsigned char physicaltrack;
}fdd;
unsigned char unused3[3];
unsigned char printerstrobe;
unsigned char unused4[2];
struct {
unsigned char model; /* 0->4 */
unsigned char unused5[4];
unsigned char HCC;
unsigned char unused;
unsigned char CLC;
unsigned char RLC;
unsigned char VTC;
unsigned char HSC;
unsigned char VSC;
unsigned short int flags;
}crtcstate;
unsigned char vsyncdelay;
unsigned char interruptscanlinecounter;
unsigned char interruptrequestflag;
unsigned char unused6[0xFF-0xB5+1];
};
struct s_snapshot_chunks {
unsigned char chunkname[4]; /* MEM1 -> MEM8 */
unsigned int chunksize;
};
struct s_breakpoint {
int address;
int bank;
};
/*********************************
S T R U C T U R E S
*********************************/
struct s_rasmstructfield {
char *name;
int offset;
};
struct s_rasmstruct {
char *name;
int crc;
int size;
/* fields */
struct s_rasmstructfield *rasmstructfield;
int irasmstructfield,mrasmstructfield;
};
/*******************************************
G L O B A L S T R U C T
*******************************************/
struct s_assenv {
/* current memory */
int maxptr;
/* CPR memory */
unsigned char **mem;
int iwnamebank[35];
int nbbank,maxbank;
int forcecpr,bankmode,activebank,amsdos,forcesnapshot,packedbank;
struct s_snapshot snapshot;
int bankset[9]; /* 64K selected flag */
int bankused[35]; /* 16K selected flag */
int bankgate[36];
/* parsing */
struct s_wordlist *wl;
int nbword;
int idx,stage;
char *label_filename;
int label_line;
char **filename;
int ifile,maxfile;
int nberr,flux,verbose;
int fastmatch[256];
unsigned char charset[256];
int maxerr,extended_error,nowarning;
/* ORG tracking */
int codeadr,outputadr,nocode;
int minadr,maxadr;
struct s_orgzone *orgzone;
int io,mo;
/* Struct */
struct s_rasmstruct *rasmstruct;
int irasmstruct,mrasmstruct;
int getstruct;
int backup_outputadr,backup_codeadr;
char *backup_filename;
int backup_line;
struct s_rasmstruct *rasmstructalias;
int irasmstructalias,mrasmstructalias;
/* expressions */
struct s_expression *expression;
int ie,me;
int maxam,as80,dams;
float rough;
struct s_compute_core_data *computectx,ctx1,ctx2;
struct s_crcstring_tree stringtree;
/* label */
struct s_label *label;
int il,ml;
struct s_crclabel_tree labeltree; /* fast label access */
char *module;
struct s_breakpoint *breakpoint;
int ibreakpoint,maxbreakpoint;
char *lastgloballabel;
int lastgloballabellen;
/* repeat */
struct s_repeat *repeat;
int ir,mr;
/* while/wend */
struct s_whilewend *whilewend;
int iw,mw;
/* if/then/else */
//int *ifthen;
struct s_ifthen *ifthen;
int ii,mi;
/* switch/case */
struct s_switchcase *switchcase;
int isw,msw;
/* expression dictionnary */
struct s_expr_dico *dico;
int idic,mdic;
struct s_crcdico_tree dicotree; /* fast dico access */
struct s_crcused_tree usedtree; /* fast used access */
/* crunch section flag */
struct s_lz_section *lzsection;
int ilz,mlz;
int lz,curlz;
/* macro */
struct s_macro *macro;
int imacro,mmacro;
/* labels locaux */
int repeatcounter,whilecounter,macrocounter;
struct s_macro_position *macropos;
int imacropos,mmacropos;
/* alias */
struct s_alias *alias;
int ialias,malias;
/* hexbin */
struct s_rasm_thread **rasm_thread;
int irt,mrt;
struct s_hexbin *hexbin;
int ih,mh;
char **includepath;
int ipath,mpath;
/* automates */
char AutomateExpressionValidCharExtended[256];
char AutomateExpressionValidCharFirst[256];
char AutomateExpressionValidChar[256];
char AutomateExpressionDecision[256];
char AutomateValidLabelFirst[256];
char AutomateValidLabel[256];
char AutomateDigit[256];
char AutomateHexa[256];
struct s_compute_element AutomateElement[256];
unsigned char psgtab[256];
unsigned char psgfine[256];
/* output */
char *outputfilename;
int export_sym,export_local;
int export_var,export_equ;
int export_sna,export_snabrk;
int export_brk;
char *breakpoint_name;
char *symbol_name;
char *binary_name;
char *cartridge_name;
char *snapshot_name;
struct s_save *save;
int nbsave,maxsave;
struct s_edsk_wrapper *edsk_wrapper;
int nbedskwrapper,maxedskwrapper;
int edskoverwrite;
int checkmode,dependencies;
int stop;
};
struct s_asm_keyword {
char *mnemo;
int crc;
void (*makemnemo)(struct s_assenv *ae);
};
struct s_math_keyword math_keyword[]={
{"SIN",0,E_COMPUTE_OPERATION_SIN},
{"COS",0,E_COMPUTE_OPERATION_COS},
{"INT",0,E_COMPUTE_OPERATION_INT},
{"ABS",0,E_COMPUTE_OPERATION_ABS},
{"LN",0,E_COMPUTE_OPERATION_LN},
{"LOG10",0,E_COMPUTE_OPERATION_LOG10},
{"SQRT",0,E_COMPUTE_OPERATION_SQRT},
{"FLOOR",0,E_COMPUTE_OPERATION_FLOOR},
{"ASIN",0,E_COMPUTE_OPERATION_ASIN},
{"ACOS",0,E_COMPUTE_OPERATION_ACOS},
{"ATAN",0,E_COMPUTE_OPERATION_ATAN},
{"EXP",0,E_COMPUTE_OPERATION_EXP},
{"LO",0,E_COMPUTE_OPERATION_LOW},
{"HI",0,E_COMPUTE_OPERATION_HIGH},
{"PSGVALUE",0,E_COMPUTE_OPERATION_PSG},
{"",0,-1}
};
#define CRC_SWITCH 0x01AEDE4A
#define CRC_CASE 0x0826B794
#define CRC_DEFAULT 0x9A0DAC7D
#define CRC_BREAK 0xCD364DDD
#define CRC_ENDSWITCH 0x18E9FB21
#define CRC_ELSEIF 0xE175E230
#define CRC_ELSE 0x3FF177A1
#define CRC_ENDIF 0xCD5265DE
#define CRC_IF 0x4BD52507
#define CRC_IFDEF 0x4CB29DD6
#define CRC_UNDEF 0xCCD2FDEA
#define CRC_IFNDEF 0xD9AD0824
#define CRC_IFNOT 0x4CCAC9F8
#define CRC_WHILE 0xBC268FF1
#define CRC_UNTIL 0xCC12A604
#define CRC_MEND 0xFFFD899C
#define CRC_ENDM 0x3FF9559C
#define CRC_MACRO 0x64AA85EA
#define CRC_IFUSED 0x91752638
#define CRC_IFNUSED 0x1B39A886
#define CRC_SIN 0xE1B71962
#define CRC_COS 0xE077C55D
#define CRC_0 0x7A98A6A8
#define CRC_1 0x7A98A6A9
#define CRC_2 0x7A98A6AA
#define CRC_NC 0x4BD52B09
#define CRC_Z 0x7A98A6D2
#define CRC_NZ 0x4BD52B20
#define CRC_P 0x7A98A6C8
#define CRC_PO 0x4BD53717
#define CRC_PE 0x4BD5370D
#define CRC_M 0x7A98A6C5
/* 8 bits registers */
#define CRC_F 0x7A98A6BE
#define CRC_I 0x7A98A6C1
#define CRC_R 0x7A98A6CA
#define CRC_A 0x7A98A6B9
#define CRC_B 0x7A98A6BA
#define CRC_C 0x7A98A6BB
#define CRC_D 0x7A98A6BC
#define CRC_E 0x7A98A6BD
#define CRC_H 0x7A98A6C0
#define CRC_L 0x7A98A6C4
/* dual naming */
#define CRC_XH 0x4BD50718
#define CRC_XL 0x4BD5071C
#define CRC_YH 0x4BD50519
#define CRC_YL 0x4BD5051D
#define CRC_HX 0x4BD52718
#define CRC_LX 0x4BD52F1C
#define CRC_HY 0x4BD52719
#define CRC_LY 0x4BD52F1D
#define CRC_IXL 0xE19F1765
#define CRC_IXH 0xE19F1761
#define CRC_IYL 0xE19F1166
#define CRC_IYH 0xE19F1162
/* 16 bits registers */
#define CRC_BC 0x4BD5D2FD
#define CRC_DE 0x4BD5DF01
#define CRC_HL 0x4BD5270C
#define CRC_IX 0x4BD52519
#define CRC_IY 0x4BD5251A
#define CRC_SP 0x4BD5311B
#define CRC_AF 0x4BD5D4FF
/* memory convention */
#define CRC_MHL 0xD0765F5D
#define CRC_MDE 0xD0467D52
#define CRC_MBC 0xD05E694E
#define CRC_MIX 0xD072B76A
#define CRC_MIY 0xD072B16B
#define CRC_MSP 0xD01A876C
#define CRC_MC 0xE018210C
/* struct parsing */
#define CRC_DEFB 0x37D15389
#define CRC_DB 0x4BD5DEFE
#define CRC_DEFW 0x37D1539E
#define CRC_DW 0x4BD5DF13
#define CRC_DEFI 0x37D15390
#define CRC_DEFS 0x37D1539A
#define CRC_DS 0x4BD5DF0F
#define CRC_DEFR 0x37D15399
#define CRC_DR 0x4BD5DF0E
/*
# base=16
% base=2
0-9 base=10
A-Z variable ou fonction (cos, sin, tan, sqr, pow, mod, and, xor, mod, ...)
+*-/&^m| operateur
*/
#define AutomateExpressionValidCharExtendedDefinition "0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ_{}@+-*/~^$#%§<=>|&"
#define AutomateExpressionValidCharFirstDefinition "#%0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ_@${"
#define AutomateExpressionValidCharDefinition "0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ_{}@$"
#define AutomateValidLabelFirstDefinition ".ABCDEFGHIJKLMNOPQRSTUVWXYZ_@"
#define AutomateValidLabelDefinition "0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ_@{}"
#define AutomateDigitDefinition ".0123456789"
#define AutomateHexaDefinition "0123456789ABCDEF"
#ifndef NO_3RD_PARTIES
unsigned char *LZ4_crunch(unsigned char *data, int zelen, int *retlen){
unsigned char *lzdest=NULL;
lzdest=MemMalloc(65536);
*retlen=LZ4_compress_HC((char*)data,(char*)lzdest,zelen,65536,9);
return lzdest;
}
#endif
unsigned char *LZ48_encode_legacy(unsigned char *data, int length, int *retlength);
#define LZ48_crunch LZ48_encode_legacy
unsigned char *LZ49_encode_legacy(unsigned char *data, int length, int *retlength);
#define LZ49_crunch LZ49_encode_legacy
/*
* optimised reading of text file in one shot
*/
unsigned char *_internal_readbinaryfile(char *filename, int *filelength)
{
#undef FUNC
#define FUNC "_internal_readbinaryfile"
unsigned char *binary_data=NULL;
*filelength=FileGetSize(filename);
binary_data=MemMalloc((*filelength)+1);
/* we try to read one byte more to close the file just after the read func */
if (FileReadBinary(filename,(char*)binary_data,(*filelength)+1)!=*filelength) {
logerr("Cannot fully read %s",filename);
exit(INTERNAL_ERROR);
}
return binary_data;
}
char **_internal_readtextfile(char *filename, char replacechar)
{
#undef FUNC
#define FUNC "_internal_readtextfile"
char **lines_buffer=NULL;
unsigned char *bigbuffer;
int nb_lines=0,max_lines=0,i=0,e=0;
int file_size;
bigbuffer=_internal_readbinaryfile(filename,&file_size);
while (i<file_size) {
while (e<file_size && bigbuffer[e]!=0x0A) {
/* Windows de meeeeeeeerrrdde... */
if (bigbuffer[e]==0x0D) bigbuffer[e]=replacechar;
e++;
}
if (e<file_size) e++;
if (nb_lines>=max_lines) {
max_lines=max_lines*2+10;
lines_buffer=MemRealloc(lines_buffer,(max_lines+1)*sizeof(char **));
}
lines_buffer[nb_lines]=MemMalloc(e-i+1);
memcpy(lines_buffer[nb_lines],bigbuffer+i,e-i);
lines_buffer[nb_lines][e-i]=0;
if (0)
{
int yy;
for (yy=0;lines_buffer[nb_lines][yy];yy++) {
if (lines_buffer[nb_lines][yy]>31) printf("%c",lines_buffer[nb_lines][yy]); else printf("(0x%X)",lines_buffer[nb_lines][yy]);
}
printf("\n");
}
nb_lines++;
i=e;
}
if (!max_lines) {
lines_buffer=MemMalloc(sizeof(char**));
lines_buffer[0]=NULL;
} else {
lines_buffer[nb_lines]=NULL;
}
MemFree(bigbuffer);
return lines_buffer;
}
#define FileReadLines(filename) _internal_readtextfile(filename,':')
#define FileReadLinesRAW(filename) _internal_readtextfile(filename,0x0D)
#define FileReadContent(filename,filesize) _internal_readbinaryfile(filename,filesize)
/***
TxtReplace