Subversion Repositories Kolibri OS

Rev

Rev 9705 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9705 Rev 9717
1
#define _MAIN_
1
#define _MAIN_
2
 
2
 
3
#ifdef _UNIX_
3
#ifdef _UNIX_
4
#define DIV_PATH ':'			//äåëèòåëü ïóòåé â ïåðåìåííîé îêðóæåíèÿ PATH
4
#define DIV_PATH ':'			//äåëèòåëü ïóòåé â ïåðåìåííîé îêðóæåíèÿ PATH
5
#define DIV_FOLD '/'			//ýòèì ñèìâîëîì ðàçäåëÿþòñÿ ïàïêè â ïóòè ê ôàéëó
5
#define DIV_FOLD '/'			//ýòèì ñèìâîëîì ðàçäåëÿþòñÿ ïàïêè â ïóòè ê ôàéëó
6
#endif
6
#endif
7
 
7
 
8
#ifdef _WIN32_
8
#ifdef _WIN32_
9
#define DIV_PATH ';'
9
#define DIV_PATH ';'
10
#define DIV_FOLD '\\'
10
#define DIV_FOLD '\\'
11
#endif
11
#endif
12
 
12
 
13
#ifdef _KOS_
13
#ifdef _KOS_
14
#define DIV_PATH ';'
14
#define DIV_PATH ';'
15
#define DIV_FOLD '/'
15
#define DIV_FOLD '/'
16
#endif
16
#endif
17
 
17
 
18
#include 
18
#include 
19
#include 
19
#include 
20
#include 
20
#include 
21
#include 
21
#include 
22
#include "tok.h"
22
#include "tok.h"
-
 
23
 
-
 
24
#ifdef _KOS_
-
 
25
#include 
-
 
26
#endif
23
 
27
 
24
static char **_Argv; //!!! simplest way to make your own variable
28
static char **_Argv; //!!! simplest way to make your own variable
25
 
29
 
26
unsigned char compilerstr[]="SPHINX C-- 0.239";
30
unsigned char compilerstr[]="SPHINX C-- 0.239";
27
char *rawfilename;					/* file name */
31
char *rawfilename;					/* file name */
28
char *rawext;
32
char *rawext;
29
LISTCOM *listcom;
33
LISTCOM *listcom;
30
EWAR wartype={NULL,NULL},errfile={NULL,NULL};
34
EWAR wartype={NULL,NULL},errfile={NULL,NULL};
31
int numfindpath=0;
35
int numfindpath=0;
32
char *findpath[16];
36
char *findpath[16];
33
char modelmem=TINY;
37
char modelmem=TINY;
34
char *stubfile=NULL;
38
char *stubfile=NULL;
35
char *winstub=NULL;
39
char *winstub=NULL;
36
FILE *hout=NULL;
40
FILE *hout=NULL;
37
const char *namestartupfile="startup.h--";
41
const char *namestartupfile="startup.h--";
38
 
42
 
39
char outext[4] = "com";
43
char outext[4] = "com";
40
short extflag=TRUE;//ðàñøèðåíèå ìîæíî ïðèñâîèòü
44
short extflag=TRUE;//ðàñøèðåíèå ìîæíî ïðèñâîèòü
41
//int scrsize;
45
//int scrsize;
42
unsigned char gwarning=FALSE;
46
unsigned char gwarning=FALSE;
43
unsigned char sobj=FALSE;
47
unsigned char sobj=FALSE;
44
unsigned char usestub=TRUE;
48
unsigned char usestub=TRUE;
45
unsigned char dpmistub=FALSE;
49
unsigned char dpmistub=FALSE;
46
short dllflag=FALSE;
50
short dllflag=FALSE;
47
static int numstr;
51
static int numstr;
48
 
52
 
49
char meinfo[]=
53
char meinfo[]=
50
	"\nEdition of this version by\n"
54
	"\nEdition of this version by\n"
51
	"    Mishel Sheker\n"
55
	"    Mishel Sheker\n"
52
	"    Fido 2:5021/3.40\n"
56
	"    Fido 2:5021/3.40\n"
53
	"    E-Mail sheker@mail.ru\n"
57
	"    E-Mail sheker@mail.ru\n"
54
	"    Russia";
58
	"    Russia";
55
 
59
 
56
time_t systime;
60
time_t systime;
57
struct tm timeptr;
61
struct tm timeptr;
58
char comsymbios=FALSE;
62
char comsymbios=FALSE;
59
char fobj=FALSE;	//ïðèçíàê ãåíåðàöèè obj
63
char fobj=FALSE;	//ïðèçíàê ãåíåðàöèè obj
60
unsigned int	startptr = 0x100; 			// start address
64
unsigned int	startptr = 0x100; 			// start address
61
unsigned char wconsole=FALSE;	//ïðèçíàê ãåíåðàöèè êîíñîëüíîãî ïðèëîæåíèÿ windows
65
unsigned char wconsole=FALSE;	//ïðèçíàê ãåíåðàöèè êîíñîëüíîãî ïðèëîæåíèÿ windows
62
unsigned char optstr=FALSE;	//îïòèìèçàöèÿ ñòðîêîâûõ êîíñòàíò
66
unsigned char optstr=FALSE;	//îïòèìèçàöèÿ ñòðîêîâûõ êîíñòàíò
63
unsigned char crif=TRUE;	//check reply include file
67
unsigned char crif=TRUE;	//check reply include file
64
unsigned char idasm=FALSE;	//àññåìáëåðíûå èíñòðóêöèè ñ÷èòàòü èäåíòèôèêàòîðàìè
68
unsigned char idasm=FALSE;	//àññåìáëåðíûå èíñòðóêöèè ñ÷èòàòü èäåíòèôèêàòîðàìè
65
unsigned char wbss=2;	//ïîñò ïåðåìåííûå â îòäåëüíóþ ñåêöèþ
69
unsigned char wbss=2;	//ïîñò ïåðåìåííûå â îòäåëüíóþ ñåêöèþ
66
unsigned char use_env=FALSE;	//ïåðåìåííàÿ îêðóæåíèÿ
70
unsigned char use_env=FALSE;	//ïåðåìåííàÿ îêðóæåíèÿ
67
int numrel=0;	//÷èñëî ýëåìåíòîâ â òàáëèöå ïåðåìåùåíèé
71
int numrel=0;	//÷èñëî ýëåìåíòîâ â òàáëèöå ïåðåìåùåíèé
68
unsigned char useordinal=FALSE;
72
unsigned char useordinal=FALSE;
69
unsigned char useDOS4GW=FALSE;
73
unsigned char useDOS4GW=FALSE;
70
unsigned char clearpost=FALSE;
74
unsigned char clearpost=FALSE;
71
unsigned char uselea=TRUE;
75
unsigned char uselea=TRUE;
72
unsigned char regoverstack=TRUE;
76
unsigned char regoverstack=TRUE;
73
unsigned char shortimport=FALSE;
77
unsigned char shortimport=FALSE;
74
unsigned char useinline=2;
78
unsigned char useinline=2;
75
unsigned char ocoff=FALSE;
79
unsigned char ocoff=FALSE;
76
unsigned char ESPloc=FALSE;
80
unsigned char ESPloc=FALSE;
77
 
81
 
78
int startupfile=-1;
82
int startupfile=-1;
79
int alignproc=8,aligncycle=8;
83
int alignproc=8,aligncycle=8;
80
 
84
 
81
const char *usage[]={
85
const char *usage[]={
82
"USAGE: C-- [options] [FILE_NAME.INI] [SOURCE_FILE_NAME]",
86
"USAGE: C-- [options] [FILE_NAME.INI] [SOURCE_FILE_NAME]",
83
"",
87
"",
84
"                       C-- COMPILER OPTIONS",
88
"                       C-- COMPILER OPTIONS",
85
"",
89
"",
86
"                           OPTIMIZATION",
90
"                           OPTIMIZATION",
87
"-OC  optimize for code size           -DE  enable temporary expansion variable",
91
"-OC  optimize for code size           -DE  enable temporary expansion variable",
88
"-OS  optimize for speed               -OST enable optimization string",
92
"-OS  optimize for speed               -OST enable optimization string",
89
"-ON  enable optimization number       -AP[=n] align start function",
93
"-ON  enable optimization number       -AP[=n] align start function",
90
"-UST use startup code for variables   -AC[=n] align start cycles",
94
"-UST use startup code for variables   -AC[=n] align start cycles",
91
#ifdef OPTVARCONST
95
#ifdef OPTVARCONST
92
"-ORV replace variable on constant     -OIR skip repeated initializing register",
96
"-ORV replace variable on constant     -OIR skip repeated initializing register",
93
#else
97
#else
94
"                                      -OIR skip repeated initializing register",
98
"                                      -OIR skip repeated initializing register",
95
#endif
99
#endif
96
"",
100
"",
97
"                          CODE GENERATION",
101
"                          CODE GENERATION",
98
"-2   80286 code optimizations         -SA=#### start code address",
102
"-2   80286 code optimizations         -SA=#### start code address",
99
"-3   80386 code optimizations         -AL=## set value insert byte",
103
"-3   80386 code optimizations         -AL=## set value insert byte",
100
"-4   80486 code optimizations         -WFA fast call API functions",
104
"-4   80486 code optimizations         -WFA fast call API functions",
101
"-5   pentium code optimizations       -IV  initial all variables",
105
"-5   pentium code optimizations       -IV  initial all variables",
102
"-A   enable address alignment         -SUV=#### start address variables",
106
"-A   enable address alignment         -SUV=#### start address variables",
103
"-AS[=n] def. alignment in structures  -LRS load in registers over stack",
107
"-AS[=n] def. alignment in structures  -LRS load in registers over stack",
104
"-UL  use 'lea' for adding registers   -JS  join stack calling functions",
108
"-UL  use 'lea' for adding registers   -JS  join stack calling functions",
105
"-BA  byte access to array",//             -ASP addressing local variable via ESP",
109
"-BA  byte access to array",//             -ASP addressing local variable via ESP",
106
"",
110
"",
107
"                           PREPROCESSOR",
111
"                           PREPROCESSOR",
108
"-IP=  include file path         -IA   assembly instructions as identifier",
112
"-IP=  include file path         -IA   assembly instructions as identifier",
109
"-D= defined identifier        -CRI- not check include file on repeated",
113
"-D= defined identifier        -CRI- not check include file on repeated",
110
"-MIF= main input file           -IND= import name from dll",
114
"-MIF= main input file           -IND= import name from dll",
111
"-SF=  other startup file",
115
"-SF=  other startup file",
112
"",
116
"",
113
"                              LINKING",
117
"                              LINKING",
114
"-AT    insert ATEXIT support block    -NS    disable stub",
118
"-AT    insert ATEXIT support block    -NS    disable stub",
115
"-ARGC  insert parse command line      -S=#####  set stack size",
119
"-ARGC  insert parse command line      -S=#####  set stack size",
116
"-P     insert parse command line      -WIB=##### set image base address",
120
"-P     insert parse command line      -WIB=##### set image base address",
117
"-C     insert CTRL ignoring code   -WFU   add Fix Up table, for Windows",
121
"-C     insert CTRL ignoring code   -WFU   add Fix Up table, for Windows",
118
"-R     insert resize memory block     -WMB   create Windows mono block",
122
"-R     insert resize memory block     -WMB   create Windows mono block",
119
"-ENV   insert variable with environ   -WS= set name stub file for win32",
123
"-ENV   insert variable with environ   -WS= set name stub file for win32",
120
"-J0    disable initial jump to main() -WBSS  set post data in bss section",
124
"-J0    disable initial jump to main() -WBSS  set post data in bss section",
121
"-J1    initial jump to main() short   -WO    call API functions on ordinals",
125
"-J1    initial jump to main() short   -WO    call API functions on ordinals",
122
"-J2    initial jump to main() near    -CPA   clear post area",
126
"-J2    initial jump to main() near    -CPA   clear post area",
123
"-STUB=  set name stub file      -WSI   short import table, for Windows",
127
"-STUB=  set name stub file      -WSI   short import table, for Windows",
124
"-DOS4GW file running with DOS4GW      -WAF=#### align Windows file (def 512)",
128
"-DOS4GW file running with DOS4GW      -WAF=#### align Windows file (def 512)",
125
"-STM   startup code in main function",
129
"-STM   startup code in main function",
126
"",
130
"",
127
"                           OUTPUT FILES",
131
"                           OUTPUT FILES",
128
"-TEXE DOS EXE file (model TINY)       -D32  EXE file (32bit code for DOS)",
132
"-TEXE DOS EXE file (model TINY)       -D32  EXE file (32bit code for DOS)",
129
"-EXE  DOS EXE file (model SMALL)      -W32  EXE for Windows32 GUI",
133
"-EXE  DOS EXE file (model SMALL)      -W32  EXE for Windows32 GUI",
130
"-OBJ  OBJ output file                 -W32C EXE for Windows32 console",
134
"-OBJ  OBJ output file                 -W32C EXE for Windows32 console",
131
"-SOBJ slave OBJ output file           -DLL  DLL for Windows32",
135
"-SOBJ slave OBJ output file           -DLL  DLL for Windows32",
132
"-COFF OBJ COFF output file            -DBG  create debug information",
136
"-COFF OBJ COFF output file            -DBG  create debug information",
133
"-SYM  COM file symbiosis              -LST  create assembly listing",
137
"-SYM  COM file symbiosis              -LST  create assembly listing",
134
"-SYS  device (SYS) file               -B32  32bit binary files",
138
"-SYS  device (SYS) file               -B32  32bit binary files",
135
"-MEOS executable file for MeOS        -MAP  create function map file",
139
"-MEOS executable file for MeOS        -MAP  create function map file",
136
"-EXT=  set file extension",
140
"-EXT=  set file extension",
137
"",
141
"",
138
"                           MISCELLANEOUS",
142
"                           MISCELLANEOUS",
139
"-HELP -H -? help, this info           -WORDS list of C-- reserved words",
143
"-HELP -H -? help, this info           -WORDS list of C-- reserved words",
140
"-W         enable warning             -LAI   list of assembler instructions",
144
"-W         enable warning             -LAI   list of assembler instructions",
141
"-WF= direct warnings to a file  -ME    display my name and my address",
145
"-WF= direct warnings to a file  -ME    display my name and my address",
142
"-MER=##    set maximum number errors  -X     disable SPHINX C-- header in output",
146
"-MER=##    set maximum number errors  -X     disable SPHINX C-- header in output",
143
"-NW=##     disable selected warnings  -WE=## selected warning will be error",
147
"-NW=##     disable selected warnings  -WE=## selected warning will be error",
144
//" -SCD        split code and date",
148
//" -SCD        split code and date",
145
NULL};
149
NULL};
146
 
150
 
147
const char *dir[]={
151
const char *dir[]={
148
	"ME",    "WORDS",   "SYM",   "LAI",
152
	"ME",    "WORDS",   "SYM",   "LAI",
149
 
153
 
150
	"OBJ",   "SOBJ",    "J0",		 "J1",     "J2",    "C",     "R",
154
	"OBJ",   "SOBJ",    "J0",		 "J1",     "J2",    "C",     "R",
151
	"P",     "X",       "EXE",   "S",      "SYS",   "ARGC",  "TEXE",
155
	"P",     "X",       "EXE",   "S",      "SYS",   "ARGC",  "TEXE",
152
	"ROM",   "W32",     "D32",   "W32C",   "AT",    "WFA",   "SA",
156
	"ROM",   "W32",     "D32",   "W32C",   "AT",    "WFA",   "SA",
153
	"STM",   "SUV",     "UST",   "MIF",    "DLL", 	"DOS4GW","ENV",
157
	"STM",   "SUV",     "UST",   "MIF",    "DLL", 	"DOS4GW","ENV",
154
	"CPA",   "WBSS",    "MEOS",  "SF",     "B32",   "WIB",   "DBG",
158
	"CPA",   "WBSS",    "MEOS",  "SF",     "B32",   "WIB",   "DBG",
155
 
159
 
156
	"OS",    "OC",      "A",     "0",      "1",     "2",     "3",
160
	"OS",    "OC",      "A",     "0",      "1",     "2",     "3",
157
	"4",     "5",       "6",     "7",      "8",     "9",     "W",
161
	"4",     "5",       "6",     "7",      "8",     "9",     "W",
158
	"WF",    "DE",
162
	"WF",    "DE",
159
	"ON",    "IP",      "STUB",  "NS",     "AP",    "D",     "OST",
163
	"ON",    "IP",      "STUB",  "NS",     "AP",    "D",     "OST",
160
	"CRI",   "IA",      "SCD",   "AL",     "WFU",   "IV",
164
	"CRI",   "IA",      "SCD",   "AL",     "WFU",   "IV",
161
	"MER",   "WMB",     "HELP",  "H",      "?",     "AC",    "WS",
165
	"MER",   "WMB",     "HELP",  "H",      "?",     "AC",    "WS",
162
	"IND",   "WO",      "NW",    "LST",    "AS",    "UL",    "LRS",
166
	"IND",   "WO",      "NW",    "LST",    "AS",    "UL",    "LRS",
163
	"WSI",   "WAF",     "OIR",   "COFF",   "JS",    "BA",    "ASP",
167
	"WSI",   "WAF",     "OIR",   "COFF",   "JS",    "BA",    "ASP",
164
#ifdef OPTVARCONST
168
#ifdef OPTVARCONST
165
	"ORV",
169
	"ORV",
166
#endif
170
#endif
167
   "MAP",  "WE",   "EXT",   NULL};
171
   "MAP",  "WE",   "EXT",   NULL};
168
 
172
 
169
enum {
173
enum {
170
	c_me,    c_key,     c_sym,   c_lasm,   c_endinfo=c_lasm,
174
	c_me,    c_key,     c_sym,   c_lasm,   c_endinfo=c_lasm,
171
 
175
 
172
	c_obj,   c_sobj,    c_j0,    c_j1,     c_j2,    c_ctrlc, c_r,
176
	c_obj,   c_sobj,    c_j0,    c_j1,     c_j2,    c_ctrlc, c_r,
173
	c_p,     c_x,		    c_exe,   c_s,      c_sys,   c_arg,   c_texe,
177
	c_p,     c_x,		    c_exe,   c_s,      c_sys,   c_arg,   c_texe,
174
	c_rom,   c_w32,     c_d32,   c_w32c,   c_at,    c_wfa,   c_sa,
178
	c_rom,   c_w32,     c_d32,   c_w32c,   c_at,    c_wfa,   c_sa,
175
	c_stm,   c_suv,     c_ust,   c_mif,    c_dll,   c_d4g,   c_env,
179
	c_stm,   c_suv,     c_ust,   c_mif,    c_dll,   c_d4g,   c_env,
176
	c_cpa,   c_wbss,    c_meos,  c_sf,     c_b32,   c_wib,   c_dbg,
180
	c_cpa,   c_wbss,    c_meos,  c_sf,     c_b32,   c_wib,   c_dbg,
177
	c_endstart=c_dbg,
181
	c_endstart=c_dbg,
178
 
182
 
179
	c_os,    c_oc,      c_a,     c_0,      c_1,     c_2,     c_3,
183
	c_os,    c_oc,      c_a,     c_0,      c_1,     c_2,     c_3,
180
	c_4,     c_5,       c_6,     c_7,      c_8,     c_9,     c_w,
184
	c_4,     c_5,       c_6,     c_7,      c_8,     c_9,     c_w,
181
	c_wf,    c_de,
185
	c_wf,    c_de,
182
	c_opnum, c_ip,      c_stub,  c_ns,     c_ap,    c_define,c_ost,
186
	c_opnum, c_ip,      c_stub,  c_ns,     c_ap,    c_define,c_ost,
183
	c_cri,   c_ia,      c_scd,   c_al,     c_wfu,   c_iv,
187
	c_cri,   c_ia,      c_scd,   c_al,     c_wfu,   c_iv,
184
	c_mer,   c_wmb,     c_help,  c_h,      c_hh,    c_ac,    c_ws,
188
	c_mer,   c_wmb,     c_help,  c_h,      c_hh,    c_ac,    c_ws,
185
	c_ind,   c_wo,      c_nw,    c_lst,    c_as,    c_ul,    c_lrs,
189
	c_ind,   c_wo,      c_nw,    c_lst,    c_as,    c_ul,    c_lrs,
186
	c_wsi,   c_waf,     c_oir,   c_coff,   c_js,    c_ba,    c_asp,
190
	c_wsi,   c_waf,     c_oir,   c_coff,   c_js,    c_ba,    c_asp,
187
#ifdef OPTVARCONST
191
#ifdef OPTVARCONST
188
	c_orv,
192
	c_orv,
189
#endif
193
#endif
190
	c_map,   c_we,      c_ext,   c_end};
194
	c_map,   c_we,      c_ext,   c_end};
191
 
195
 
192
#define NUMEXT 6	//÷èñëî ðàçðåøåííûõ ðàñøèðåíèé êîìïèëèðóåìîãî ôàéëà
196
#define NUMEXT 6	//÷èñëî ðàçðåøåííûõ ðàñøèðåíèé êîìïèëèðóåìîãî ôàéëà
193
char extcompile[NUMEXT][4]={"c--","cmm","c","h--","hmm","h"};
197
char extcompile[NUMEXT][4]={"c--","cmm","c","h--","hmm","h"};
194
 
198
 
195
#ifdef _KOS_
199
#ifdef _KOS_
196
char __pgmname[256];
200
char __pgmname[256];
197
char __cmdline[256];
201
char __cmdline[256];
198
#endif
202
#endif
199
 
203
 
200
char *bufstr=NULL;	//áóôåð äëÿ ñòðîê èç ïðîöåäóð
204
char *bufstr=NULL;	//áóôåð äëÿ ñòðîê èç ïðîöåäóð
201
int sbufstr=SIZEBUF;	//íà÷àëüíûé ðàçìåð ýòîãî áóôåðà
205
int sbufstr=SIZEBUF;	//íà÷àëüíûé ðàçìåð ýòîãî áóôåðà
202
 
206
 
203
void compile();
207
void compile();
204
void PrintInfo(char **str);
208
void PrintInfo(char **str);
205
void LoadIni(char *name);
209
void LoadIni(char *name);
206
//void CheckNumStr();
210
//void CheckNumStr();
207
void ListId(int num,unsigned char *list,unsigned short *ofs);
211
void ListId(int num,unsigned char *list,unsigned short *ofs);
208
void printmemsizes();
212
void printmemsizes();
209
void print8item(char *str);
213
void print8item(char *str);
210
void doposts(void);
214
void doposts(void);
211
void GetMemExeDat();
215
void GetMemExeDat();
212
void AddJmpApi();
216
void AddJmpApi();
213
void startsymbiosys(char *symfile);
217
void startsymbiosys(char *symfile);
214
int writeoutput();
218
int writeoutput();
215
void BadCommandLine(char *str);
219
void BadCommandLine(char *str);
216
void  CheckExtenshions();
220
void  CheckExtenshions();
217
void ImportName(char *name);
221
void ImportName(char *name);
218
void WarnUnusedVar();//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
222
void WarnUnusedVar();//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
219
void MakeExeHeader(EXE_DOS_HEADER *exeheader);
223
void MakeExeHeader(EXE_DOS_HEADER *exeheader);
220
void CheckPageCode(unsigned int ofs);
224
void CheckPageCode(unsigned int ofs);
221
int MakePE();
225
int MakePE();
222
int MakeObj();
226
int MakeObj();
223
void CheckUndefClassProc();
227
void CheckUndefClassProc();
224
 
228
 
225
// Added by Coldy
229
// Added by Coldy
226
void ParseObjCommand(int cmd);
230
void ParseObjCommand(int cmd);
227
 
-
 
228
#ifdef _KOS_
-
 
229
extern "C" {
-
 
230
    void con_set_title(char* title);
-
 
231
}
-
 
232
#endif
-
 
233
 
231
 
234
void ListId(int numfirstchar,unsigned char *list,unsigned short *ofs)
232
void ListId(int numfirstchar,unsigned char *list,unsigned short *ofs)
235
{
233
{
236
char buf[40];
234
char buf[40];
237
	for(int i=0;i
235
	for(int i=0;i
238
		if((short)ofs[i]!=-1){
236
		if((short)ofs[i]!=-1){
239
			if(i<26)buf[0]=(char)('A'+i);
237
			if(i<26)buf[0]=(char)('A'+i);
240
			else if(i==26)buf[0]='_';
238
			else if(i==26)buf[0]='_';
241
			else buf[0]=(char)(i-27+'a');
239
			else buf[0]=(char)(i-27+'a');
242
			unsigned char *ii=(unsigned char *)(list+ofs[i]);
240
			unsigned char *ii=(unsigned char *)(list+ofs[i]);
243
			while(*(short *)&*ii!=-1){
241
			while(*(short *)&*ii!=-1){
244
				ii+=2;
242
				ii+=2;
245
				strcpy(buf+1,(char *)ii);
243
				strcpy(buf+1,(char *)ii);
246
				ii+=strlen((char *)ii)+1;
244
				ii+=strlen((char *)ii)+1;
247
				puts(buf);
245
				puts(buf);
248
//				CheckNumStr();
246
//				CheckNumStr();
249
			}
247
			}
250
		}
248
		}
251
	}
249
	}
252
}
250
}
253
 
251
 
254
/*
252
/*
255
void PrintTegList(structteg *tteg)
253
void PrintTegList(structteg *tteg)
256
{
254
{
257
	if(tteg){
255
	if(tteg){
258
		PrintTegList(tteg->left);
256
		PrintTegList(tteg->left);
259
		PrintTegList(tteg->right);
257
		PrintTegList(tteg->right);
260
		puts(tteg->name);
258
		puts(tteg->name);
261
	}
259
	}
262
} */
260
} */
263
 
261
 
264
//unsigned long maxusedmem=0;
262
//unsigned long maxusedmem=0;
265
 
263
 
266
void ErrOpenFile(char *str)
264
void ErrOpenFile(char *str)
267
{
265
{
268
	printf("Unable to open file %s.\n",str);
266
	printf("Unable to open file %s.\n",str);
269
}
267
}
270
 
268
 
271
int main(int argc,char *argv[])
269
int main(int argc,char *argv[])
272
{
270
{
273
int count;
271
int count;
274
unsigned char pari=FALSE;
272
unsigned char pari=FALSE;
275
	char *buffer;
273
	char *buffer;
276
 
274
 
277
	char compiler_ver[64];
275
	char compiler_ver[64];
278
	snprintf(compiler_ver, 64, "\nSPHINX C-- Compiler   Version %d.%d%s   %s\r\n",ver1,ver2,betta,__DATE__);
276
	snprintf(compiler_ver, 64, "\nSPHINX C-- Compiler   Version %d.%d%s   %s\r\n",ver1,ver2,betta,__DATE__);
279
	puts(compiler_ver);
277
	puts(compiler_ver);
280
#ifdef _KOS_
278
#ifdef _KOS_
281
	con_set_title(compiler_ver);
279
	con_set_title(compiler_ver);
282
#endif
280
#endif
283
//	scrsize=24;
281
//	scrsize=24;
284
	if(argc>1){
282
	if(argc>1){
285
		_Argv=argv;// This make portable code
283
		_Argv=argv;// This make portable code
286
		bufstr=(char *)MALLOC(SIZEBUF);
284
		bufstr=(char *)MALLOC(SIZEBUF);
287
		output=(unsigned char *)MALLOC((size_t)MAXDATA);
285
		output=(unsigned char *)MALLOC((size_t)MAXDATA);
288
		outputdata=output;
286
		outputdata=output;
289
		postbuf=(postinfo *)MALLOC(MAXPOSTS*sizeof(postinfo));
287
		postbuf=(postinfo *)MALLOC(MAXPOSTS*sizeof(postinfo));
290
		strcpy((char *)string,argv[0]);
288
		strcpy((char *)string,argv[0]);
291
		rawext=strrchr((char *)string,DIV_FOLD);
289
		rawext=strrchr((char *)string,DIV_FOLD);
292
		
290
		
293
		if(rawext!=NULL){
291
		if(rawext!=NULL){
294
			rawext[0]=0;
292
			rawext[0]=0;
295
			IncludePath((char *)string);
293
			IncludePath((char *)string);
296
		} 
294
		} 
297
		rawfilename=getenv("C--");
295
		rawfilename=getenv("C--");
298
		if(rawfilename!=NULL)IncludePath(rawfilename);
296
		if(rawfilename!=NULL)IncludePath(rawfilename);
299
		
297
		
300
		rawfilename=rawext=NULL;
298
		rawfilename=rawext=NULL;
301
		LoadIni((char *)"c--.ini");	 
299
		LoadIni((char *)"c--.ini");	 
302
		
300
		
303
		for(count=1;count
301
		for(count=1;count
304
			if(argv[count][0]=='/'||argv[count][0]=='-'){
302
			if(argv[count][0]=='/'||argv[count][0]=='-'){
305
			//if(argv[count][0]=='-'){
303
			//if(argv[count][0]=='-'){
306
				if(SelectComand(argv[count]+1,&count)==c_end) BadCommandLine(argv[count]);
304
				if(SelectComand(argv[count]+1,&count)==c_end) BadCommandLine(argv[count]);
307
			}
305
			}
308
			else{
306
			else{
309
				if(pari==FALSE){
307
				if(pari==FALSE){
310
					rawfilename=argv[count];
308
					rawfilename=argv[count];
311
					pari=TRUE;
309
					pari=TRUE;
312
					if((rawext=strrchr(rawfilename,'.'))!=NULL){
310
					if((rawext=strrchr(rawfilename,'.'))!=NULL){
313
						if(stricmp(rawext,".ini")==0){	//óêàçàí ini ôàéë
311
						if(stricmp(rawext,".ini")==0){	//óêàçàí ini ôàéë
314
							rawfilename=NULL;
312
							rawfilename=NULL;
315
							rawext=NULL;
313
							rawext=NULL;
316
							LoadIni(argv[count]);
314
							LoadIni(argv[count]);
317
							if(rawfilename==NULL)pari=FALSE;
315
							if(rawfilename==NULL)pari=FALSE;
318
						}
316
						}
319
						else{
317
						else{
320
							*rawext++=0;
318
							*rawext++=0;
321
							CheckExtenshions();
319
							CheckExtenshions();
322
						}
320
						}
323
					}
321
					}
324
				}
322
				}
325
			}
323
			}
326
		}
324
		}
327
	}
325
	}
328
  //{	Added by Coldy
326
  //{	Added by Coldy
329
	//	If -coff (for fully mscoff)
327
	//	If -coff (for fully mscoff)
330
	if (ocoff && !sobj) {
328
	if (ocoff && !sobj) {
331
		am32 = TRUE;
329
		am32 = TRUE;
332
		ParseObjCommand(c_sobj);
330
		ParseObjCommand(c_sobj);
333
 
331
 
334
	}
332
	}
335
	//}
333
	//}
336
	if(rawfilename==NULL){
334
	if(rawfilename==NULL){
337
		PrintInfo((char **)usage);
335
		PrintInfo((char **)usage);
338
		exit( e_noinputspecified );
336
		exit( e_noinputspecified );
339
	}
337
	}
340
	time(&systime); //òåêóùåå âðåìÿ
338
	time(&systime); //òåêóùåå âðåìÿ
341
	memcpy(&timeptr,localtime(&systime),sizeof(tm));
339
	memcpy(&timeptr,localtime(&systime),sizeof(tm));
342
	InitDefineConst();
340
	InitDefineConst();
343
	compile();
341
	compile();
344
	if(error==0)exit(e_ok);
342
	if(error==0)exit(e_ok);
345
	exit(e_someerrors);
343
	exit(e_someerrors);
346
	return 0;
344
	return 0;
347
}
345
}
348
 
346
 
349
void CheckExtenshions()
347
void CheckExtenshions()
350
{
348
{
351
int i;
349
int i;
352
	for(i=0;i
350
	for(i=0;i
353
		if(stricmp(rawext,extcompile[i])==0)break;
351
		if(stricmp(rawext,extcompile[i])==0)break;
354
	}
352
	}
355
	if(i==NUMEXT){
353
	if(i==NUMEXT){
356
	 	printf("Bad input file extension '%s'.",rawext);
354
	 	printf("Bad input file extension '%s'.",rawext);
357
	  exit(e_badinputfilename);
355
	  exit(e_badinputfilename);
358
	}
356
	}
359
}
357
}
360
 
358
 
361
void compile()
359
void compile()
362
{
360
{
363
long segments_required;
361
long segments_required;
364
union{
362
union{
365
	long longhold;
363
	long longhold;
366
	void *nextstr;
364
	void *nextstr;
367
};
365
};
368
//ñîçäàòü èìÿ ôàéëà ñ ïðåäóïðåæäåíèÿìè è åñëè îí åñòü óäàëèòü
366
//ñîçäàòü èìÿ ôàéëà ñ ïðåäóïðåæäåíèÿìè è åñëè îí åñòü óäàëèòü
369
	errfile.name=(char *)MALLOC(strlen(rawfilename)+5);
367
	errfile.name=(char *)MALLOC(strlen(rawfilename)+5);
370
	sprintf(errfile.name,"%s.err",rawfilename);
368
	sprintf(errfile.name,"%s.err",rawfilename);
371
	if(stat(errfile.name,(struct stat *)string2)==0)remove(errfile.name);
369
	if(stat(errfile.name,(struct stat *)string2)==0)remove(errfile.name);
372
//åñëè åñòü èìÿ ôàéëà äëÿ ïðåäóïðåæäåíèé ïðîâåðèòü åãî ñóùåñòâîâàíèå è óäàëèòü.
370
//åñëè åñòü èìÿ ôàéëà äëÿ ïðåäóïðåæäåíèé ïðîâåðèòü åãî ñóùåñòâîâàíèå è óäàëèòü.
373
	if(wartype.name!=NULL){
371
	if(wartype.name!=NULL){
374
		if(stat(wartype.name,(struct stat *)string2)==0)remove(wartype.name);
372
		if(stat(wartype.name,(struct stat *)string2)==0)remove(wartype.name);
375
	}
373
	}
376
	puts("Compiling Commenced . . .");
374
	puts("Compiling Commenced . . .");
377
	if(rawext!=NULL)sprintf((char *)string,"%s.%s",rawfilename,rawext);
375
	if(rawext!=NULL)sprintf((char *)string,"%s.%s",rawfilename,rawext);
378
	else{
376
	else{
379
		for(unsigned int i=0;i
377
		for(unsigned int i=0;i
380
			sprintf((char *)string,"%s.%s",rawfilename,extcompile[i]);
378
			sprintf((char *)string,"%s.%s",rawfilename,extcompile[i]);
381
			if(stat((char *)string,(struct stat *)string2)==0)break;
379
			if(stat((char *)string,(struct stat *)string2)==0)break;
382
		}
380
		}
383
	}
381
	}
384
	linenumber=0;
382
	linenumber=0;
385
	initregstat();
383
	initregstat();
386
#ifdef OPTVARCONST
384
#ifdef OPTVARCONST
387
	CreateMainLVIC();
385
	CreateMainLVIC();
388
#endif
386
#endif
389
#ifdef __NEWLEX__
387
#ifdef __NEWLEX__
390
	inittokn();
388
	inittokn();
391
#endif
389
#endif
392
	compilefile((char *)string,2); //ñîáñòâåííî ðàçáîðêà è êîìïèëÿöèÿ
390
	compilefile((char *)string,2); //ñîáñòâåííî ðàçáîðêà è êîìïèëÿöèÿ
393
	puts("Link . . .");
391
	puts("Link . . .");
394
	if(comfile==file_w32&&wbss==2){
392
	if(comfile==file_w32&&wbss==2){
395
		wbss=FALSE;
393
		wbss=FALSE;
396
		if(wconsole==FALSE)wbss=TRUE;
394
		if(wconsole==FALSE)wbss=TRUE;
397
	}
395
	}
398
	if(notdoneprestuff==TRUE)doprestuff();	//startup code
396
	if(notdoneprestuff==TRUE)doprestuff();	//startup code
399
	if(endifcount>=0)preerror("?endif expected before end of file");
397
	if(endifcount>=0)preerror("?endif expected before end of file");
400
	AddObj();
398
	AddObj();
401
	docalls();	//äîáàâèòü âíåøíèå ïðîöåäóðû
399
	docalls();	//äîáàâèòü âíåøíèå ïðîöåäóðû
402
	addinitvar();
400
	addinitvar();
403
	CheckUndefClassProc();
401
	CheckUndefClassProc();
404
	if(undefoffstart!=NULL){	//âûäàòü ñïèñîê íåèçâåñòíûõ ññûëîê
402
	if(undefoffstart!=NULL){	//âûäàòü ñïèñîê íåèçâåñòíûõ ññûëîê
405
		UNDEFOFF *curptr=undefoffstart;
403
		UNDEFOFF *curptr=undefoffstart;
406
		for(;;){
404
		for(;;){
407
			char holdstr[80];
405
			char holdstr[80];
408
			UNDEFOFF *ocurptr;
406
			UNDEFOFF *ocurptr;
409
			linenumber=curptr->pos->line;
407
			linenumber=curptr->pos->line;
410
			sprintf(holdstr,"\'%s\' offset undefined",curptr->name);
408
			sprintf(holdstr,"\'%s\' offset undefined",curptr->name);
411
			currentfileinfo=curptr->pos->file;
409
			currentfileinfo=curptr->pos->file;
412
			preerror(holdstr);
410
			preerror(holdstr);
413
			free(curptr->pos);
411
			free(curptr->pos);
414
			if(curptr->next==NULL)break;
412
			if(curptr->next==NULL)break;
415
			ocurptr=curptr->next;
413
			ocurptr=curptr->next;
416
			free(curptr);
414
			free(curptr);
417
			curptr=ocurptr;
415
			curptr=ocurptr;
418
		}
416
		}
419
		free(curptr);
417
		free(curptr);
420
	}
418
	}
421
	while(liststring!=NULL){
419
	while(liststring!=NULL){
422
		STRING_LIST *ins;
420
		STRING_LIST *ins;
423
		ins=(STRING_LIST *)liststring;
421
		ins=(STRING_LIST *)liststring;
424
		nextstr=ins->next;
422
		nextstr=ins->next;
425
		free(liststring);
423
		free(liststring);
426
		liststring=nextstr;
424
		liststring=nextstr;
427
	}
425
	}
428
	free(bufstr);
426
	free(bufstr);
429
	if(warning==TRUE&&wact[7].usewarn)WarnUnusedVar();//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
427
	if(warning==TRUE&&wact[7].usewarn)WarnUnusedVar();//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
430
	if(numstrtbl)CreatStrTabRes();	//çàâåðøèòü ñîçäàíèå ðåñóðñîâ
428
	if(numstrtbl)CreatStrTabRes();	//çàâåðøèòü ñîçäàíèå ðåñóðñîâ
431
	if(fobj==FALSE){
429
	if(fobj==FALSE){
432
		if(comfile==file_w32&&error==0){
430
		if(comfile==file_w32&&error==0){
433
			AddJmpApi();	//êîñâåííûå âûçîâû API
431
			AddJmpApi();	//êîñâåííûå âûçîâû API
434
			CreatWinStub();
432
			CreatWinStub();
435
		}
433
		}
436
		longhold=outptr;
434
		longhold=outptr;
437
		if(comfile==file_rom){
435
		if(comfile==file_rom){
438
			ooutptr=outptr;
436
			ooutptr=outptr;
439
			if(modelmem==SMALL){
437
			if(modelmem==SMALL){
440
				*(short *)&output[stackstartaddress]=(short)(((outptrdata+postsize+stacksize)/4+1)*4);
438
				*(short *)&output[stackstartaddress]=(short)(((outptrdata+postsize+stacksize)/4+1)*4);
441
				*(short *)&output[dataromstart]=(short)(outptr+4);
439
				*(short *)&output[dataromstart]=(short)(outptr+4);
442
				*(short *)&output[dataromsize]=(short)(outptrdata/2);
440
				*(short *)&output[dataromsize]=(short)(outptrdata/2);
443
//				printf("outptr=%d outptrdate=%d outptrsize=%d\n",outptr,outptrdata,outptrsize);
441
//				printf("outptr=%d outptrdate=%d outptrsize=%d\n",outptr,outptrdata,outptrsize);
444
				for(unsigned int i=0;i
442
				for(unsigned int i=0;i
445
			}
443
			}
446
			if(romsize==0){
444
			if(romsize==0){
447
				unsigned int i=outptr/1024;
445
				unsigned int i=outptr/1024;
448
				if((outptr%1024)!=0)i++;
446
				if((outptr%1024)!=0)i++;
449
				if(i>32)i=64;
447
				if(i>32)i=64;
450
				else if(i>16)i=32;
448
				else if(i>16)i=32;
451
				else if(i>8)i=16;
449
				else if(i>8)i=16;
452
				else if(i>4)i=8;
450
				else if(i>4)i=8;
453
				else if(i>2)i=4;
451
				else if(i>2)i=4;
454
		 		romsize=i*1024;
452
		 		romsize=i*1024;
455
				output[2]=(unsigned char)(romsize/512);
453
				output[2]=(unsigned char)(romsize/512);
456
			}
454
			}
457
			if(outptr>=romsize)preerror("The size of a code is more than the size of the ROM");
455
			if(outptr>=romsize)preerror("The size of a code is more than the size of the ROM");
458
			for(;outptr
456
			for(;outptr
459
			unsigned char summa=0;
457
			unsigned char summa=0;
460
			for(unsigned int i=0;i
458
			for(unsigned int i=0;i
461
			output[romsize-1]-=summa;
459
			output[romsize-1]-=summa;
462
			outptr=ooutptr;
460
			outptr=ooutptr;
463
		}
461
		}
464
		else if(modelmem==SMALL&&comfile==file_exe){ // if an EXE file
462
		else if(modelmem==SMALL&&comfile==file_exe){ // if an EXE file
465
			longhold+=AlignCD(CS,16);
463
			longhold+=AlignCD(CS,16);
466
//			if((outptr%16)!=0)outptr+=16-outptr%16;// paragraph align the end of the code seg
464
//			if((outptr%16)!=0)outptr+=16-outptr%16;// paragraph align the end of the code seg
467
			if(((long)outptrdata+(long)postsize+(long)stacksize)>65535L)
465
			if(((long)outptrdata+(long)postsize+(long)stacksize)>65535L)
468
					preerror("Data and stack total exceeds 64k");
466
					preerror("Data and stack total exceeds 64k");
469
		}
467
		}
470
		else if(comfile==file_sys){
468
		else if(comfile==file_sys){
471
			for(int i=0;i
469
			for(int i=0;i
472
				searchvar((listcom+i)->name);
470
				searchvar((listcom+i)->name);
473
				*(short *)&output[syscom+i*2]=(unsigned short)itok.number;
471
				*(short *)&output[syscom+i*2]=(unsigned short)itok.number;
474
			}
472
			}
475
			free(listcom);
473
			free(listcom);
476
		}
474
		}
477
		else longhold+=(long)postsize+(long)(stacksize);
475
		else longhold+=(long)postsize+(long)(stacksize);
478
		if(am32==0&&longhold>65535L&&!(modelmem==TINY&&(!resizemem)))preerror("Code, data and stack total exceeds 64k");
476
		if(am32==0&&longhold>65535L&&!(modelmem==TINY&&(!resizemem)))preerror("Code, data and stack total exceeds 64k");
479
		if(posts>0)doposts();  //Óñòàíîâèòü àäðåñà âûçîâîâ ïðîöåäóð è ïåðåõîäîâ
477
		if(posts>0)doposts();  //Óñòàíîâèòü àäðåñà âûçîâîâ ïðîöåäóð è ïåðåõîäîâ
480
		if(resizemem&&comfile==file_com){
478
		if(resizemem&&comfile==file_com){
481
			segments_required=(outptr+postsize+stacksize+15)/16;
479
			segments_required=(outptr+postsize+stacksize+15)/16;
482
			*(short *)&output[resizesizeaddress]=(short)segments_required;
480
			*(short *)&output[resizesizeaddress]=(short)segments_required;
483
			*(short *)&output[stackstartaddress]=(short)(segments_required*16);
481
			*(short *)&output[stackstartaddress]=(short)(segments_required*16);
484
		}
482
		}
485
	}
483
	}
486
	deinitregstat();
484
	deinitregstat();
487
#ifdef OPTVARCONST
485
#ifdef OPTVARCONST
488
	KillMainLVIC();
486
	KillMainLVIC();
489
#endif
487
#endif
490
//	puts("List Teg name:");
488
//	puts("List Teg name:");
491
//	PrintTegList(tegtree);
489
//	PrintTegList(tegtree);
492
	printf("COMPILING FINISHED.  Errors: %d\n",error);
490
	printf("COMPILING FINISHED.  Errors: %d\n",error);
493
	if(error==0){
491
	if(error==0){
494
		if(cpu>=1){
492
		if(cpu>=1){
495
			char m1[12];
493
			char m1[12];
496
			switch(cpu){
494
			switch(cpu){
497
				case 5:
495
				case 5:
498
					strcpy(m1,"Pentium");
496
					strcpy(m1,"Pentium");
499
					break;
497
					break;
500
				case 6:
498
				case 6:
501
					strcpy(m1,"MMX");
499
					strcpy(m1,"MMX");
502
					break;
500
					break;
503
				case 7:
501
				case 7:
504
					strcpy(m1,"Pentium II");
502
					strcpy(m1,"Pentium II");
505
					break;
503
					break;
506
				case 8:
504
				case 8:
507
					strcpy(m1,"Pentium III");
505
					strcpy(m1,"Pentium III");
508
					break;
506
					break;
509
				case 9:
507
				case 9:
510
					strcpy(m1,"Pentium IV");
508
					strcpy(m1,"Pentium IV");
511
					break;
509
					break;
512
				default: sprintf(m1,"80%d86",cpu);
510
				default: sprintf(m1,"80%d86",cpu);
513
			}
511
			}
514
			printf("CPU required: %s or greater.\n",m1);
512
			printf("CPU required: %s or greater.\n",m1);
515
		}
513
		}
516
		runfilesize=outptr-startptr;
514
		runfilesize=outptr-startptr;
517
		if(comfile==file_rom)runfilesize=romsize;
515
		if(comfile==file_rom)runfilesize=romsize;
518
		else if(modelmem==SMALL&&comfile==file_exe){
516
		else if(modelmem==SMALL&&comfile==file_exe){
519
			runfilesize+=outptrdata-startptrdata+0x20;
517
			runfilesize+=outptrdata-startptrdata+0x20;
520
			postsize+=postsize%2;
518
			postsize+=postsize%2;
521
			stacksize=(stacksize+15)/16*16;
519
			stacksize=(stacksize+15)/16*16;
522
		}
520
		}
523
		else if((comfile==file_exe||comfile==file_d32)&&modelmem==TINY)
521
		else if((comfile==file_exe||comfile==file_d32)&&modelmem==TINY)
524
				runfilesize+=0x20;
522
				runfilesize+=0x20;
525
		printmemsizes();
523
		printmemsizes();
526
		endinptr=outptr;
524
		endinptr=outptr;
527
		if(writeoutput()==0)printf("Run File Saved (%ld bytes).\n",runfilesize);
525
		if(writeoutput()==0)printf("Run File Saved (%ld bytes).\n",runfilesize);
528
		if(comfile==file_w32&&fobj==FALSE)printf("Created file of a format PE for Windows.\nFor alignment section code, added %u zero bytes.\n",filingzerope);
526
		if(comfile==file_w32&&fobj==FALSE)printf("Created file of a format PE for Windows.\nFor alignment section code, added %u zero bytes.\n",filingzerope);
529
//		else if(FILEALIGN&&fobj==FALSE)printf("For alignment file, added %u zero bytes.\n",filingzerope);
527
//		else if(FILEALIGN&&fobj==FALSE)printf("For alignment file, added %u zero bytes.\n",filingzerope);
530
	}
528
	}
531
		if(pdbg)DoTDS();
529
		if(pdbg)DoTDS();
532
}
530
}
533
 
531
 
534
void printmemsizes()
532
void printmemsizes()
535
{
533
{
536
long stacklong;
534
long stacklong;
537
unsigned int stackword;
535
unsigned int stackword;
538
unsigned int postword,codeword;
536
unsigned int postword,codeword;
539
	postword=postsize;
537
	postword=postsize;
540
	codeword=outptr-startptr;
538
	codeword=outptr-startptr;
541
	stackword=stacksize;
539
	stackword=stacksize;
542
	if(comfile==file_com||(comfile==file_exe&&modelmem==TINY)){
540
	if(comfile==file_com||(comfile==file_exe&&modelmem==TINY)){
543
		if(resizemem==0){
541
		if(resizemem==0){
544
			stacklong=0xFFFE - outptr - postsize;
542
			stacklong=0xFFFE - outptr - postsize;
545
			stackword=stacklong;
543
			stackword=stacklong;
546
		}
544
		}
547
		codeword=codeword-datasize-alignersize;
545
		codeword=codeword-datasize-alignersize;
548
	}
546
	}
549
	else if(comfile==file_sys)stackword=sysstack;
547
	else if(comfile==file_sys)stackword=sysstack;
550
	else if(comfile==file_exe||comfile==file_rom)datasize=outptrdata;
548
	else if(comfile==file_exe||comfile==file_rom)datasize=outptrdata;
551
	else if(comfile==file_d32)codeword-=datasize;
549
	else if(comfile==file_d32)codeword-=datasize;
552
	printf("Code: %u bytes, Data: %u bytes, Post: %u bytes, Stack: %u bytes\n"
550
	printf("Code: %u bytes, Data: %u bytes, Post: %u bytes, Stack: %u bytes\n"
553
			,codeword,datasize,postword,stackword);
551
			,codeword,datasize,postword,stackword);
554
	for(int i=0;i
552
	for(int i=0;i
555
		switch((postbuf+i)->type){
553
		switch((postbuf+i)->type){
556
			case CODE_SIZE:
554
			case CODE_SIZE:
557
				*(short *)&output[(postbuf+i)->loc]+=codeword;
555
				*(short *)&output[(postbuf+i)->loc]+=codeword;
558
				break;
556
				break;
559
			case CODE_SIZE32:
557
			case CODE_SIZE32:
560
				*(long *)&output[(postbuf+i)->loc]+=codeword;
558
				*(long *)&output[(postbuf+i)->loc]+=codeword;
561
				break;
559
				break;
562
			case DATA_SIZE:
560
			case DATA_SIZE:
563
				*(short *)&output[(postbuf+i)->loc]+=datasize;
561
				*(short *)&output[(postbuf+i)->loc]+=datasize;
564
				break;
562
				break;
565
			case DATA_SIZE32:
563
			case DATA_SIZE32:
566
				*(long *)&output[(postbuf+i)->loc]+=datasize;
564
				*(long *)&output[(postbuf+i)->loc]+=datasize;
567
				break;
565
				break;
568
			case POST_SIZE:
566
			case POST_SIZE:
569
				*(short *)&output[(postbuf+i)->loc]+=postword;
567
				*(short *)&output[(postbuf+i)->loc]+=postword;
570
				break;
568
				break;
571
			case POST_SIZE32:
569
			case POST_SIZE32:
572
				*(long *)&output[(postbuf+i)->loc]+=postword;
570
				*(long *)&output[(postbuf+i)->loc]+=postword;
573
				break;
571
				break;
574
			case STACK_SIZE:
572
			case STACK_SIZE:
575
				*(short *)&output[(postbuf+i)->loc]+=stackword;
573
				*(short *)&output[(postbuf+i)->loc]+=stackword;
576
				break;
574
				break;
577
			case STACK_SIZE32:
575
			case STACK_SIZE32:
578
				*(long *)&output[(postbuf+i)->loc]+=stackword;
576
				*(long *)&output[(postbuf+i)->loc]+=stackword;
579
				break;
577
				break;
580
		}
578
		}
581
	}
579
	}
582
}
580
}
583
 
581
 
584
void PrintInfo(char **str)
582
void PrintInfo(char **str)
585
{
583
{
586
	numstr=1;
584
	numstr=1;
587
	for(int i=0;str[i]!=NULL;i++){
585
	for(int i=0;str[i]!=NULL;i++){
588
		puts(str[i]);
586
		puts(str[i]);
589
//		CheckNumStr();
587
//		CheckNumStr();
590
	}
588
	}
591
}
589
}
592
 
590
 
593
/*void CheckNumStr()
591
/*void CheckNumStr()
594
{
592
{
595
#ifndef _UNIX_
593
#ifndef _UNIX_
596
	if(((numstr+1)%(scrsize-1))==0&&outfile!=0){
594
	if(((numstr+1)%(scrsize-1))==0&&outfile!=0){
597
		puts("Press any key...");
595
		puts("Press any key...");
598
		getch();
596
		getch();
599
	}
597
	}
600
	numstr++;
598
	numstr++;
601
#endif
599
#endif
602
} */
600
} */
603
 
601
 
604
void strbtrim(char *st)
602
void strbtrim(char *st)
605
{
603
{
606
int i;
604
int i;
607
char *p,*q;
605
char *p,*q;
608
	p=q=st;
606
	p=q=st;
609
	while(isspace(*p))p++;	//ïîêà íåçíà÷àùèå ñèìâîëû
607
	while(isspace(*p))p++;	//ïîêà íåçíà÷àùèå ñèìâîëû
610
	while(*p)*q++=*p++;     //ïåðåìåñòèòü ñòðîêó
608
	while(*p)*q++=*p++;     //ïåðåìåñòèòü ñòðîêó
611
	*q='\0';
609
	*q='\0';
612
	for(i=strlen(st)-1;isspace(st[i])&&i>=0;i--);
610
	for(i=strlen(st)-1;isspace(st[i])&&i>=0;i--);
613
	st[i+1]='\0';
611
	st[i+1]='\0';
614
}
612
}
615
 
613
 
616
unsigned long getnumber(unsigned char *buf)
614
unsigned long getnumber(unsigned char *buf)
617
{
615
{
618
int temp2;
616
int temp2;
619
unsigned long retnum;
617
unsigned long retnum;
620
unsigned char *oinput;
618
unsigned char *oinput;
621
unsigned int oinptr,oendinptr;
619
unsigned int oinptr,oendinptr;
622
	if(!isdigit(buf[0]))return 0;
620
	if(!isdigit(buf[0]))return 0;
623
	oinptr=inptr;
621
	oinptr=inptr;
624
	oinput=input;
622
	oinput=input;
625
	oendinptr=endinptr;
623
	oendinptr=endinptr;
626
	input=buf;
624
	input=buf;
627
	inptr=0;
625
	inptr=0;
628
	endinptr=256;
626
	endinptr=256;
629
	retnum=scannumber(&temp2);
627
	retnum=scannumber(&temp2);
630
	inptr=oinptr;
628
	inptr=oinptr;
631
	input=oinput;
629
	input=oinput;
632
	endinptr=oendinptr;
630
	endinptr=oendinptr;
633
	return retnum;
631
	return retnum;
634
}
632
}
635
 
633
 
636
void ParseObjCommand(int cmd){
634
void ParseObjCommand(int cmd){
637
	switch (cmd) {
635
	switch (cmd) {
638
	case c_sobj:
636
	case c_sobj:
639
		sobj = TRUE;
637
		sobj = TRUE;
640
		FixUp = TRUE;
638
		FixUp = TRUE;
641
		jumptomain = CALL_NONE;
639
		jumptomain = CALL_NONE;
642
	case c_obj:
640
	case c_obj:
643
		fobj = TRUE;
641
		fobj = TRUE;
644
		//					if(comfile==file_d32)FixUp=TRUE;
642
		//					if(comfile==file_d32)FixUp=TRUE;
645
		FastCallApi = FALSE;
643
		FastCallApi = FALSE;
646
	}
644
	}
647
}
645
}
648
 
646
 
649
int SelectComand(char *pptr,int *count)
647
int SelectComand(char *pptr,int *count)
650
{
648
{
651
int i;
649
int i;
652
unsigned char neg=FALSE;
650
unsigned char neg=FALSE;
653
char *ptr;
651
char *ptr;
654
int len;
652
int len;
655
	if((ptr=strchr(pptr,';'))!=NULL)*ptr=0;// èùåì êîììåíòàðèé îòñåêàåì âñå ïîñëå íåãî
653
	if((ptr=strchr(pptr,';'))!=NULL)*ptr=0;// èùåì êîììåíòàðèé îòñåêàåì âñå ïîñëå íåãî
656
        if((ptr=strchr(pptr,'='))!=NULL){ // èùåì çíàê ðàâåíñòâà
654
        if((ptr=strchr(pptr,'='))!=NULL){ // èùåì çíàê ðàâåíñòâà
657
		*ptr=0; // äåëèì
655
		*ptr=0; // äåëèì
658
		ptr++;
656
		ptr++;
659
	  strbtrim(ptr);	//óáðàòü ëèøíèå ïðîáåëû
657
	  strbtrim(ptr);	//óáðàòü ëèøíèå ïðîáåëû
660
	}
658
	}
661
  strbtrim(pptr);	//óáðàòü ëèøíèå ïðîáåëû
659
  strbtrim(pptr);	//óáðàòü ëèøíèå ïðîáåëû
662
	if(*pptr==0)return c_end+1;	//ïóñòàÿ ñòðîêà
660
	if(*pptr==0)return c_end+1;	//ïóñòàÿ ñòðîêà
663
	if((i=strlen(pptr))>1&&pptr[i-1]=='-'){
661
	if((i=strlen(pptr))>1&&pptr[i-1]=='-'){
664
		neg=TRUE;
662
		neg=TRUE;
665
		pptr[i-1]=0;
663
		pptr[i-1]=0;
666
	}
664
	}
667
	strupr(pptr);
665
	strupr(pptr);
668
	for(i=0;dir[i]!=NULL;i++){
666
	for(i=0;dir[i]!=NULL;i++){
669
		if(strcmp(dir[i],pptr)==0){
667
		if(strcmp(dir[i],pptr)==0){
670
			if((i<=c_endinfo)&&count==0){
668
			if((i<=c_endinfo)&&count==0){
671
				char buf[80];
669
				char buf[80];
672
				sprintf(buf,"Option '%s' is used only in command line",dir[i]);
670
				sprintf(buf,"Option '%s' is used only in command line",dir[i]);
673
				preerror(buf);
671
				preerror(buf);
674
				return i;
672
				return i;
675
			}
673
			}
676
			if(i<=c_endstart&¬doneprestuff!=TRUE){
674
			if(i<=c_endstart&¬doneprestuff!=TRUE){
677
errlate:
675
errlate:
678
				char buf[80];
676
				char buf[80];
679
				sprintf(buf,"Too late used '#pragma option %s'",dir[i]);
677
				sprintf(buf,"Too late used '#pragma option %s'",dir[i]);
680
				preerror(buf);
678
				preerror(buf);
681
				return i;
679
				return i;
682
			}
680
			}
683
			switch(i){
681
			switch(i){
684
				case c_j0: jumptomain=(unsigned char)(neg!=FALSE?CALL_NEAR:CALL_NONE); header=(unsigned char)0^neg; break;
682
				case c_j0: jumptomain=(unsigned char)(neg!=FALSE?CALL_NEAR:CALL_NONE); header=(unsigned char)0^neg; break;
685
				case c_j1: jumptomain=(unsigned char)CALL_SHORT; header=(unsigned char)1; break;
683
				case c_j1: jumptomain=(unsigned char)CALL_SHORT; header=(unsigned char)1; break;
686
				case c_j2: jumptomain=(unsigned char)(neg==FALSE?CALL_NEAR:CALL_NONE); header=(unsigned char)1^neg; break;
684
				case c_j2: jumptomain=(unsigned char)(neg==FALSE?CALL_NEAR:CALL_NONE); header=(unsigned char)1^neg; break;
687
				case c_ctrlc: killctrlc=(unsigned char)1^neg; break;
685
				case c_ctrlc: killctrlc=(unsigned char)1^neg; break;
688
				case c_os: optimizespeed=(unsigned char)1^neg; break;
686
				case c_os: optimizespeed=(unsigned char)1^neg; break;
689
				case c_oc: optimizespeed=(unsigned char)0^neg; break;
687
				case c_oc: optimizespeed=(unsigned char)0^neg; break;
690
				case c_r: resizemem=(unsigned char)1^neg; break;
688
				case c_r: resizemem=(unsigned char)1^neg; break;
691
				case c_p: parsecommandline=(unsigned char)1^neg; break;
689
				case c_p: parsecommandline=(unsigned char)1^neg; break;
692
				case c_a: alignword=(unsigned char)1^neg; break;
690
				case c_a: alignword=(unsigned char)1^neg; break;
693
				case c_sym:
691
				case c_sym:
694
					startptr=0x100;
692
					startptr=0x100;
695
					comsymbios=TRUE;
693
					comsymbios=TRUE;
696
					*count=*count+1;
694
					*count=*count+1;
697
          startsymbiosys(_Argv[*count]);
695
          startsymbiosys(_Argv[*count]);
698
					break;
696
					break;
699
				case c_0: chip=0; break;
697
				case c_0: chip=0; break;
700
				case c_1: chip=1; break;
698
				case c_1: chip=1; break;
701
				case c_2: chip=2; break;
699
				case c_2: chip=2; break;
702
				case c_3: chip=3; break;
700
				case c_3: chip=3; break;
703
				case c_4: chip=4; break;
701
				case c_4: chip=4; break;
704
				case c_5: chip=5; break;
702
				case c_5: chip=5; break;
705
				case c_6: chip=6; break;	//MMX
703
				case c_6: chip=6; break;	//MMX
706
				case c_7: chip=7; break;  //Pro
704
				case c_7: chip=7; break;  //Pro
707
				case c_8: chip=8; break;  //PII
705
				case c_8: chip=8; break;  //PII
708
				case c_9: chip=9; break;  //PIII
706
				case c_9: chip=9; break;  //PIII
709
				case c_x: header=(unsigned char)0^neg; break;
707
				case c_x: header=(unsigned char)0^neg; break;
710
				case c_exe:
708
				case c_exe:
711
					comfile=file_exe;
709
					comfile=file_exe;
712
					modelmem=SMALL;
710
					modelmem=SMALL;
713
					splitdata=TRUE;
711
					splitdata=TRUE;
714
					GetMemExeDat();
712
					GetMemExeDat();
715
					if(extflag) strcpy(outext,"exe");
713
					if(extflag) strcpy(outext,"exe");
716
					startptr=0; 			// start address
714
					startptr=0; 			// start address
717
					startptrdata=0; 	// data start address
715
					startptrdata=0; 	// data start address
718
					dos1=2;
716
					dos1=2;
719
					dos2=0;
717
					dos2=0;
720
					break;
718
					break;
721
				case c_sys:
719
				case c_sys:
722
					comfile=file_sys;
720
					comfile=file_sys;
723
					if(extflag) strcpy(outext,"sys");
721
					if(extflag) strcpy(outext,"sys");
724
					startptr=0; 		// start address
722
					startptr=0; 		// start address
725
					startptrdata=0; 	// data start address
723
					startptrdata=0; 	// data start address
726
					jumptomain=CALL_NONE;
724
					jumptomain=CALL_NONE;
727
					header=0;
725
					header=0;
728
					break;
726
					break;
729
				case c_sobj:
727
				case c_sobj:
730
/*					sobj=TRUE;
728
/*					sobj=TRUE;
731
					FixUp=TRUE;
729
					FixUp=TRUE;
732
					jumptomain=CALL_NONE;
730
					jumptomain=CALL_NONE;
733
*/			case c_obj:
731
*/			case c_obj:
734
/*					fobj=TRUE;
732
/*					fobj=TRUE;
735
//					if(comfile==file_d32)FixUp=TRUE;
733
//					if(comfile==file_d32)FixUp=TRUE;
736
					FastCallApi=FALSE;
734
					FastCallApi=FALSE;
737
*/
735
*/
738
          ParseObjCommand(i);
736
          ParseObjCommand(i);
739
					break;
737
					break;
740
				case c_me:
738
				case c_me:
741
					puts(meinfo);
739
					puts(meinfo);
742
					exit( e_ok );
740
					exit( e_ok );
743
				case c_key:
741
				case c_key:
744
					int j,jj;
742
					int j,jj;
745
					puts("LIST OF RESERVED IDENTIFIERS:");
743
					puts("LIST OF RESERVED IDENTIFIERS:");
746
					numstr=1;
744
					numstr=1;
747
					ListId(53,(unsigned char *)id,idofs);
745
					ListId(53,(unsigned char *)id,idofs);
748
					for(j=0;j
746
					for(j=0;j
749
						puts(id2[j]);
747
						puts(id2[j]);
750
//						CheckNumStr();
748
//						CheckNumStr();
751
					}
749
					}
752
					for(jj=0;jj<2;jj++){
750
					for(jj=0;jj<2;jj++){
753
						for(j=0;j<8;j++)printf("%s ",regs[jj][j]);
751
						for(j=0;j<8;j++)printf("%s ",regs[jj][j]);
754
						puts("");
752
						puts("");
755
//						CheckNumStr();
753
//						CheckNumStr();
756
					}
754
					}
757
					for(j=0;j<8;j++)printf("%s ",begs[j]);
755
					for(j=0;j<8;j++)printf("%s ",begs[j]);
758
					puts("");
756
					puts("");
759
//					CheckNumStr();
757
//					CheckNumStr();
760
					for(j=0;j<6;j++)printf("%s ",segs[j]);
758
					for(j=0;j<6;j++)printf("%s ",segs[j]);
761
					print8item("ST(%d) ");
759
					print8item("ST(%d) ");
762
					puts("ST");
760
					puts("ST");
763
					print8item("st(%d) ");
761
					print8item("st(%d) ");
764
					puts("st");
762
					puts("st");
765
					exit(e_ok);
763
					exit(e_ok);
766
				case c_lasm:
764
				case c_lasm:
767
					puts("LIST OF SUPPORTED ASSEMBLER INSTRUCTIONS:");
765
					puts("LIST OF SUPPORTED ASSEMBLER INSTRUCTIONS:");
768
					numstr=1;
766
					numstr=1;
769
					ListId(26,asmMnem,ofsmnem);
767
					ListId(26,asmMnem,ofsmnem);
770
					exit(e_ok);
768
					exit(e_ok);
771
				case c_s:
769
				case c_s:
772
					if(ptr==NULL)return c_end;
770
					if(ptr==NULL)return c_end;
773
					if((stacksize=getnumber((unsigned char *)ptr))==0){
771
					if((stacksize=getnumber((unsigned char *)ptr))==0){
774
						puts("Bad stack size.");
772
						puts("Bad stack size.");
775
						exit(e_unknowncommandline);
773
						exit(e_unknowncommandline);
776
					}
774
					}
777
					stacksize=Align(stacksize,4);
775
					stacksize=Align(stacksize,4);
778
					break;
776
					break;
779
				case c_w:
777
				case c_w:
780
					gwarning=(unsigned char)TRUE^neg;
778
					gwarning=(unsigned char)TRUE^neg;
781
					break;
779
					break;
782
				case c_wf:
780
				case c_wf:
783
					if(wartype.name)free(wartype.name);
781
					if(wartype.name)free(wartype.name);
784
					wartype.name=BackString(ptr);
782
					wartype.name=BackString(ptr);
785
					break;
783
					break;
786
				case c_de:
784
				case c_de:
787
					divexpand=(unsigned char)TRUE^neg;
785
					divexpand=(unsigned char)TRUE^neg;
788
					break;
786
					break;
789
				case c_opnum:
787
				case c_opnum:
790
					optnumber=(unsigned char)TRUE^neg;
788
					optnumber=(unsigned char)TRUE^neg;
791
					break;
789
					break;
792
				case c_ip:
790
				case c_ip:
793
					IncludePath(ptr);
791
					IncludePath(ptr);
794
					break;
792
					break;
795
				case c_arg:
793
				case c_arg:
796
					parsecommandline=(unsigned char)TRUE^neg;
794
					parsecommandline=(unsigned char)TRUE^neg;
797
					fargc=(unsigned char)TRUE^neg;
795
					fargc=(unsigned char)TRUE^neg;
798
					break;
796
					break;
799
				case c_texe:
797
				case c_texe:
800
					if(extflag) strcpy(outext,"exe");
798
					if(extflag) strcpy(outext,"exe");
801
					comfile=file_exe;
799
					comfile=file_exe;
802
					break;
800
					break;
803
				case c_rom:
801
				case c_rom:
804
					if(extflag) strcpy(outext,"rom");
802
					if(extflag) strcpy(outext,"rom");
805
					comfile=file_rom;
803
					comfile=file_rom;
806
					startptr=0;
804
					startptr=0;
807
					startptrdata=0; 	// data start address
805
					startptrdata=0; 	// data start address
808
					GetMemExeDat();
806
					GetMemExeDat();
809
					break;
807
					break;
810
				case c_dll:
808
				case c_dll:
811
					wconsole=TRUE;
809
					wconsole=TRUE;
812
					dllflag=TRUE;
810
					dllflag=TRUE;
813
					if(extflag) strcpy(outext,"dll");
811
					if(extflag) strcpy(outext,"dll");
814
					comfile=file_w32;
812
					comfile=file_w32;
815
					FixUpTable=TRUE;
813
					FixUpTable=TRUE;
816
					goto nexpardll;
814
					goto nexpardll;
817
 
815
 
818
/*					FixUp=TRUE;
816
/*					FixUp=TRUE;
819
					startptrdata=startptr=0;
817
					startptrdata=startptr=0;
820
					am32=TRUE;
818
					am32=TRUE;
821
					if(chip<3)chip=3;
819
					if(chip<3)chip=3;
822
					if(FILEALIGN==0)FILEALIGN=512;
820
					if(FILEALIGN==0)FILEALIGN=512;
823
					break;*/
821
					break;*/
824
				case c_w32c:
822
				case c_w32c:
825
					wconsole=TRUE;
823
					wconsole=TRUE;
826
					goto init_w32;
824
					goto init_w32;
827
				case c_w32:
825
				case c_w32:
828
					wconsole=FALSE;
826
					wconsole=FALSE;
829
					dllflag=FALSE;
827
					dllflag=FALSE;
830
init_w32:
828
init_w32:
831
					comfile=file_w32;
829
					comfile=file_w32;
832
					goto nexpar;
830
					goto nexpar;
833
				case c_d32:
831
				case c_d32:
834
					comfile=file_d32;
832
					comfile=file_d32;
835
nexpar:
833
nexpar:
836
					if(extflag) strcpy(outext,"exe");
834
					if(extflag) strcpy(outext,"exe");
837
nexpardll:
835
nexpardll:
838
					FixUp=TRUE;
836
					FixUp=TRUE;
839
					startptrdata=startptr=0;
837
					startptrdata=startptr=0;
840
					am32=TRUE;
838
					am32=TRUE;
841
					if(chip<3)chip=3;
839
					if(chip<3)chip=3;
842
					if(FILEALIGN==0)FILEALIGN=512;
840
					if(FILEALIGN==0)FILEALIGN=512;
843
					break;
841
					break;
844
				case c_meos:
842
				case c_meos:
845
					comfile=file_meos;
843
					comfile=file_meos;
846
					am32=TRUE;
844
					am32=TRUE;
847
					startptrdata=startptr=0;
845
					startptrdata=startptr=0;
848
					if(extflag) strcpy(outext,"");
846
					if(extflag) strcpy(outext,"");
849
					if(chip<3)chip=3;
847
					if(chip<3)chip=3;
850
					break;
848
					break;
851
				case c_b32:
849
				case c_b32:
852
					comfile=file_bin;
850
					comfile=file_bin;
853
					am32=TRUE;
851
					am32=TRUE;
854
					startptrdata=startptr=0;
852
					startptrdata=startptr=0;
855
					if(extflag) strcpy(outext,"bin");
853
					if(extflag) strcpy(outext,"bin");
856
					FixUp=TRUE;
854
					FixUp=TRUE;
857
					ImageBase=0;
855
					ImageBase=0;
858
					if(chip<3)chip=3;
856
					if(chip<3)chip=3;
859
					break;
857
					break;
860
				case c_stub:
858
				case c_stub:
861
					if(stubfile)free(stubfile);
859
					if(stubfile)free(stubfile);
862
					stubfile=BackString(ptr);
860
					stubfile=BackString(ptr);
863
					dpmistub=FALSE;
861
					dpmistub=FALSE;
864
					if(stricmp(stubfile,"dpmi")==0){
862
					if(stricmp(stubfile,"dpmi")==0){
865
						if(notdoneprestuff!=TRUE)goto errlate;
863
						if(notdoneprestuff!=TRUE)goto errlate;
866
						dpmistub=TRUE;
864
						dpmistub=TRUE;
867
						usestub=FALSE;
865
						usestub=FALSE;
868
					}
866
					}
869
					break;
867
					break;
870
				case c_ns:
868
				case c_ns:
871
					usestub=(unsigned char)0^neg;
869
					usestub=(unsigned char)0^neg;
872
					break;
870
					break;
873
				case c_ap:
871
				case c_ap:
874
					AlignProc=(unsigned char)1^neg;
872
					AlignProc=(unsigned char)1^neg;
875
					if(ptr!=NULL){
873
					if(ptr!=NULL){
876
						alignproc=getnumber((unsigned char *)ptr);
874
						alignproc=getnumber((unsigned char *)ptr);
877
						if(alignproc<1||alignproc>4096)alignproc=8;
875
						if(alignproc<1||alignproc>4096)alignproc=8;
878
					}
876
					}
879
					break;
877
					break;
880
				case c_define:
878
				case c_define:
881
					addconsttotree(ptr,TRUE);
879
					addconsttotree(ptr,TRUE);
882
					break;
880
					break;
883
				case c_ost:
881
				case c_ost:
884
					optstr=(unsigned char)TRUE^neg;
882
					optstr=(unsigned char)TRUE^neg;
885
					break;
883
					break;
886
				case c_cri:
884
				case c_cri:
887
					crif=(unsigned char)1^neg;
885
					crif=(unsigned char)1^neg;
888
					break;
886
					break;
889
				case c_ia:
887
				case c_ia:
890
					idasm=(unsigned char)1^neg;
888
					idasm=(unsigned char)1^neg;
891
					break;
889
					break;
892
				case c_dbg:
890
				case c_dbg:
893
					dbg&=0xFE;
891
					dbg&=0xFE;
894
					char c;
892
					char c;
895
					c=(unsigned char)1^neg;
893
					c=(unsigned char)1^neg;
896
					dbg|=c;
894
					dbg|=c;
897
					if(!neg)InitDbg();
895
					if(!neg)InitDbg();
898
					break;
896
					break;
899
				case c_scd:
897
				case c_scd:
900
/*-----------------13.08.00 23:01-------------------
898
/*-----------------13.08.00 23:01-------------------
901
 áóäåò ââåäåíà ïîñëå äîðàáîòêè äèíàìè÷åñêèõ ïðîöåäóð
899
 áóäåò ââåäåíà ïîñëå äîðàáîòêè äèíàìè÷åñêèõ ïðîöåäóð
902
	--------------------------------------------------*/
900
	--------------------------------------------------*/
903
					splitdata=(unsigned char)1^neg;
901
					splitdata=(unsigned char)1^neg;
904
					if(modelmem==SMALL)splitdata=TRUE;
902
					if(modelmem==SMALL)splitdata=TRUE;
905
					break;
903
					break;
906
				case c_al:
904
				case c_al:
907
					if(ptr==NULL)return c_end;
905
					if(ptr==NULL)return c_end;
908
					aligner=(unsigned char)getnumber((unsigned char *)ptr);
906
					aligner=(unsigned char)getnumber((unsigned char *)ptr);
909
					break;
907
					break;
910
				case c_at:
908
				case c_at:
911
					atex=(unsigned char)1^neg;
909
					atex=(unsigned char)1^neg;
912
					break;
910
					break;
913
				case c_wfa:
911
				case c_wfa:
914
					FastCallApi=(unsigned char)1^neg;
912
					FastCallApi=(unsigned char)1^neg;
915
					break;
913
					break;
916
				case c_wfu:
914
				case c_wfu:
917
					FixUpTable=(unsigned char)1^neg;
915
					FixUpTable=(unsigned char)1^neg;
918
					break;
916
					break;
919
				case c_wib:
917
				case c_wib:
920
					if(ptr==NULL)return c_end;
918
					if(ptr==NULL)return c_end;
921
					ImageBase=getnumber((unsigned char *)ptr);
919
					ImageBase=getnumber((unsigned char *)ptr);
922
					break;
920
					break;
923
				case c_iv:
921
				case c_iv:
924
					notpost=(unsigned char)1^neg;
922
					notpost=(unsigned char)1^neg;
925
					break;
923
					break;
926
				case c_mer:
924
				case c_mer:
927
					if(ptr==NULL)return c_end;
925
					if(ptr==NULL)return c_end;
928
					if((maxerrors=getnumber((unsigned char *)ptr))==0)maxerrors=16;
926
					if((maxerrors=getnumber((unsigned char *)ptr))==0)maxerrors=16;
929
					break;
927
					break;
930
				case c_sa:
928
				case c_sa:
931
					if(ptr==NULL)return c_end;
929
					if(ptr==NULL)return c_end;
932
					startptrdata=startptr=getnumber((unsigned char *)ptr);
930
					startptrdata=startptr=getnumber((unsigned char *)ptr);
933
					break;
931
					break;
934
				case c_stm:
932
				case c_stm:
935
					startuptomain=(unsigned char)1^neg;
933
					startuptomain=(unsigned char)1^neg;
936
					break;
934
					break;
937
				case c_suv:
935
				case c_suv:
938
					if(ptr==NULL)return c_end;
936
					if(ptr==NULL)return c_end;
939
					startStartup=getnumber((unsigned char *)ptr);
937
					startStartup=getnumber((unsigned char *)ptr);
940
					break;
938
					break;
941
				case c_wmb:
939
				case c_wmb:
942
					WinMonoBlock=(unsigned char)1^neg;
940
					WinMonoBlock=(unsigned char)1^neg;
943
					break;
941
					break;
944
				case c_ust:
942
				case c_ust:
945
					useStartup=(unsigned char)1^neg;
943
					useStartup=(unsigned char)1^neg;
946
					break;
944
					break;
947
				case c_help:
945
				case c_help:
948
				case c_h:
946
				case c_h:
949
				case c_hh:
947
				case c_hh:
950
					PrintInfo((char **)usage);
948
					PrintInfo((char **)usage);
951
					exit(e_ok);
949
					exit(e_ok);
952
				case c_mif:
950
				case c_mif:
953
					if(ptr==NULL)return c_end;
951
					if(ptr==NULL)return c_end;
954
					if(rawfilename!=NULL){
952
					if(rawfilename!=NULL){
955
						free(rawfilename);
953
						free(rawfilename);
956
						rawfilename=NULL;
954
						rawfilename=NULL;
957
					}
955
					}
958
					if(rawext!=NULL){
956
					if(rawext!=NULL){
959
						free(rawext);
957
						free(rawext);
960
						rawext=NULL;
958
						rawext=NULL;
961
					}
959
					}
962
					char *temp;
960
					char *temp;
963
        	if((temp=strrchr(ptr,'.'))!=NULL){
961
        	if((temp=strrchr(ptr,'.'))!=NULL){
964
						*temp++=0;
962
						*temp++=0;
965
						rawext=BackString(temp);
963
						rawext=BackString(temp);
966
						CheckExtenshions();
964
						CheckExtenshions();
967
 	  	    }
965
 	  	    }
968
					rawfilename=BackString(ptr);
966
					rawfilename=BackString(ptr);
969
					break;
967
					break;
970
				case c_ac:
968
				case c_ac:
971
					AlignCycle=(unsigned char)1^neg;
969
					AlignCycle=(unsigned char)1^neg;
972
					if(ptr!=NULL){
970
					if(ptr!=NULL){
973
						aligncycle=getnumber((unsigned char *)ptr);
971
						aligncycle=getnumber((unsigned char *)ptr);
974
						if(aligncycle<1&&aligncycle>4096)aligncycle=8;
972
						if(aligncycle<1&&aligncycle>4096)aligncycle=8;
975
					}
973
					}
976
					break;
974
					break;
977
				case c_ws:	//dos-stub for windows programs
975
				case c_ws:	//dos-stub for windows programs
978
					if(winstub)free(winstub);
976
					if(winstub)free(winstub);
979
					winstub=BackString(ptr);
977
					winstub=BackString(ptr);
980
					break;
978
					break;
981
				case c_ind:
979
				case c_ind:
982
					ImportName(ptr);
980
					ImportName(ptr);
983
					break;
981
					break;
984
				case c_wbss:
982
				case c_wbss:
985
					wbss=(unsigned char)1^neg;
983
					wbss=(unsigned char)1^neg;
986
					break;
984
					break;
987
				case c_wo:
985
				case c_wo:
988
					useordinal=(unsigned char)1^neg;
986
					useordinal=(unsigned char)1^neg;
989
					break;
987
					break;
990
				case c_nw:
988
				case c_nw:
991
					if(ptr==NULL)return c_end;
989
					if(ptr==NULL)return c_end;
992
					len=getnumber((unsigned char *)ptr);
990
					len=getnumber((unsigned char *)ptr);
993
					if(len>0&&len<=WARNCOUNT)wact[len-1].usewarn=(unsigned char)0^neg;
991
					if(len>0&&len<=WARNCOUNT)wact[len-1].usewarn=(unsigned char)0^neg;
994
					break;
992
					break;
995
				case c_we:
993
				case c_we:
996
					if(ptr==NULL)return c_end;
994
					if(ptr==NULL)return c_end;
997
					len=getnumber((unsigned char *)ptr);
995
					len=getnumber((unsigned char *)ptr);
998
					if(len>0&&len<=WARNCOUNT){
996
					if(len>0&&len<=WARNCOUNT){
999
						if(neg)wact[len-1].fwarn=warningprint;
997
						if(neg)wact[len-1].fwarn=warningprint;
1000
						else wact[len-1].fwarn=preerror3;
998
						else wact[len-1].fwarn=preerror3;
1001
					}
999
					}
1002
					break;
1000
					break;
1003
				case c_lst:
1001
				case c_lst:
1004
					SetLST(neg);
1002
					SetLST(neg);
1005
					break;
1003
					break;
1006
				case c_d4g:
1004
				case c_d4g:
1007
					useDOS4GW=(unsigned char)1^neg;
1005
					useDOS4GW=(unsigned char)1^neg;
1008
					break;
1006
					break;
1009
				case c_env:
1007
				case c_env:
1010
					use_env=(unsigned char)1^neg;
1008
					use_env=(unsigned char)1^neg;
1011
					break;
1009
					break;
1012
				case c_cpa:
1010
				case c_cpa:
1013
					clearpost=(unsigned char)1^neg;
1011
					clearpost=(unsigned char)1^neg;
1014
					break;
1012
					break;
1015
				case c_ul:
1013
				case c_ul:
1016
					uselea=(unsigned char)1^neg;
1014
					uselea=(unsigned char)1^neg;
1017
					break;
1015
					break;
1018
				case c_as:
1016
				case c_as:
1019
					if(ptr){
1017
					if(ptr){
1020
						len=getnumber((unsigned char *)ptr);
1018
						len=getnumber((unsigned char *)ptr);
1021
						if(caselong(len)!=NUMNUM)strpackdef=len;
1019
						if(caselong(len)!=NUMNUM)strpackdef=len;
1022
					}
1020
					}
1023
					else strpackdef=(neg==FALSE?8:1);
1021
					else strpackdef=(neg==FALSE?8:1);
1024
					strpackcur=strpackdef;
1022
					strpackcur=strpackdef;
1025
					break;
1023
					break;
1026
				case c_lrs:
1024
				case c_lrs:
1027
					regoverstack=(unsigned char)1^neg;
1025
					regoverstack=(unsigned char)1^neg;
1028
					break;
1026
					break;
1029
				case c_wsi:
1027
				case c_wsi:
1030
					shortimport=(unsigned char)1^neg;
1028
					shortimport=(unsigned char)1^neg;
1031
					break;
1029
					break;
1032
				case c_waf:
1030
				case c_waf:
1033
					if(ptr!=NULL){
1031
					if(ptr!=NULL){
1034
						FILEALIGN=Align(getnumber((unsigned char *)ptr),16);
1032
						FILEALIGN=Align(getnumber((unsigned char *)ptr),16);
1035
					}
1033
					}
1036
					break;
1034
					break;
1037
				case c_sf:
1035
				case c_sf:
1038
					if(ptr==NULL)return c_end;
1036
					if(ptr==NULL)return c_end;
1039
					namestartupfile=BackString(ptr);
1037
					namestartupfile=BackString(ptr);
1040
					break;
1038
					break;
1041
				case c_oir:
1039
				case c_oir:
1042
					optinitreg=(unsigned char)1^neg;
1040
					optinitreg=(unsigned char)1^neg;
1043
					break;
1041
					break;
1044
				case c_coff:
1042
				case c_coff:
1045
					ocoff=(unsigned char)1^neg;
1043
					ocoff=(unsigned char)1^neg;
1046
					break;
1044
					break;
1047
				case c_js:
1045
				case c_js:
1048
					addstack=(unsigned char)1^neg;
1046
					addstack=(unsigned char)1^neg;
1049
					if(addstack==0)RestoreStack();
1047
					if(addstack==0)RestoreStack();
1050
					break;
1048
					break;
1051
				case c_ba:
1049
				case c_ba:
1052
					bytesize=(unsigned char)1^neg;
1050
					bytesize=(unsigned char)1^neg;
1053
					break;
1051
					break;
1054
				case c_asp:
1052
				case c_asp:
1055
					if(blockproc)goto errlate;
1053
					if(blockproc)goto errlate;
1056
					else ESPloc=(unsigned char)1^neg;
1054
					else ESPloc=(unsigned char)1^neg;
1057
					break;
1055
					break;
1058
#ifdef OPTVARCONST
1056
#ifdef OPTVARCONST
1059
				case c_orv:
1057
				case c_orv:
1060
					replasevar=(unsigned char)1^neg;
1058
					replasevar=(unsigned char)1^neg;
1061
					if(replasevar&&listvic)ClearLVIC();
1059
					if(replasevar&&listvic)ClearLVIC();
1062
					break;
1060
					break;
1063
				case c_map:
1061
				case c_map:
1064
					mapfile=(unsigned char)1^neg;
1062
					mapfile=(unsigned char)1^neg;
1065
					break;
1063
					break;
1066
#endif
1064
#endif
1067
				case c_ext:     //***lev***
1065
				case c_ext:     //***lev***
1068
					strcpy(outext,BackString(ptr)); //***lev***
1066
					strcpy(outext,BackString(ptr)); //***lev***
1069
					extflag=FALSE; //÷òîáû ðàñøèðåíèå íå ïåðåçàáèâàëîñü äðóãèìè êëþ÷àìè, åñëè îíè èäóò ïîçæå
1067
					extflag=FALSE; //÷òîáû ðàñøèðåíèå íå ïåðåçàáèâàëîñü äðóãèìè êëþ÷àìè, åñëè îíè èäóò ïîçæå
1070
					break;  //***lev***
1068
					break;  //***lev***
1071
			}
1069
			}
1072
			break;
1070
			break;
1073
		}
1071
		}
1074
	}
1072
	}
1075
	return i;
1073
	return i;
1076
}
1074
}
1077
 
1075
 
1078
void SetLST(unsigned char neg)
1076
void SetLST(unsigned char neg)
1079
{
1077
{
1080
	if(((dbg&2)>>1)==neg){
1078
	if(((dbg&2)>>1)==neg){
1081
		dbg&=0xFD;
1079
		dbg&=0xFD;
1082
		unsigned char c=(unsigned char)((1^neg)<<1);
1080
		unsigned char c=(unsigned char)((1^neg)<<1);
1083
		dbg|=c;
1081
		dbg|=c;
1084
		if(neg){
1082
		if(neg){
1085
			if((dbg&0xFE)==0)dbgact=TRUE;
1083
			if((dbg&0xFE)==0)dbgact=TRUE;
1086
			AddEndLine();
1084
			AddEndLine();
1087
		}
1085
		}
1088
		else{
1086
		else{
1089
			InitDbg();
1087
			InitDbg();
1090
			if(notdoneprestuff!=TRUE)dbgact=FALSE;	//startup cod
1088
			if(notdoneprestuff!=TRUE)dbgact=FALSE;	//startup cod
1091
		}
1089
		}
1092
	}
1090
	}
1093
}
1091
}
1094
 
1092
 
1095
void print8item(char *str)
1093
void print8item(char *str)
1096
{
1094
{
1097
//	CheckNumStr();
1095
//	CheckNumStr();
1098
	for(int j=0;j<8;j++)printf(str,j);
1096
	for(int j=0;j<8;j++)printf(str,j);
1099
	puts("");
1097
	puts("");
1100
}
1098
}
1101
 
1099
 
1102
 
1100
 
1103
 
1101
 
1104
 
1102
 
1105
void _loadIni(FILE *inih)
1103
void _loadIni(FILE *inih)
1106
{
1104
{
1107
	char m1[256];
1105
	char m1[256];
1108
	for(;;){
1106
	for(;;){
1109
		if(fgets(m1,255,inih)==NULL)break;
1107
		if(fgets(m1,255,inih)==NULL)break;
1110
		if(SelectComand(m1,0)==c_end)BadCommandLine(m1);
1108
		if(SelectComand(m1,0)==c_end)BadCommandLine(m1);
1111
	}
1109
	}
1112
	fclose(inih);
1110
	fclose(inih);
1113
}
1111
}
1114
 
1112
 
1115
void LoadIni(char *name)
1113
void LoadIni(char *name)
1116
{
1114
{
1117
FILE *inih;
1115
FILE *inih;
1118
char m1[256];
1116
char m1[256];
1119
 
1117
 
1120
							// load name
1118
							// load name
1121
	if (inih = fopen(name,"rb"))
1119
	if (inih = fopen(name,"rb"))
1122
	{_loadIni(inih);return;}
1120
	{_loadIni(inih);return;}
1123
	
1121
	
1124
	if(strcmp(name,"c--.ini")!=0)
1122
	if(strcmp(name,"c--.ini")!=0)
1125
			return;
1123
			return;
1126
 
1124
 
1127
							//load findpath[0]\c--.ini
1125
							//load findpath[0]\c--.ini
1128
	if (findpath[0]!=0)
1126
	if (findpath[0]!=0)
1129
	{
1127
	{
1130
		sprintf(m1,"%s%s",findpath[0],name);
1128
		sprintf(m1,"%s%s",findpath[0],name);
1131
		if (inih = fopen(m1,"rb"))
1129
		if (inih = fopen(m1,"rb"))
1132
		{_loadIni(inih);return;}
1130
		{_loadIni(inih);return;}
1133
	}
1131
	}
1134
							//load PATH[i=0..end]/c--.ini
1132
							//load PATH[i=0..end]/c--.ini
1135
	char* pth = getenv("PATH");	
1133
	char* pth = getenv("PATH");	
1136
	if (pth != 0)
1134
	if (pth != 0)
1137
	{
1135
	{
1138
		char* start;
1136
		char* start;
1139
		int size;
1137
		int size;
1140
		start = pth;	
1138
		start = pth;	
1141
		while(*start) 
1139
		while(*start) 
1142
		{
1140
		{
1143
			size = 0;
1141
			size = 0;
1144
			char* endp = strchr(start, DIV_PATH);
1142
			char* endp = strchr(start, DIV_PATH);
1145
			size = (endp == 0)? strlen(start): endp-start;
1143
			size = (endp == 0)? strlen(start): endp-start;
1146
			strncpy(m1, start, size);
1144
			strncpy(m1, start, size);
1147
			start += size + 1;
1145
			start += size + 1;
1148
			if (m1[size - 1] != DIV_FOLD)
1146
			if (m1[size - 1] != DIV_FOLD)
1149
				m1[size++] = '/';
1147
				m1[size++] = '/';
1150
			
1148
			
1151
			strcpy(m1 + size,"c--.ini");
1149
			strcpy(m1 + size,"c--.ini");
1152
			if (inih = fopen(m1,"rb"))
1150
			if (inih = fopen(m1,"rb"))
1153
			{_loadIni(inih);return;}
1151
			{_loadIni(inih);return;}
1154
		}
1152
		}
1155
	}
1153
	}
1156
#ifdef _KOS_
1154
#ifdef _KOS_
1157
								//for KolibriOS: load program_dir/c--.ini 
1155
								//for KolibriOS: load program_dir/c--.ini 
1158
	int p;
1156
	int p;
1159
	strcpy(m1,__pgmname);
1157
	strcpy(m1,__pgmname);
1160
	p = strlen(m1);
1158
	p = strlen(m1);
1161
	while ((*(m1+p)!='/') && (p != 0))
1159
	while ((*(m1+p)!='/') && (p != 0))
1162
		p--;
1160
		p--;
1163
	if (p){
1161
	if (p){
1164
		p++;
1162
		p++;
1165
		strcpy(m1+p,"c--.ini");
1163
		strcpy(m1+p,"c--.ini");
1166
		if (inih = fopen(m1,"rb"))
1164
		if (inih = fopen(m1,"rb"))
1167
		{_loadIni(inih);return;}
1165
		{_loadIni(inih);return;}
1168
	}
1166
	}
1169
								//for KolibriOS: load /sys/settings/c--.ini
1167
								//for KolibriOS: load /sys/settings/c--.ini
1170
	inih = fopen("/sys/settings/c--.ini","rb");
1168
	inih = fopen("/sys/settings/c--.ini","rb");
1171
	for(;;){
1169
	for(;;){
1172
		if(fgets(m1,255,inih)==NULL)break;
1170
		if(fgets(m1,255,inih)==NULL)break;
1173
		if(SelectComand(m1,0)==c_end)BadCommandLine(m1);
1171
		if(SelectComand(m1,0)==c_end)BadCommandLine(m1);
1174
	}
1172
	}
1175
	fclose(inih);
1173
	fclose(inih);
1176
	return;
1174
	return;
1177
#endif //_KOS_		
1175
#endif //_KOS_		
1178
}
1176
}
1179
			
1177
			
1180
/*****************************************************************************
1178
/*****************************************************************************
1181
* .NAME   : MALLOC
1179
* .NAME   : MALLOC
1182
* .TITLE  : Âûäåëÿåò ïàìÿòü ñ îáðàáîòêîé îøèáîê.
1180
* .TITLE  : Âûäåëÿåò ïàìÿòü ñ îáðàáîòêîé îøèáîê.
1183
*****************************************************************************/
1181
*****************************************************************************/
1184
void OutMemory()
1182
void OutMemory()
1185
{
1183
{
1186
	preerror("Compiler out of memory");
1184
	preerror("Compiler out of memory");
1187
	exit(e_outofmemory);
1185
	exit(e_outofmemory);
1188
}
1186
}
1189
 
1187
 
1190
void * MALLOC (unsigned long size)
1188
void * MALLOC (unsigned long size)
1191
{
1189
{
1192
void *mem;
1190
void *mem;
1193
	mem=malloc(size);
1191
	mem=malloc(size);
1194
	if(mem==NULL)OutMemory();
1192
	if(mem==NULL)OutMemory();
1195
#ifdef _UNIX_
1193
#ifdef _UNIX_
1196
	else memset(mem,0,size);
1194
	else memset(mem,0,size);
1197
#endif
1195
#endif
1198
 
1196
 
1199
//	if(((unsigned long)mem+size)>maxusedmem)maxusedmem=(unsigned long)mem+size;
1197
//	if(((unsigned long)mem+size)>maxusedmem)maxusedmem=(unsigned long)mem+size;
1200
 
1198
 
1201
	return mem;
1199
	return mem;
1202
}
1200
}
1203
 
1201
 
1204
void *REALLOC(void *block,unsigned long size)
1202
void *REALLOC(void *block,unsigned long size)
1205
{
1203
{
1206
void *mem;
1204
void *mem;
1207
	mem=realloc(block,size);
1205
	mem=realloc(block,size);
1208
	if(mem==NULL)OutMemory();
1206
	if(mem==NULL)OutMemory();
1209
 
1207
 
1210
//	if(((unsigned long)mem+size)>maxusedmem)maxusedmem=(unsigned long)mem+size;
1208
//	if(((unsigned long)mem+size)>maxusedmem)maxusedmem=(unsigned long)mem+size;
1211
 
1209
 
1212
	return mem;
1210
	return mem;
1213
}
1211
}
1214
 
1212
 
1215
void IncludePath(char *buf)
1213
void IncludePath(char *buf)
1216
{
1214
{
1217
	char divfold[3];
1215
	char divfold[3];
1218
	sprintf(divfold,"%c",DIV_FOLD);
1216
	sprintf(divfold,"%c",DIV_FOLD);
1219
	if(numfindpath
1217
	if(numfindpath
1220
		int len=strlen(buf);
1218
		int len=strlen(buf);
1221
		if(buf[len-1]==DIV_FOLD)buf[len-1]=0;
1219
		if(buf[len-1]==DIV_FOLD)buf[len-1]=0;
1222
		else len++;
1220
		else len++;
1223
		char *a=(char *)MALLOC(len+1);
1221
		char *a=(char *)MALLOC(len+1);
1224
		strcpy(a,buf);
1222
		strcpy(a,buf);
1225
		strcat(a,divfold);
1223
		strcat(a,divfold);
1226
		findpath[numfindpath]=a;
1224
		findpath[numfindpath]=a;
1227
		numfindpath++;
1225
		numfindpath++;
1228
		findpath[numfindpath]="";
1226
		findpath[numfindpath]="";
1229
	}
1227
	}
1230
	else puts("Too many include paths");
1228
	else puts("Too many include paths");
1231
}
1229
}
1232
 
1230
 
1233
void doposts()
1231
void doposts()
1234
{
1232
{
1235
unsigned long addvalue,i,addval,addvalw32=0,addvalbss=0;
1233
unsigned long addvalue,i,addval,addvalw32=0,addvalbss=0;
1236
	if(splitdata&&modelmem==TINY&&outptrdata){
1234
	if(splitdata&&modelmem==TINY&&outptrdata){
1237
		memcpy((char *)&output[outptr],(char *)&outputdata[0],outptrdata);
1235
		memcpy((char *)&output[outptr],(char *)&outputdata[0],outptrdata);
1238
		addval=outptr;
1236
		addval=outptr;
1239
		outptr+=outptrdata;
1237
		outptr+=outptrdata;
1240
		outptrdata=outptr;
1238
		outptrdata=outptr;
1241
	}
1239
	}
1242
	addvalue=outptrdata;
1240
	addvalue=outptrdata;
1243
	if(comfile==file_bin)addvalbss=addvalw32=ImageBase;
1241
	if(comfile==file_bin)addvalbss=addvalw32=ImageBase;
1244
	else if(comfile==file_w32){
1242
	else if(comfile==file_w32){
1245
		addvalbss=addvalw32=ImageBase+vsizeheader;
1243
		addvalbss=addvalw32=ImageBase+vsizeheader;
1246
		if(postsize&&wbss){
1244
		if(postsize&&wbss){
1247
			addvalw32+=Align(postsize,OBJECTALIGN);
1245
			addvalw32+=Align(postsize,OBJECTALIGN);
1248
			addvalue=0;
1246
			addvalue=0;
1249
		}
1247
		}
1250
	}
1248
	}
1251
	else{
1249
	else{
1252
		if((outptrdata%2)==1){	/* alignment of entire post data block manditory */
1250
		if((outptrdata%2)==1){	/* alignment of entire post data block manditory */
1253
			addvalue++;	//íà÷àëî íåèíèö.äàííûõ
1251
			addvalue++;	//íà÷àëî íåèíèö.äàííûõ
1254
			postsize++;
1252
			postsize++;
1255
		}
1253
		}
1256
/*		if(am32&&(outptrdata%4)==2){
1254
/*		if(am32&&(outptrdata%4)==2){
1257
			addvalue+=2;	//íà÷àëî íåèíèö.äàííûõ
1255
			addvalue+=2;	//íà÷àëî íåèíèö.äàííûõ
1258
			postsize+=2;
1256
			postsize+=2;
1259
		}*/
1257
		}*/
1260
	}
1258
	}
1261
	if(am32==0&&(MAXDATA-outptrdata)
1259
	if(am32==0&&(MAXDATA-outptrdata)
1262
	for(i=0;i
1260
	for(i=0;i
1263
		switch((postbuf+i)->type){
1261
		switch((postbuf+i)->type){
1264
			case POST_VAR:
1262
			case POST_VAR:
1265
				*(short *)&output[(postbuf+i)->loc]+=(short)addvalue;
1263
				*(short *)&output[(postbuf+i)->loc]+=(short)addvalue;
1266
				break;
1264
				break;
1267
			case POST_VAR32:
1265
			case POST_VAR32:
1268
				*(long *)&output[(postbuf+i)->loc]+=addvalue+addvalbss;
1266
				*(long *)&output[(postbuf+i)->loc]+=addvalue+addvalbss;
1269
				numrel++;
1267
				numrel++;
1270
				break;
1268
				break;
1271
			case FIX_VAR32:
1269
			case FIX_VAR32:
1272
			case FIX_CODE32:
1270
			case FIX_CODE32:
1273
				*(long *)&output[(postbuf+i)->loc]+=addvalw32;
1271
				*(long *)&output[(postbuf+i)->loc]+=addvalw32;
1274
				numrel++;
1272
				numrel++;
1275
				break;
1273
				break;
1276
			case FIX_CODE_ADD:
1274
			case FIX_CODE_ADD:
1277
				if(am32){
1275
				if(am32){
1278
					*(long *)&output[(postbuf+i)->loc]+=addvalw32+(postbuf+i)->num;
1276
					*(long *)&output[(postbuf+i)->loc]+=addvalw32+(postbuf+i)->num;
1279
					(postbuf+i)->type=(unsigned short)FIX_VAR32;
1277
					(postbuf+i)->type=(unsigned short)FIX_VAR32;
1280
				}
1278
				}
1281
				else{
1279
				else{
1282
					*(short *)&output[(postbuf+i)->loc]+=(short)(addval+(postbuf+i)->num);
1280
					*(short *)&output[(postbuf+i)->loc]+=(short)(addval+(postbuf+i)->num);
1283
					(postbuf+i)->type=(unsigned short)FIX_VAR;
1281
					(postbuf+i)->type=(unsigned short)FIX_VAR;
1284
				}
1282
				}
1285
				numrel++;
1283
				numrel++;
1286
				break;
1284
				break;
1287
			case DATABLOCK_VAR:
1285
			case DATABLOCK_VAR:
1288
				*(short *)&output[(postbuf+i)->loc]+=(short)addval;
1286
				*(short *)&output[(postbuf+i)->loc]+=(short)addval;
1289
				if(FixUp)(postbuf+i)->type=(unsigned short)FIX_VAR;
1287
				if(FixUp)(postbuf+i)->type=(unsigned short)FIX_VAR;
1290
				break;
1288
				break;
1291
			case DATABLOCK_VAR32:
1289
			case DATABLOCK_VAR32:
1292
				*(long *)&output[(postbuf+i)->loc]+=addval+addvalw32;
1290
				*(long *)&output[(postbuf+i)->loc]+=addval+addvalw32;
1293
				if(FixUp)(postbuf+i)->type=(unsigned short)FIX_VAR32;
1291
				if(FixUp)(postbuf+i)->type=(unsigned short)FIX_VAR32;
1294
				numrel++;
1292
				numrel++;
1295
				break;
1293
				break;
1296
		}
1294
		}
1297
	}
1295
	}
1298
	ooutptr=addvalue;	//ñîõðàíèòü íà÷àëî post äëÿ debug;
1296
	ooutptr=addvalue;	//ñîõðàíèòü íà÷àëî post äëÿ debug;
1299
}
1297
}
1300
 
1298
 
1301
void GetMemExeDat()
1299
void GetMemExeDat()
1302
{
1300
{
1303
	if(outputdata==output&&outputdata!=0)outputdata=(unsigned char *)MALLOC((size_t)MAXDATA);
1301
	if(outputdata==output&&outputdata!=0)outputdata=(unsigned char *)MALLOC((size_t)MAXDATA);
1304
}
1302
}
1305
 
1303
 
1306
 
1304
 
1307
 
1305
 
1308
int writeoutput()
1306
int writeoutput()
1309
{
1307
{
1310
EXE_DOS_HEADER exeheader;  // header for EXE format
1308
EXE_DOS_HEADER exeheader;  // header for EXE format
1311
	if(fobj){
1309
	if(fobj){
1312
		if(comfile==file_w32&&ocoff
1310
		if(comfile==file_w32&&ocoff
1313
       // Edited by Coldy
1311
       // Edited by Coldy
1314
			||ocoff&&sobj)return MakeCoff();
1312
			||ocoff&&sobj)return MakeCoff();
1315
		return MakeObj();
1313
		return MakeObj();
1316
	}
1314
	}
1317
	if(comfile==file_w32)return MakePE();
1315
	if(comfile==file_w32)return MakePE();
1318
	if(comfile==file_meos)return MakeMEOS();
1316
	if(comfile==file_meos)return MakeMEOS();
1319
	if(comfile==file_bin)return MakeBin32();
1317
	if(comfile==file_bin)return MakeBin32();
1320
	memset(&exeheader,0,sizeof(EXE_DOS_HEADER));
1318
	memset(&exeheader,0,sizeof(EXE_DOS_HEADER));
1321
	if(comfile==file_d32){
1319
	if(comfile==file_d32){
1322
		if(usestub){
1320
		if(usestub){
1323
			MakeLE();
1321
			MakeLE();
1324
			runfilesize+=ftell(hout)-32;
1322
			runfilesize+=ftell(hout)-32;
1325
			goto savecode;
1323
			goto savecode;
1326
		}
1324
		}
1327
		else goto exefile;
1325
		else goto exefile;
1328
	}
1326
	}
1329
	if(comfile==file_com||comfile==file_sys||comfile==file_rom){
1327
	if(comfile==file_com||comfile==file_sys||comfile==file_rom){
1330
		hout=CreateOutPut(outext,"wb");
1328
		hout=CreateOutPut(outext,"wb");
1331
		if(fwrite(output+startptr,comfile==file_rom?romsize:outptr-startptr,1,hout)!=1){
1329
		if(fwrite(output+startptr,comfile==file_rom?romsize:outptr-startptr,1,hout)!=1){
1332
			ErrWrite();
1330
			ErrWrite();
1333
			return(-1);
1331
			return(-1);
1334
		}
1332
		}
1335
	}
1333
	}
1336
	else if(comfile==file_exe){
1334
	else if(comfile==file_exe){
1337
exefile:
1335
exefile:
1338
		hout=CreateOutPut(outext,"wb");
1336
		hout=CreateOutPut(outext,"wb");
1339
		MakeExeHeader(&exeheader);
1337
		MakeExeHeader(&exeheader);
1340
		if(fwrite(&exeheader,sizeof(EXE_DOS_HEADER),1,hout)!=1){
1338
		if(fwrite(&exeheader,sizeof(EXE_DOS_HEADER),1,hout)!=1){
1341
errwr:
1339
errwr:
1342
			fclose(hout);
1340
			fclose(hout);
1343
			hout=NULL;
1341
			hout=NULL;
1344
			ErrWrite();
1342
			ErrWrite();
1345
			return(-1);
1343
			return(-1);
1346
		}
1344
		}
1347
		outputcodestart=ftell(hout);
1345
		outputcodestart=ftell(hout);
1348
savecode:
1346
savecode:
1349
		if(fwrite(output+startptr,outptr-startptr,1,hout)!=1)goto errwr;
1347
		if(fwrite(output+startptr,outptr-startptr,1,hout)!=1)goto errwr;
1350
		if(modelmem==SMALL&&outptrdata!=0){
1348
		if(modelmem==SMALL&&outptrdata!=0){
1351
			if(fwrite(outputdata,outptrdata,1,hout)!=1)goto errwr;
1349
			if(fwrite(outputdata,outptrdata,1,hout)!=1)goto errwr;
1352
		}
1350
		}
1353
	}
1351
	}
1354
	fclose(hout);
1352
	fclose(hout);
1355
	hout=NULL;
1353
	hout=NULL;
1356
	return(0);
1354
	return(0);
1357
}
1355
}
1358
 
1356
 
1359
long CopyFile(FILE *in,FILE *out)
1357
long CopyFile(FILE *in,FILE *out)
1360
{
1358
{
1361
char tbuf[1024];
1359
char tbuf[1024];
1362
long loads=0;
1360
long loads=0;
1363
unsigned int len;
1361
unsigned int len;
1364
	do{
1362
	do{
1365
		len=fread(tbuf,1,1024,in);
1363
		len=fread(tbuf,1,1024,in);
1366
		if(fwrite(tbuf,1,len,out)!=len){
1364
		if(fwrite(tbuf,1,len,out)!=len){
1367
			ErrWrite();
1365
			ErrWrite();
1368
			return -1;
1366
			return -1;
1369
		}
1367
		}
1370
		loads+=len;
1368
		loads+=len;
1371
	}while(len==1024);
1369
	}while(len==1024);
1372
	return loads;
1370
	return loads;
1373
}
1371
}
1374
 
1372
 
1375
unsigned int EntryPoint()
1373
unsigned int EntryPoint()
1376
{
1374
{
1377
ITOK btok;
1375
ITOK btok;
1378
int bb=tk_id;
1376
int bb=tk_id;
1379
unsigned char bufmain[]="main";
1377
unsigned char bufmain[]="main";
1380
unsigned char buf2[]="__startupproc";
1378
unsigned char buf2[]="__startupproc";
1381
unsigned char *buf;
1379
unsigned char *buf;
1382
	if(comfile==file_com)return startptr;
1380
	if(comfile==file_com)return startptr;
1383
	btok.number=0;
1381
	btok.number=0;
1384
//	if(jumptomain!=CALL_NONE||(comfile==file_w32&&dllflag))buf=buf2;
1382
//	if(jumptomain!=CALL_NONE||(comfile==file_w32&&dllflag))buf=buf2;
1385
//	else buf=bufmain;
1383
//	else buf=bufmain;
1386
 
1384
 
1387
	if(jumptomain==CALL_NONE){
1385
	if(jumptomain==CALL_NONE){
1388
		if(useDOS4GW)buf=buf2;
1386
		if(useDOS4GW)buf=buf2;
1389
		else buf=bufmain;
1387
		else buf=bufmain;
1390
	}
1388
	}
1391
	else buf=buf2;
1389
	else buf=buf2;
1392
 
1390
 
1393
	searchtree(&btok,&bb,buf);
1391
	searchtree(&btok,&bb,buf);
1394
	if(bb==tk_id){
1392
	if(bb==tk_id){
1395
		if(comfile==file_w32&&dllflag)return 0xffffffff;
1393
		if(comfile==file_w32&&dllflag)return 0xffffffff;
1396
		printf("Error! Entry point '%s' is not found.\n",buf);
1394
		printf("Error! Entry point '%s' is not found.\n",buf);
1397
		exit(e_entrynotfound);
1395
		exit(e_entrynotfound);
1398
	}
1396
	}
1399
	return btok.number;
1397
	return btok.number;
1400
}
1398
}
1401
 
1399
 
1402
void MakeExeHeader(EXE_DOS_HEADER *exeheader)
1400
void MakeExeHeader(EXE_DOS_HEADER *exeheader)
1403
{
1401
{
1404
long paragraphsrequired;
1402
long paragraphsrequired;
1405
unsigned short count,i;
1403
unsigned short count,i;
1406
int pointstart;
1404
int pointstart;
1407
	exeheader->sign=0x5a4D;				 // MZ
1405
	exeheader->sign=0x5a4D;				 // MZ
1408
//	if(modelmem==TINY&&comfile==file_exe)pointstart=0x100;
1406
//	if(modelmem==TINY&&comfile==file_exe)pointstart=0x100;
1409
/*	else*/ pointstart=EntryPoint();
1407
/*	else*/ pointstart=EntryPoint();
1410
	count=(unsigned short)(runfilesize%512);
1408
	count=(unsigned short)(runfilesize%512);
1411
	i=(unsigned short)(runfilesize/512);
1409
	i=(unsigned short)(runfilesize/512);
1412
	exeheader->numlastbyte=count;
1410
	exeheader->numlastbyte=count;
1413
	exeheader->numpage=(unsigned short)(count==0?i:i+1);
1411
	exeheader->numpage=(unsigned short)(count==0?i:i+1);
1414
	exeheader->headsize=2; 		// size of header in paragraphs (2 paragraphs)
1412
	exeheader->headsize=2; 		// size of header in paragraphs (2 paragraphs)
1415
	exeheader->initIP=(unsigned short)pointstart;	 // IP at entry (0x0000)
1413
	exeheader->initIP=(unsigned short)pointstart;	 // IP at entry (0x0000)
1416
	paragraphsrequired=(outptr+outptrdata+postsize+stacksize+15)/16;
1414
	paragraphsrequired=(outptr+outptrdata+postsize+stacksize+15)/16;
1417
	if(modelmem==TINY&&comfile==file_exe){
1415
	if(modelmem==TINY&&comfile==file_exe){
1418
		exeheader->initSS=0xFFF0; 		 // displacement of SS
1416
		exeheader->initSS=0xFFF0; 		 // displacement of SS
1419
		exeheader->initSP=0xFFFE; // intial value of SP
1417
		exeheader->initSP=0xFFFE; // intial value of SP
1420
		exeheader->initCS=0xfff0;						 // displacement of CS (0x0000)
1418
		exeheader->initCS=0xfff0;						 // displacement of CS (0x0000)
1421
		if(!resizemem){
1419
		if(!resizemem){
1422
			exeheader->minmem=0xfff;	// min-paragraphs
1420
			exeheader->minmem=0xfff;	// min-paragraphs
1423
			exeheader->maxmem=0xffff;	// max-paragraphs
1421
			exeheader->maxmem=0xffff;	// max-paragraphs
1424
		}
1422
		}
1425
		else{
1423
		else{
1426
			paragraphsrequired-=0x10;
1424
			paragraphsrequired-=0x10;
1427
			exeheader->initSP=(unsigned short)(paragraphsrequired*16); // intial value of SP
1425
			exeheader->initSP=(unsigned short)(paragraphsrequired*16); // intial value of SP
1428
			exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1426
			exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1429
			exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1427
			exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1430
		}
1428
		}
1431
	}
1429
	}
1432
	else if(comfile==file_d32){
1430
	else if(comfile==file_d32){
1433
		exeheader->initSP=(unsigned short)stacksize; // intial value of SP
1431
		exeheader->initSP=(unsigned short)stacksize; // intial value of SP
1434
		exeheader->initSS=(unsigned short)((outptr+postsize+15)/16); // displacement of SS
1432
		exeheader->initSS=(unsigned short)((outptr+postsize+15)/16); // displacement of SS
1435
		exeheader->initCS=(unsigned short)((pointstart/65536)*4096);
1433
		exeheader->initCS=(unsigned short)((pointstart/65536)*4096);
1436
		if(resizemem){
1434
		if(resizemem){
1437
			exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1435
			exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1438
			exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1436
			exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1439
		}
1437
		}
1440
		else exeheader->maxmem=(unsigned short)0xFFFF;	// max-paragraphs
1438
		else exeheader->maxmem=(unsigned short)0xFFFF;	// max-paragraphs
1441
	}
1439
	}
1442
	else{
1440
	else{
1443
		exeheader->initSS=(unsigned short)(outptr/16); 		 // displacement of SS
1441
		exeheader->initSS=(unsigned short)(outptr/16); 		 // displacement of SS
1444
		exeheader->initSP=(unsigned short)(outptrdata+postsize+stacksize); // intial value of SP
1442
		exeheader->initSP=(unsigned short)(outptrdata+postsize+stacksize); // intial value of SP
1445
		exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1443
		exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1446
		exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1444
		exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1447
	}
1445
	}
1448
	exeheader->ofsreloc=0x1c;						 // offset of first relocation item (0x0000)
1446
	exeheader->ofsreloc=0x1c;						 // offset of first relocation item (0x0000)
1449
}
1447
}
1450
 
1448
 
1451
void startsymbiosys(char *symfile)
1449
void startsymbiosys(char *symfile)
1452
{
1450
{
1453
unsigned int size;
1451
unsigned int size;
1454
int filehandle;
1452
int filehandle;
1455
long filesize;
1453
long filesize;
1456
	outptr=startptr;
1454
	outptr=startptr;
1457
	if((filehandle=open(symfile,O_BINARY|O_RDONLY))==-1){;
1455
	if((filehandle=open(symfile,O_BINARY|O_RDONLY))==-1){;
1458
		ErrOpenFile(symfile);
1456
		ErrOpenFile(symfile);
1459
		exit(e_symbioerror);
1457
		exit(e_symbioerror);
1460
	}
1458
	}
1461
	if((filesize=getfilelen(filehandle))!=-1L){
1459
	if((filesize=getfilelen(filehandle))!=-1L){
1462
		if(filesize+outptr
1460
		if(filesize+outptr
1463
			size=filesize;
1461
			size=filesize;
1464
			if((unsigned int)read(filehandle,output+outptr,size)!=size){
1462
			if((unsigned int)read(filehandle,output+outptr,size)!=size){
1465
				close(filehandle);
1463
				close(filehandle);
1466
				puts("Error reading symbio COM file.");
1464
				puts("Error reading symbio COM file.");
1467
				exit(e_symbioerror);
1465
				exit(e_symbioerror);
1468
			}
1466
			}
1469
			outptr+=size;
1467
			outptr+=size;
1470
		}
1468
		}
1471
		else{
1469
		else{
1472
			puts("Symbio COM file is too large.");
1470
			puts("Symbio COM file is too large.");
1473
			exit(e_symbioerror);
1471
			exit(e_symbioerror);
1474
		}
1472
		}
1475
	}
1473
	}
1476
	else{
1474
	else{
1477
		puts("Unable to determine symbio COM file size.");
1475
		puts("Unable to determine symbio COM file size.");
1478
		exit(e_symbioerror);
1476
		exit(e_symbioerror);
1479
	}
1477
	}
1480
	close(filehandle);
1478
	close(filehandle);
1481
	outptrdata=outptr;
1479
	outptrdata=outptr;
1482
	outputcodestart=outptr-startptr;
1480
	outputcodestart=outptr-startptr;
1483
	addconsttotree("__comsymbios",TRUE);
1481
	addconsttotree("__comsymbios",TRUE);
1484
}
1482
}
1485
 
1483
 
1486
void BadCommandLine(char *str)
1484
void BadCommandLine(char *str)
1487
{
1485
{
1488
	printf("Unknown or bad command line option '%s'.\n",str);
1486
	printf("Unknown or bad command line option '%s'.\n",str);
1489
//					PrintInfo(usage);
1487
//					PrintInfo(usage);
1490
	exit(e_unknowncommandline);
1488
	exit(e_unknowncommandline);
1491
}
1489
}
1492
 
1490
 
1493
void warnunused(struct idrec *ptr)
1491
void warnunused(struct idrec *ptr)
1494
{
1492
{
1495
//static count=0;
1493
//static count=0;
1496
	if(ptr!=NULL){
1494
	if(ptr!=NULL){
1497
		if(ptr->count==0&&startupfile!=ptr->file){
1495
		if(ptr->count==0&&startupfile!=ptr->file){
1498
			linenumber=ptr->line;
1496
			linenumber=ptr->line;
1499
			currentfileinfo=ptr->file;
1497
			currentfileinfo=ptr->file;
1500
			int i=0;
1498
			int i=0;
1501
			switch(ptr->rectok){
1499
			switch(ptr->rectok){
1502
				case tk_proc:
1500
				case tk_proc:
1503
					if(ptr->recsegm!=NOT_DYNAMIC||strcmp(ptr->recid,mesmain)==0)break;
1501
					if(ptr->recsegm!=NOT_DYNAMIC||strcmp(ptr->recid,mesmain)==0)break;
1504
					i++;
1502
					i++;
1505
				case tk_structvar:
1503
				case tk_structvar:
1506
					i++;
1504
					i++;
1507
				case tk_charvar:
1505
				case tk_charvar:
1508
				case tk_bytevar:
1506
				case tk_bytevar:
1509
				case tk_intvar:
1507
				case tk_intvar:
1510
				case tk_wordvar:
1508
				case tk_wordvar:
1511
				case tk_longvar:
1509
				case tk_longvar:
1512
				case tk_dwordvar:
1510
				case tk_dwordvar:
1513
				case tk_floatvar:
1511
				case tk_floatvar:
1514
				case tk_pointer:
1512
				case tk_pointer:
1515
				case tk_qword:
1513
				case tk_qword:
1516
				case tk_double:
1514
				case tk_double:
1517
					if(i<=1&&(ptr->recpost==DYNAMIC_VAR||ptr->recpost==DYNAMIC_POST))break;
1515
					if(i<=1&&(ptr->recpost==DYNAMIC_VAR||ptr->recpost==DYNAMIC_POST))break;
1518
					warningnotused(ptr->recid,i);
1516
					warningnotused(ptr->recid,i);
1519
					break;
1517
					break;
1520
			}
1518
			}
1521
		}
1519
		}
1522
		warnunused(ptr ->left);
1520
		warnunused(ptr ->left);
1523
		warnunused(ptr ->right);
1521
		warnunused(ptr ->right);
1524
	}
1522
	}
1525
}
1523
}
1526
 
1524
 
1527
void WarnUnusedVar()//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
1525
void WarnUnusedVar()//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
1528
{
1526
{
1529
	warnunused(treestart);
1527
	warnunused(treestart);
1530
	for(unsigned int i=0;istlist);
1528
	for(unsigned int i=0;istlist);
1531
}
1529
}
1532
 
1530
 
1533
void addinitvar()
1531
void addinitvar()
1534
{
1532
{
1535
unsigned int i;
1533
unsigned int i;
1536
	if(numfloatconst){	//âñòàâèòü êîíñòàíòû float è ïðèâÿçàòü èõ
1534
	if(numfloatconst){	//âñòàâèòü êîíñòàíòû float è ïðèâÿçàòü èõ
1537
		if(alignword||optimizespeed)AlignCD(DS,chip>5?16:4);
1535
		if(alignword||optimizespeed)AlignCD(DS,chip>5?16:4);
1538
		for(i=0;i
1536
		for(i=0;i
1539
			if((postbuf+i)->type==POST_FLOATNUM){
1537
			if((postbuf+i)->type==POST_FLOATNUM){
1540
				if(am32)*(unsigned long *)&output[(postbuf+i)->loc]=outptrdata+(postbuf+i)->num;
1538
				if(am32)*(unsigned long *)&output[(postbuf+i)->loc]=outptrdata+(postbuf+i)->num;
1541
				else *(unsigned short *)&output[(postbuf+i)->loc]=(unsigned short)(outptrdata+(postbuf+i)->num);
1539
				else *(unsigned short *)&output[(postbuf+i)->loc]=(unsigned short)(outptrdata+(postbuf+i)->num);
1542
				if(FixUp)(postbuf+i)->type=FIX_VAR32;
1540
				if(FixUp)(postbuf+i)->type=FIX_VAR32;
1543
				else killpost(i--);
1541
				else killpost(i--);
1544
			}
1542
			}
1545
		}
1543
		}
1546
		for(i=0;i
1544
		for(i=0;i
1547
			if(dbg&2){
1545
			if(dbg&2){
1548
				if((floatnum+i)->type==tk_float)sprintf((char *)string,"const float %f",(floatnum+i)->fnum);
1546
				if((floatnum+i)->type==tk_float)sprintf((char *)string,"const float %f",(floatnum+i)->fnum);
1549
				else sprintf((char *)string,"const double %f",(floatnum+i)->dnum);
1547
				else sprintf((char *)string,"const double %f",(floatnum+i)->dnum);
1550
				AddDataNullLine(4,(char *)string);
1548
				AddDataNullLine(4,(char *)string);
1551
			}
1549
			}
1552
			outdwordd((floatnum+i)->num[0]);
1550
			outdwordd((floatnum+i)->num[0]);
1553
			if((floatnum+i)->type!=tk_float){
1551
			if((floatnum+i)->type!=tk_float){
1554
				outdwordd((floatnum+i)->num[1]);
1552
				outdwordd((floatnum+i)->num[1]);
1555
				datasize+=4;
1553
				datasize+=4;
1556
			}
1554
			}
1557
			datasize+=4;
1555
			datasize+=4;
1558
		}
1556
		}
1559
		free(floatnum);
1557
		free(floatnum);
1560
		numfloatconst=0;
1558
		numfloatconst=0;
1561
		floatnum=NULL;
1559
		floatnum=NULL;
1562
	}
1560
	}
1563
	for(i=0;i<(unsigned int)numswtable;i++){	//ñîçäàòü è âñòàâèòü òàáëèöû switch
1561
	for(i=0;i<(unsigned int)numswtable;i++){	//ñîçäàòü è âñòàâèòü òàáëèöû switch
1564
		int j;
1562
		int j;
1565
		FSWI *swt=swtables+i;
1563
		FSWI *swt=swtables+i;
1566
		if(alignword)AlignCD(DS,swt->type);
1564
		if(alignword)AlignCD(DS,swt->type);
1567
		if(dbg&2)AddDataNullLine((char)swt->type,"switch table address");
1565
		if(dbg&2)AddDataNullLine((char)swt->type,"switch table address");
1568
		if(am32==FALSE){	//âñòàâèòü â êîä àäðåñ òàáëèöû
1566
		if(am32==FALSE){	//âñòàâèòü â êîä àäðåñ òàáëèöû
1569
			*(unsigned short *)&output[swt->ptb]=(unsigned short)outptrdata;
1567
			*(unsigned short *)&output[swt->ptb]=(unsigned short)outptrdata;
1570
		}
1568
		}
1571
		else *(unsigned long *)&output[swt->ptb]=outptrdata;
1569
		else *(unsigned long *)&output[swt->ptb]=outptrdata;
1572
		unsigned char oam32=am32;
1570
		unsigned char oam32=am32;
1573
		am32=(unsigned char)(swt->type/2-1);
1571
		am32=(unsigned char)(swt->type/2-1);
1574
 
1572
 
1575
		unsigned long val=swt->defal;
1573
		unsigned long val=swt->defal;
1576
		int oline=outptrdata;
1574
		int oline=outptrdata;
1577
		for(j=0;jsizetab;j++){	//çàïîëíèòü òàáëèöó çíà÷åíèÿìè ïî óìîë÷àíèþ
1575
		for(j=0;jsizetab;j++){	//çàïîëíèòü òàáëèöó çíà÷åíèÿìè ïî óìîë÷àíèþ
1578
//			if((swt->info+jj)->type==singlcase)
1576
//			if((swt->info+jj)->type==singlcase)
1579
			AddReloc(DS);
1577
			AddReloc(DS);
1580
			if(am32)outdwordd(val);
1578
			if(am32)outdwordd(val);
1581
			else outwordd(val);
1579
			else outwordd(val);
1582
		}
1580
		}
1583
		if(swt->mode==2){
1581
		if(swt->mode==2){
1584
			if(dbg&2)AddDataNullLine((char)swt->razr,"switch table value");
1582
			if(dbg&2)AddDataNullLine((char)swt->razr,"switch table value");
1585
			if(oam32==FALSE){	//âñòàâèòü â êîä àäðåñ òàáëèöû
1583
			if(oam32==FALSE){	//âñòàâèòü â êîä àäðåñ òàáëèöû
1586
				*(unsigned short *)&output[swt->ptv]=(unsigned short)outptrdata;
1584
				*(unsigned short *)&output[swt->ptv]=(unsigned short)outptrdata;
1587
			}
1585
			}
1588
			else *(unsigned long *)&output[swt->ptv]=outptrdata;
1586
			else *(unsigned long *)&output[swt->ptv]=outptrdata;
1589
		}
1587
		}
1590
		int ii=0;	//ñ÷åò÷èê case
1588
		int ii=0;	//ñ÷åò÷èê case
1591
		for(int jj=0;jjnumcase;jj++){
1589
		for(int jj=0;jjnumcase;jj++){
1592
			j=(swt->info+jj)->value;	//çíà÷åíèå
1590
			j=(swt->info+jj)->value;	//çíà÷åíèå
1593
			val=(swt->info+jj)->postcase;
1591
			val=(swt->info+jj)->postcase;
1594
			if((swt->info+jj)->type==singlcase){
1592
			if((swt->info+jj)->type==singlcase){
1595
				if(swt->mode==1){
1593
				if(swt->mode==1){
1596
					if(am32==FALSE)*(unsigned short *)&outputdata[oline+j*2]=(unsigned short)val;
1594
					if(am32==FALSE)*(unsigned short *)&outputdata[oline+j*2]=(unsigned short)val;
1597
					else *(unsigned long *)&outputdata[oline+j*4]=val;
1595
					else *(unsigned long *)&outputdata[oline+j*4]=val;
1598
				}
1596
				}
1599
				else{
1597
				else{
1600
					if(am32==FALSE)*(unsigned short *)&outputdata[oline+ii*2]=(unsigned short)val;
1598
					if(am32==FALSE)*(unsigned short *)&outputdata[oline+ii*2]=(unsigned short)val;
1601
					else *(unsigned long *)&outputdata[oline+ii*4]=val;
1599
					else *(unsigned long *)&outputdata[oline+ii*4]=val;
1602
					switch(swt->razr){
1600
					switch(swt->razr){
1603
						case r8: opd(j); break;
1601
						case r8: opd(j); break;
1604
						case r16: outwordd(j); break;
1602
						case r16: outwordd(j); break;
1605
						case r32: outdwordd(j); break;
1603
						case r32: outdwordd(j); break;
1606
					}
1604
					}
1607
					ii++;
1605
					ii++;
1608
				}
1606
				}
1609
			}
1607
			}
1610
			else{
1608
			else{
1611
				jj++;
1609
				jj++;
1612
				for(;(unsigned int)j<=(swt->info+jj)->value;j++){
1610
				for(;(unsigned int)j<=(swt->info+jj)->value;j++){
1613
					if(swt->mode==1){
1611
					if(swt->mode==1){
1614
						if(am32==FALSE)*(unsigned short *)&outputdata[oline+j*2]=(unsigned short)val;
1612
						if(am32==FALSE)*(unsigned short *)&outputdata[oline+j*2]=(unsigned short)val;
1615
						else *(unsigned long *)&outputdata[oline+j*4]=val;
1613
						else *(unsigned long *)&outputdata[oline+j*4]=val;
1616
					}
1614
					}
1617
					else{
1615
					else{
1618
						if(am32==FALSE)*(unsigned short *)&outputdata[oline+ii*2]=(unsigned short)val;
1616
						if(am32==FALSE)*(unsigned short *)&outputdata[oline+ii*2]=(unsigned short)val;
1619
						else *(unsigned long *)&outputdata[oline+ii*4]=val;
1617
						else *(unsigned long *)&outputdata[oline+ii*4]=val;
1620
						switch(swt->razr){
1618
						switch(swt->razr){
1621
							case r8: opd(j); break;
1619
							case r8: opd(j); break;
1622
							case r16: outwordd(j); break;
1620
							case r16: outwordd(j); break;
1623
							case r32: outdwordd(j); break;
1621
							case r32: outdwordd(j); break;
1624
						}
1622
						}
1625
						ii++;
1623
						ii++;
1626
					}
1624
					}
1627
				}
1625
				}
1628
			}
1626
			}
1629
		}
1627
		}
1630
		am32=oam32;
1628
		am32=oam32;
1631
		free(swt->info);
1629
		free(swt->info);
1632
	}
1630
	}
1633
	if(numswtable){
1631
	if(numswtable){
1634
		free(swtables);
1632
		free(swtables);
1635
		numswtable=0;
1633
		numswtable=0;
1636
	}
1634
	}
1637
 
1635
 
1638
	for(i=0;i
1636
	for(i=0;i
1639
		if((postbuf+i)->type==DIN_VAR||(postbuf+i)->type==DIN_VAR32){
1637
		if((postbuf+i)->type==DIN_VAR||(postbuf+i)->type==DIN_VAR32){
1640
			idrec *ptr=(idrec *)(postbuf+i)->num;
1638
			idrec *ptr=(idrec *)(postbuf+i)->num;
1641
//			printf("post=%u num=%08X %s\n",ptr->recpost,ptr->recnumber,ptr->recid);
1639
//			printf("post=%u num=%08X %s\n",ptr->recpost,ptr->recnumber,ptr->recid);
1642
			if(ptr->recpost==USED_DIN_VAR)setdindata(ptr,i);
1640
			if(ptr->recpost==USED_DIN_VAR)setdindata(ptr,i);
1643
			else{
1641
			else{
1644
				if((postbuf+i)->type==DIN_VAR){
1642
				if((postbuf+i)->type==DIN_VAR){
1645
					*(unsigned short *)&output[(postbuf+i)->loc]+=(unsigned short)(ptr->recnumber);
1643
					*(unsigned short *)&output[(postbuf+i)->loc]+=(unsigned short)(ptr->recnumber);
1646
				}
1644
				}
1647
				else{
1645
				else{
1648
//					printf("loc=%08X num=%08X\n",*(unsigned long *)&output[(postbuf+i)->loc],ptr->recnumber);
1646
//					printf("loc=%08X num=%08X\n",*(unsigned long *)&output[(postbuf+i)->loc],ptr->recnumber);
1649
					*(unsigned long *)&output[(postbuf+i)->loc]+=ptr->recnumber;
1647
					*(unsigned long *)&output[(postbuf+i)->loc]+=ptr->recnumber;
1650
				}
1648
				}
1651
			}
1649
			}
1652
			if(FixUp)(postbuf+i)->type=(unsigned short)((postbuf+i)->type==DIN_VAR?FIX_VAR:FIX_VAR32);
1650
			if(FixUp)(postbuf+i)->type=(unsigned short)((postbuf+i)->type==DIN_VAR?FIX_VAR:FIX_VAR32);
1653
			else killpost(i--);
1651
			else killpost(i--);
1654
		}
1652
		}
1655
	}
1653
	}
1656
	dopoststrings();
1654
	dopoststrings();
1657
}
1655
}
1658
 
1656
 
1659
void setdindata(idrec *ptr,int i)
1657
void setdindata(idrec *ptr,int i)
1660
{
1658
{
1661
unsigned char *oldinput;
1659
unsigned char *oldinput;
1662
unsigned int oldinptr,oldendinptr;
1660
unsigned int oldinptr,oldendinptr;
1663
unsigned char bcha;
1661
unsigned char bcha;
1664
unsigned int oline,ofile;
1662
unsigned int oline,ofile;
1665
char *ostartline;
1663
char *ostartline;
1666
	if(alignword){
1664
	if(alignword){
1667
		if(ptr->rectok==tk_structvar)alignersize+=AlignCD(DS,2);	//âûðîâíÿòü
1665
		if(ptr->rectok==tk_structvar)alignersize+=AlignCD(DS,2);	//âûðîâíÿòü
1668
		else alignersize+=AlignCD(DS,GetVarSize(ptr->rectok));
1666
		else alignersize+=AlignCD(DS,GetVarSize(ptr->rectok));
1669
	}
1667
	}
1670
//	printf("loc=%08X out=%08X num=%08X\n",*(unsigned long *)&output[(postbuf+i)->loc],outptrdata,ptr->recnumber);
1668
//	printf("loc=%08X out=%08X num=%08X\n",*(unsigned long *)&output[(postbuf+i)->loc],outptrdata,ptr->recnumber);
1671
	if((postbuf+i)->type==DIN_VAR)*(unsigned short *)&output[(postbuf+i)->loc]+=(unsigned short)(outptrdata);
1669
	if((postbuf+i)->type==DIN_VAR)*(unsigned short *)&output[(postbuf+i)->loc]+=(unsigned short)(outptrdata);
1672
	else *(unsigned long *)&output[(postbuf+i)->loc]+=outptrdata;
1670
	else *(unsigned long *)&output[(postbuf+i)->loc]+=outptrdata;
1673
	ptr->recpost=0;
1671
	ptr->recpost=0;
1674
	ptr->recnumber+=outptrdata;
1672
	ptr->recnumber+=outptrdata;
1675
	oline=linenum2;
1673
	oline=linenum2;
1676
	ofile=currentfileinfo;
1674
	ofile=currentfileinfo;
1677
	oldinput=input;
1675
	oldinput=input;
1678
	oldinptr=inptr2;
1676
	oldinptr=inptr2;
1679
	bcha=cha2;
1677
	bcha=cha2;
1680
	oldendinptr=endinptr;
1678
	oldendinptr=endinptr;
1681
	input=(unsigned char *)ptr->sbuf;
1679
	input=(unsigned char *)ptr->sbuf;
1682
	inptr2=1;
1680
	inptr2=1;
1683
	ostartline=startline;
1681
	ostartline=startline;
1684
	startline=(char*)input;
1682
	startline=(char*)input;
1685
	cha2=input[0];
1683
	cha2=input[0];
1686
	linenum2=ptr->line;
1684
	linenum2=ptr->line;
1687
	currentfileinfo=ptr->file;
1685
	currentfileinfo=ptr->file;
1688
	endinptr=strlen((char *)input);
1686
	endinptr=strlen((char *)input);
1689
	endinput=startline+endinptr;
1687
	endinput=startline+endinptr;
1690
	endoffile=0;
1688
	endoffile=0;
1691
	tok=ptr->rectok;
1689
	tok=ptr->rectok;
1692
	if(tok==tk_structvar)datasize+=initstructvar((structteg *)ptr->newid,ptr->recrm);
1690
	if(tok==tk_structvar)datasize+=initstructvar((structteg *)ptr->newid,ptr->recrm);
1693
	else{
1691
	else{
1694
long type = 0,ssize = 0;
1692
long type = 0,ssize = 0;
1695
unsigned char typev = 0;
1693
unsigned char typev = 0;
1696
		if(tok>=tk_charvar&&tok<=tk_doublevar){
1694
		if(tok>=tk_charvar&&tok<=tk_doublevar){
1697
			type=tok-(tk_charvar-tk_char);
1695
			type=tok-(tk_charvar-tk_char);
1698
			typev=variable;
1696
			typev=variable;
1699
			ssize=typesize(type);
1697
			ssize=typesize(type);
1700
		}
1698
		}
1701
		else if(tok==tk_pointer){
1699
		else if(tok==tk_pointer){
1702
			typev=pointer;
1700
			typev=pointer;
1703
			type=itok.type;
1701
			type=itok.type;
1704
			if(am32==FALSE&&((itok.flag&f_far)==0))ssize=2;
1702
			if(am32==FALSE&&((itok.flag&f_far)==0))ssize=2;
1705
			else ssize=4;
1703
			else ssize=4;
1706
		}
1704
		}
1707
		datasize+=initglobalvar(type,ptr->recsize/ssize,ssize,typev);
1705
		datasize+=initglobalvar(type,ptr->recsize/ssize,ssize,typev);
1708
	}
1706
	}
1709
	free(input);
1707
	free(input);
1710
	linenum2=oline;
1708
	linenum2=oline;
1711
	currentfileinfo=ofile;
1709
	currentfileinfo=ofile;
1712
	input=oldinput;
1710
	input=oldinput;
1713
	inptr2=oldinptr;
1711
	inptr2=oldinptr;
1714
	cha2=bcha;
1712
	cha2=bcha;
1715
	endinptr=oldendinptr;
1713
	endinptr=oldendinptr;
1716
	endoffile=0;
1714
	endoffile=0;
1717
	startline=ostartline;
1715
	startline=ostartline;
1718
}
1716
}
1719
 
1717
 
1720
FILE *CreateOutPut(char *ext,char *mode)
1718
FILE *CreateOutPut(char *ext,char *mode)
1721
{
1719
{
1722
char buf[256];
1720
char buf[256];
1723
FILE *diskout;
1721
FILE *diskout;
1724
    if(ext && strlen(ext)) {
1722
    if(ext && strlen(ext)) {
1725
        sprintf(buf,"%s.%s",rawfilename,ext);
1723
        sprintf(buf,"%s.%s",rawfilename,ext);
1726
    } else {
1724
    } else {
1727
        strcpy(buf, rawfilename);
1725
        strcpy(buf, rawfilename);
1728
    }
1726
    }
1729
    
1727
    
1730
	if((diskout=fopen(buf,mode))==NULL){
1728
	if((diskout=fopen(buf,mode))==NULL){
1731
		ErrOpenFile(buf);
1729
		ErrOpenFile(buf);
1732
		exit(e_notcreateoutput);
1730
		exit(e_notcreateoutput);
1733
	}
1731
	}
1734
	return diskout;
1732
	return diskout;
1735
}
1733
}
1736
 
1734
 
1737
int numundefclassproc=0;
1735
int numundefclassproc=0;
1738
idrec **undefclassproc;
1736
idrec **undefclassproc;
1739
 
1737
 
1740
void AddUndefClassProc()
1738
void AddUndefClassProc()
1741
{
1739
{
1742
	if(numundefclassproc==0)undefclassproc=(idrec **)MALLOC(sizeof(idrec **));
1740
	if(numundefclassproc==0)undefclassproc=(idrec **)MALLOC(sizeof(idrec **));
1743
	else undefclassproc=(idrec **)REALLOC(undefclassproc,sizeof(idrec **)*(numundefclassproc+1));
1741
	else undefclassproc=(idrec **)REALLOC(undefclassproc,sizeof(idrec **)*(numundefclassproc+1));
1744
	undefclassproc[numundefclassproc]=itok.rec;
1742
	undefclassproc[numundefclassproc]=itok.rec;
1745
	numundefclassproc++;
1743
	numundefclassproc++;
1746
}
1744
}
1747
 
1745
 
1748
void CheckUndefClassProc()
1746
void CheckUndefClassProc()
1749
{
1747
{
1750
	for(int i=0;i
1748
	for(int i=0;i
1751
		idrec *ptr=undefclassproc[i];
1749
		idrec *ptr=undefclassproc[i];
1752
		if(ptr->rectok==tk_undefproc){
1750
		if(ptr->rectok==tk_undefproc){
1753
			currentfileinfo=ptr->file;
1751
			currentfileinfo=ptr->file;
1754
			linenumber=ptr->line;
1752
			linenumber=ptr->line;
1755
			thisundefined(ptr->recid);
1753
			thisundefined(ptr->recid);
1756
		}
1754
		}
1757
	}
1755
	}
1758
}
1756
}
1759
>
1757
>
1760
>
1758
>
1761
>
1759
>
1762
>
1760
>
1763
>
1761
>
1764
>
1762
>
1765
>
1763
>
1766
>
1764
>
1767
>
1765
>
1768
>
1766
>
1769
>
1767
>
1770
>
1768
>
1771
>
1769
>
1772
>
1770
>
1773
>
1771
>
1774
>
1772
>
1775
>
1773
>
1776
>
1774
>
1777
errlate:
1775
errlate:
1778
>
1776
>
1779
>
1777
>
1780
>
1778
>
1781
>
1779
>
1782
>
1780
>
1783
>
1781
>
1784
>
1782
>
1785
>
1783
>
1786
>
1784
>
1787
>
1785
>
1788
>
1786
>