Subversion Repositories Kolibri OS

Rev

Rev 4478 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
 
2
; Copyright (c) 1999-2016, Tomasz Grysztar.
6467 dunkaist 3
; All rights reserved.
31 halyavin 4
5
 
6
	mov	edi,characters
2665 dunkaist 7
	xor	al,al
8
      make_characters_table:
31 halyavin 9
	stosb
2665 dunkaist 10
	inc	al
11
	jnz	make_characters_table
12
	mov	esi,characters+'a'
13
	mov	edi,characters+'A'
14
	mov	ecx,26
15
	rep	movsb
16
	mov	edi,characters
17
	mov	esi,symbol_characters+1
18
	movzx	ecx,byte [esi-1]
19
	xor	eax,eax
20
      mark_symbol_characters:
31 halyavin 21
	lodsb
2665 dunkaist 22
	mov	byte [edi+eax],0
23
	loop	mark_symbol_characters
24
	mov	edi,locals_counter
25
	mov	ax,1 + '0' shl 8
26
	stos	word [edi]
27
	mov	edi,[memory_start]
28
	mov	[include_paths],edi
29
	mov	esi,include_variable
30
	call	get_environment_variable
31
	xor	al,al
32
	stos	byte [edi]
33
	mov	[memory_start],edi
34
	mov	eax,[additional_memory]
35
	mov	[free_additional_memory],eax
36
	mov	eax,[additional_memory_end]
37
	mov	[labels_list],eax
38
	xor	eax,eax
39
	mov	[source_start],eax
40
	mov	[tagged_blocks],eax
4039 heavyiron 41
	mov	[hash_tree],eax
2665 dunkaist 42
	mov	[error],eax
43
	mov	[macro_status],al
44
	mov	[current_line],eax
6467 dunkaist 45
	mov	esi,[initial_definitions]
46
	test	esi,esi
47
	jz	predefinitions_ok
48
      process_predefinitions:
49
	movzx	ecx,byte [esi]
50
	test	ecx,ecx
51
	jz	predefinitions_ok
52
	inc	esi
53
	lea	eax,[esi+ecx]
54
	push	eax
55
	mov	ch,10b
56
	call	add_preprocessor_symbol
57
	pop	esi
58
	mov	edi,[memory_start]
59
	mov	[edx+8],edi
60
      convert_predefinition:
61
	cmp	edi,[memory_end]
62
	jae	out_of_memory
63
	lods	byte [esi]
64
	or	al,al
65
	jz	predefinition_converted
66
	cmp	al,20h
67
	je	convert_predefinition
68
	mov	ah,al
69
	mov	ebx,characters
70
	xlat	byte [ebx]
71
	or	al,al
72
	jz	predefinition_separator
73
	cmp	ah,27h
74
	je	predefinition_string
75
	cmp	ah,22h
76
	je	predefinition_string
77
	mov	byte [edi],1Ah
78
	scas	word [edi]
79
	xchg	al,ah
80
	stos	byte [edi]
81
	mov	ebx,characters
82
	xor	ecx,ecx
83
      predefinition_symbol:
84
	lods	byte [esi]
85
	stos	byte [edi]
86
	xlat	byte [ebx]
87
	or	al,al
88
	loopnzd predefinition_symbol
89
	neg	ecx
90
	cmp	ecx,255
91
	ja	invalid_definition
92
	mov	ebx,edi
93
	sub	ebx,ecx
94
	mov	byte [ebx-2],cl
95
      found_predefinition_separator:
96
	dec	edi
97
	mov	ah,[esi-1]
98
      predefinition_separator:
99
	xchg	al,ah
100
	or	al,al
101
	jz	predefinition_converted
102
	cmp	al,20h
103
	je	convert_predefinition
104
	cmp	al,3Bh
105
	je	invalid_definition
106
	cmp	al,5Ch
107
	je	predefinition_backslash
108
	stos	byte [edi]
109
	jmp	convert_predefinition
110
      predefinition_string:
111
	mov	al,22h
112
	stos	byte [edi]
113
	scas	dword [edi]
114
	mov	ebx,edi
115
      copy_predefinition_string:
116
	lods	byte [esi]
117
	stos	byte [edi]
118
	or	al,al
119
	jz	invalid_definition
120
	cmp	al,ah
121
	jne	copy_predefinition_string
122
	lods	byte [esi]
123
	cmp	al,ah
124
	je	copy_predefinition_string
125
	dec	esi
126
	dec	edi
127
	mov	eax,edi
128
	sub	eax,ebx
129
	mov	[ebx-4],eax
130
	jmp	convert_predefinition
131
      predefinition_backslash:
132
	mov	byte [edi],0
133
	lods	byte [esi]
134
	or	al,al
135
	jz	invalid_definition
136
	cmp	al,20h
137
	je	invalid_definition
138
	cmp	al,3Bh
139
	je	invalid_definition
140
	mov	al,1Ah
141
	stos	byte [edi]
142
	mov	ecx,edi
143
	mov	ax,5C01h
144
	stos	word [edi]
145
	dec	esi
146
      group_predefinition_backslashes:
147
	lods	byte [esi]
148
	cmp	al,5Ch
149
	jne	predefinition_backslashed_symbol
150
	stos	byte [edi]
151
	inc	byte [ecx]
152
	jmp	group_predefinition_backslashes
153
      predefinition_backslashed_symbol:
154
	cmp	al,20h
155
	je	invalid_definition
156
	cmp	al,22h
157
	je	invalid_definition
158
	cmp	al,27h
159
	je	invalid_definition
160
	cmp	al,3Bh
161
	je	invalid_definition
162
	mov	ah,al
163
	mov	ebx,characters
164
	xlat	byte [ebx]
165
	or	al,al
166
	jz	predefinition_backslashed_symbol_character
167
	mov	al,ah
168
      convert_predefinition_backslashed_symbol:
169
	stos	byte [edi]
170
	xlat	byte [ebx]
171
	or	al,al
172
	jz	found_predefinition_separator
173
	inc	byte [ecx]
174
	jz	invalid_definition
175
	lods	byte [esi]
176
	jmp	convert_predefinition_backslashed_symbol
177
      predefinition_backslashed_symbol_character:
178
	mov	al,ah
179
	stos	byte [edi]
180
	inc	byte [ecx]
181
	jmp	convert_predefinition
182
      predefinition_converted:
183
	mov	[memory_start],edi
184
	sub	edi,[edx+8]
185
	mov	[edx+12],edi
186
	jmp	process_predefinitions
187
      predefinitions_ok:
188
	mov	esi,[input_file]
2665 dunkaist 189
	mov	edx,esi
190
	call	open
191
	jc	main_file_not_found
192
	mov	edi,[memory_start]
193
	call	preprocess_file
194
	cmp	[macro_status],0
4478 dunkaist 195
	je	process_postponed
196
	mov	eax,[error_line]
2665 dunkaist 197
	mov	[current_line],eax
198
	jmp	incomplete_macro
4478 dunkaist 199
      process_postponed:
200
	mov	edx,hash_tree
201
	mov	ecx,32
202
      find_postponed_list:
203
	mov	edx,[edx]
204
	or	edx,edx
205
	loopnz	find_postponed_list
206
	jz	preprocessing_finished
207
      process_postponed_list:
208
	mov	eax,[edx]
209
	or	eax,eax
210
	jz	preprocessing_finished
211
	push	edx
212
	mov	ebx,edx
213
      find_earliest_postponed:
214
	mov	eax,[edx]
215
	or	eax,eax
216
	jz	earliest_postponed_found
217
	mov	ebx,edx
218
	mov	edx,eax
219
	jmp	find_earliest_postponed
220
      earliest_postponed_found:
221
	mov	[ebx],eax
222
	call	use_postponed_macro
223
	pop	edx
224
	cmp	[macro_status],0
6467 dunkaist 225
	je	process_postponed_list
226
	mov	eax,[error_line]
227
	mov	[current_line],eax
228
	jmp	incomplete_macro
229
      preprocessing_finished:
4478 dunkaist 230
	mov	[source_start],edi
2665 dunkaist 231
	ret
232
      use_postponed_macro:
4478 dunkaist 233
	lea	esi,[edi-1]
234
	push	ecx esi
235
	mov	[struc_name],0
236
	jmp	use_macro
237
31 halyavin 238
 
239
	push	[memory_end]
2665 dunkaist 240
	push	esi
241
	mov	al,2
242
	xor	edx,edx
243
	call	lseek
244
	push	eax
245
	xor	al,al
246
	xor	edx,edx
247
	call	lseek
248
	pop	ecx
249
	mov	edx,[memory_end]
250
	dec	edx
251
	mov	byte [edx],1Ah
252
	sub	edx,ecx
253
	jc	out_of_memory
254
	mov	esi,edx
255
	cmp	edx,edi
256
	jbe	out_of_memory
257
	mov	[memory_end],edx
258
	call	read
259
	call	close
260
	pop	edx
261
	xor	ecx,ecx
262
	mov	ebx,esi
263
      preprocess_source:
31 halyavin 264
	inc	ecx
2665 dunkaist 265
	mov	[current_line],edi
266
	mov	eax,edx
267
	stos	dword [edi]
268
	mov	eax,ecx
269
	stos	dword [edi]
270
	mov	eax,esi
271
	sub	eax,ebx
272
	stos	dword [edi]
273
	xor	eax,eax
274
	stos	dword [edi]
275
	push	ebx edx
276
	call	convert_line
277
	call	preprocess_line
278
	pop	edx ebx
279
      next_line:
31 halyavin 280
	cmp	byte [esi-1],0
2665 dunkaist 281
	je	file_end
282
	cmp	byte [esi-1],1Ah
283
	jne	preprocess_source
284
      file_end:
31 halyavin 285
	pop	[memory_end]
2665 dunkaist 286
	clc
287
	ret
288
31 halyavin 289
 
290
	push	ecx
2665 dunkaist 291
	test	[macro_status],0Fh
292
	jz	convert_line_data
293
	mov	ax,3Bh
294
	stos	word [edi]
295
      convert_line_data:
31 halyavin 296
	cmp	edi,[memory_end]
2665 dunkaist 297
	jae	out_of_memory
298
	lods	byte [esi]
299
	cmp	al,20h
300
	je	convert_line_data
301
	cmp	al,9
302
	je	convert_line_data
303
	mov	ah,al
304
	mov	ebx,characters
305
	xlat	byte [ebx]
306
	or	al,al
307
	jz	convert_separator
308
	cmp	ah,27h
309
	je	convert_string
310
	cmp	ah,22h
311
	je	convert_string
312
	mov	byte [edi],1Ah
313
	scas	word [edi]
314
	xchg	al,ah
315
	stos	byte [edi]
316
	mov	ebx,characters
317
	xor	ecx,ecx
318
      convert_symbol:
31 halyavin 319
	lods	byte [esi]
2665 dunkaist 320
	stos	byte [edi]
321
	xlat	byte [ebx]
322
	or	al,al
323
	loopnzd convert_symbol
324
	neg	ecx
325
	cmp	ecx,255
326
	ja	name_too_long
327
	mov	ebx,edi
328
	sub	ebx,ecx
329
	mov	byte [ebx-2],cl
330
      found_separator:
31 halyavin 331
	dec	edi
2665 dunkaist 332
	mov	ah,[esi-1]
333
      convert_separator:
31 halyavin 334
	xchg	al,ah
2665 dunkaist 335
	cmp	al,20h
336
	jb	control_character
337
	je	convert_line_data
338
      symbol_character:
31 halyavin 339
	cmp	al,3Bh
2665 dunkaist 340
	je	ignore_comment
341
	cmp	al,5Ch
342
	je	backslash_character
343
	stos	byte [edi]
344
	jmp	convert_line_data
345
      control_character:
31 halyavin 346
	cmp	al,1Ah
2665 dunkaist 347
	je	line_end
348
	cmp	al,0Dh
349
	je	cr_character
350
	cmp	al,0Ah
351
	je	lf_character
352
	cmp	al,9
353
	je	convert_line_data
354
	or	al,al
355
	jnz	symbol_character
356
	jmp	line_end
357
      lf_character:
31 halyavin 358
	lods	byte [esi]
2665 dunkaist 359
	cmp	al,0Dh
360
	je	line_end
361
	dec	esi
362
	jmp	line_end
363
      cr_character:
31 halyavin 364
	lods	byte [esi]
2665 dunkaist 365
	cmp	al,0Ah
366
	je	line_end
367
	dec	esi
368
	jmp	line_end
369
      convert_string:
31 halyavin 370
	mov	al,22h
2665 dunkaist 371
	stos	byte [edi]
372
	scas	dword [edi]
373
	mov	ebx,edi
374
      copy_string:
31 halyavin 375
	lods	byte [esi]
2665 dunkaist 376
	stos	byte [edi]
377
	cmp	al,0Ah
378
	je	no_end_quote
4039 heavyiron 379
	cmp	al,0Dh
2665 dunkaist 380
	je	no_end_quote
4039 heavyiron 381
	or	al,al
2665 dunkaist 382
	jz	no_end_quote
4039 heavyiron 383
	cmp	al,1Ah
2665 dunkaist 384
	je	no_end_quote
4039 heavyiron 385
	cmp	al,ah
2665 dunkaist 386
	jne	copy_string
387
	lods	byte [esi]
388
	cmp	al,ah
389
	je	copy_string
390
	dec	esi
391
	dec	edi
392
	mov	eax,edi
393
	sub	eax,ebx
394
	mov	[ebx-4],eax
395
	jmp	convert_line_data
396
      backslash_character:
31 halyavin 397
	mov	byte [edi],0
2665 dunkaist 398
	lods	byte [esi]
399
	cmp	al,20h
400
	je	concatenate_lines
401
	cmp	al,9
402
	je	concatenate_lines
403
	cmp	al,1Ah
404
	je	unexpected_end_of_file
405
	or	al,al
406
	jz	unexpected_end_of_file
407
	cmp	al,0Ah
408
	je	concatenate_lf
409
	cmp	al,0Dh
410
	je	concatenate_cr
411
	cmp	al,3Bh
412
	je	find_concatenated_line
413
	mov	al,1Ah
414
	stos	byte [edi]
415
	mov	ecx,edi
416
	mov	ax,5C01h
417
	stos	word [edi]
418
	dec	esi
419
      group_backslashes:
31 halyavin 420
	lods	byte [esi]
2665 dunkaist 421
	cmp	al,5Ch
422
	jne	backslashed_symbol
423
	stos	byte [edi]
424
	inc	byte [ecx]
425
	jz	name_too_long
6467 dunkaist 426
	jmp	group_backslashes
2665 dunkaist 427
      no_end_quote:
4039 heavyiron 428
	mov	byte [ebx-5],0
429
	jmp	missing_end_quote
430
      backslashed_symbol:
31 halyavin 431
	cmp	al,1Ah
2665 dunkaist 432
	je	unexpected_end_of_file
433
	or	al,al
434
	jz	unexpected_end_of_file
435
	cmp	al,0Ah
436
	je	extra_characters_on_line
437
	cmp	al,0Dh
438
	je	extra_characters_on_line
439
	cmp	al,20h
440
	je	extra_characters_on_line
441
	cmp	al,9
442
	je	extra_characters_on_line
443
	cmp	al,22h
444
	je	extra_characters_on_line
445
	cmp	al,27h
446
	je	extra_characters_on_line
447
	cmp	al,3Bh
448
	je	extra_characters_on_line
449
	mov	ah,al
450
	mov	ebx,characters
451
	xlat	byte [ebx]
452
	or	al,al
453
	jz	backslashed_symbol_character
454
	mov	al,ah
455
      convert_backslashed_symbol:
31 halyavin 456
	stos	byte [edi]
2665 dunkaist 457
	xlat	byte [ebx]
458
	or	al,al
459
	jz	found_separator
460
	inc	byte [ecx]
461
	jz	name_too_long
462
	lods	byte [esi]
463
	jmp	convert_backslashed_symbol
464
      backslashed_symbol_character:
31 halyavin 465
	mov	al,ah
2665 dunkaist 466
	stos	byte [edi]
467
	inc	byte [ecx]
468
	jmp	convert_line_data
469
      concatenate_lines:
31 halyavin 470
	lods	byte [esi]
2665 dunkaist 471
	cmp	al,20h
472
	je	concatenate_lines
473
	cmp	al,9
474
	je	concatenate_lines
475
	cmp	al,1Ah
476
	je	unexpected_end_of_file
477
	or	al,al
478
	jz	unexpected_end_of_file
479
	cmp	al,0Ah
480
	je	concatenate_lf
481
	cmp	al,0Dh
482
	je	concatenate_cr
483
	cmp	al,3Bh
484
	jne	extra_characters_on_line
485
      find_concatenated_line:
31 halyavin 486
	lods	byte [esi]
2665 dunkaist 487
	cmp	al,0Ah
488
	je	concatenate_lf
489
	cmp	al,0Dh
490
	je	concatenate_cr
491
	or	al,al
492
	jz	concatenate_ok
493
	cmp	al,1Ah
494
	jne	find_concatenated_line
495
	jmp	unexpected_end_of_file
496
      concatenate_lf:
31 halyavin 497
	lods	byte [esi]
2665 dunkaist 498
	cmp	al,0Dh
499
	je	concatenate_ok
500
	dec	esi
501
	jmp	concatenate_ok
502
      concatenate_cr:
31 halyavin 503
	lods	byte [esi]
2665 dunkaist 504
	cmp	al,0Ah
505
	je	concatenate_ok
506
	dec	esi
507
      concatenate_ok:
31 halyavin 508
	inc	dword [esp]
2665 dunkaist 509
	jmp	convert_line_data
510
      ignore_comment:
31 halyavin 511
	lods	byte [esi]
2665 dunkaist 512
	cmp	al,0Ah
513
	je	lf_character
514
	cmp	al,0Dh
515
	je	cr_character
516
	or	al,al
517
	jz	line_end
518
	cmp	al,1Ah
519
	jne	ignore_comment
520
      line_end:
31 halyavin 521
	xor	al,al
2665 dunkaist 522
	stos	byte [edi]
523
	pop	ecx
524
	ret
525
31 halyavin 526
 
109 heavyiron 527
	mov	edi,converted
2665 dunkaist 528
	mov	ebx,characters
529
      convert_case:
109 heavyiron 530
	lods	byte [esi]
2665 dunkaist 531
	xlat	byte [ebx]
532
	stos	byte [edi]
533
	loop	convert_case
534
      case_ok:
109 heavyiron 535
	ret
2665 dunkaist 536
109 heavyiron 537
 
538
	push	edi
2665 dunkaist 539
	mov	edx,esi
540
	mov	ebp,ecx
541
	call	lower_case
542
	pop	edi
543
      scan_directives:
109 heavyiron 544
	mov	esi,converted
2665 dunkaist 545
	movzx	eax,byte [edi]
546
	or	al,al
547
	jz	no_directive
548
	mov	ecx,ebp
549
	inc	edi
550
	mov	ebx,edi
551
	add	ebx,eax
552
	mov	ah,[esi]
553
	cmp	ah,[edi]
554
	jb	no_directive
555
	ja	next_directive
556
	cmp	cl,al
557
	jne	next_directive
558
	repe	cmps byte [esi],[edi]
559
	jb	no_directive
560
	je	directive_ok
561
      next_directive:
109 heavyiron 562
	mov	edi,ebx
2665 dunkaist 563
	add	edi,2
564
	jmp	scan_directives
565
      no_directive:
109 heavyiron 566
	mov	esi,edx
2665 dunkaist 567
	mov	ecx,ebp
568
	stc
569
	ret
570
      directive_ok:
109 heavyiron 571
	lea	esi,[edx+ebp]
2665 dunkaist 572
	call	directive_handler
573
      directive_handler:
1189 heavyiron 574
	pop	ecx
2665 dunkaist 575
	movzx	eax,word [ebx]
576
	add	eax,ecx
577
	clc
578
	ret
579
109 heavyiron 580
 
31 halyavin 581
	mov	eax,esp
2665 dunkaist 582
	sub	eax,100h
583
	jc	stack_overflow
584
	cmp	eax,[stack_limit]
585
	jb	stack_overflow
586
	push	ecx esi
587
      preprocess_current_line:
31 halyavin 588
	mov	esi,[current_line]
2665 dunkaist 589
	add	esi,16
590
	cmp	word [esi],3Bh
591
	jne	line_start_ok
592
	add	esi,2
593
      line_start_ok:
31 halyavin 594
	test	[macro_status],0F0h
2665 dunkaist 595
	jnz	macro_preprocessing
596
	cmp	byte [esi],1Ah
597
	jne	not_fix_constant
598
	movzx	edx,byte [esi+1]
599
	lea	edx,[esi+2+edx]
600
	cmp	word [edx],031Ah
601
	jne	not_fix_constant
602
	mov	ebx,characters
603
	movzx	eax,byte [edx+2]
604
	xlat	byte [ebx]
605
	ror	eax,8
606
	mov	al,[edx+3]
607
	xlat	byte [ebx]
608
	ror	eax,8
609
	mov	al,[edx+4]
610
	xlat	byte [ebx]
611
	ror	eax,16
612
	cmp	eax,'fix'
613
	je	define_fix_constant
614
      not_fix_constant:
31 halyavin 615
	call	process_fix_constants
2665 dunkaist 616
	jmp	initial_preprocessing_ok
617
      macro_preprocessing:
31 halyavin 618
	call	process_macro_operators
2665 dunkaist 619
      initial_preprocessing_ok:
31 halyavin 620
	mov	esi,[current_line]
2665 dunkaist 621
	add	esi,16
622
	mov	al,[macro_status]
623
	test	al,2
624
	jnz	skip_macro_block
625
	test	al,1
626
	jnz	find_macro_block
627
      preprocess_instruction:
31 halyavin 628
	mov	[current_offset],esi
2665 dunkaist 629
	lods	byte [esi]
630
	movzx	ecx,byte [esi]
631
	inc	esi
632
	cmp	al,1Ah
633
	jne	not_preprocessor_symbol
634
	cmp	cl,3
635
	jb	not_preprocessor_directive
636
	push	edi
637
	mov	edi,preprocessor_directives
638
	call	get_directive
639
	pop	edi
640
	jc	not_preprocessor_directive
641
	mov	byte [edx-2],3Bh
642
	jmp	near eax
643
      not_preprocessor_directive:
31 halyavin 644
	xor	ch,ch
2665 dunkaist 645
	call	get_preprocessor_symbol
646
	jc	not_macro
647
	mov	byte [ebx-2],3Bh
648
	mov	[struc_name],0
649
	jmp	use_macro
650
      not_macro:
31 halyavin 651
	mov	[struc_name],esi
2665 dunkaist 652
	add	esi,ecx
653
	lods	byte [esi]
654
	cmp	al,':'
655
	je	preprocess_label
656
	cmp	al,1Ah
657
	jne	not_preprocessor_symbol
658
	lods	byte [esi]
659
	cmp	al,3
660
	jne	not_symbolic_constant
661
	mov	ebx,characters
662
	movzx	eax,byte [esi]
663
	xlat	byte [ebx]
664
	ror	eax,8
665
	mov	al,[esi+1]
666
	xlat	byte [ebx]
667
	ror	eax,8
668
	mov	al,[esi+2]
669
	xlat	byte [ebx]
670
	ror	eax,16
671
	cmp	eax,'equ'
672
	je	define_equ_constant
673
	mov	al,3
674
      not_symbolic_constant:
31 halyavin 675
	mov	ch,1
2665 dunkaist 676
	mov	cl,al
677
	call	get_preprocessor_symbol
678
	jc	not_preprocessor_symbol
679
	push	edx esi
680
	mov	esi,[struc_name]
681
	mov	[struc_label],esi
682
	sub	[struc_label],2
683
	mov	cl,[esi-1]
684
	mov	ch,10b
685
	call	get_preprocessor_symbol
686
	jc	struc_name_ok
687
	mov	ecx,[edx+12]
688
	add	ecx,3
689
	lea	ebx,[edi+ecx]
690
	mov	ecx,edi
691
	sub	ecx,[struc_label]
692
	lea	esi,[edi-1]
693
	lea	edi,[ebx-1]
694
	std
695
	rep	movs byte [edi],[esi]
696
	cld
697
	mov	edi,[struc_label]
698
	mov	esi,[edx+8]
699
	mov	ecx,[edx+12]
700
	add	[struc_name],ecx
701
	add	[struc_name],3
702
	call	move_data
703
	mov	al,3Ah
704
	stos	byte [edi]
705
	mov	ax,3Bh
706
	stos	word [edi]
707
	mov	edi,ebx
708
	pop	esi
709
	add	esi,[edx+12]
710
	add	esi,3
711
	pop	edx
712
	jmp	use_macro
713
      struc_name_ok:
31 halyavin 714
	mov	edx,[struc_name]
2665 dunkaist 715
	movzx	eax,byte [edx-1]
716
	add	edx,eax
717
	push	edi
718
	lea	esi,[edi-1]
719
	mov	ecx,edi
720
	sub	ecx,edx
721
	std
722
	rep	movs byte [edi],[esi]
723
	cld
724
	pop	edi
725
	inc	edi
726
	mov	al,3Ah
727
	mov	[edx],al
728
	inc	al
729
	mov	[edx+1],al
730
	pop	esi edx
731
	inc	esi
732
	jmp	use_macro
733
      preprocess_label:
31 halyavin 734
	dec	esi
2665 dunkaist 735
	sub	esi,ecx
736
	lea	ebp,[esi-2]
737
	mov	ch,10b
738
	call	get_preprocessor_symbol
739
	jnc	symbolic_constant_in_label
740
	lea	esi,[esi+ecx+1]
741
	cmp	byte [esi],':'
4039 heavyiron 742
	jne	preprocess_instruction
743
	inc	esi
744
	jmp	preprocess_instruction
2665 dunkaist 745
      symbolic_constant_in_label:
31 halyavin 746
	mov	ebx,[edx+8]
2665 dunkaist 747
	mov	ecx,[edx+12]
748
	add	ecx,ebx
749
      check_for_broken_label:
31 halyavin 750
	cmp	ebx,ecx
2665 dunkaist 751
	je	label_broken
752
	cmp	byte [ebx],1Ah
753
	jne	label_broken
754
	movzx	eax,byte [ebx+1]
755
	lea	ebx,[ebx+2+eax]
756
	cmp	ebx,ecx
757
	je	label_constant_ok
758
	cmp	byte [ebx],':'
759
	jne	label_broken
760
	inc	ebx
761
	cmp	byte [ebx],':'
4039 heavyiron 762
	jne	check_for_broken_label
763
	inc	ebx
764
	jmp	check_for_broken_label
2665 dunkaist 765
      label_broken:
31 halyavin 766
	push	line_preprocessed
2665 dunkaist 767
	jmp	replace_symbolic_constant
768
      label_constant_ok:
31 halyavin 769
	mov	ecx,edi
2665 dunkaist 770
	sub	ecx,esi
771
	mov	edi,[edx+12]
772
	add	edi,ebp
773
	push	edi
774
	lea	eax,[edi+ecx]
775
	push	eax
776
	cmp	esi,edi
777
	je	replace_label
778
	jb	move_rest_of_line_up
779
	rep	movs byte [edi],[esi]
780
	jmp	replace_label
781
      move_rest_of_line_up:
31 halyavin 782
	lea	esi,[esi+ecx-1]
2665 dunkaist 783
	lea	edi,[edi+ecx-1]
784
	std
785
	rep	movs byte [edi],[esi]
786
	cld
787
      replace_label:
31 halyavin 788
	mov	ecx,[edx+12]
2665 dunkaist 789
	mov	edi,[esp+4]
790
	sub	edi,ecx
791
	mov	esi,[edx+8]
792
	rep	movs byte [edi],[esi]
793
	pop	edi esi
794
	inc	esi
795
	jmp	preprocess_instruction
796
      not_preprocessor_symbol:
31 halyavin 797
	mov	esi,[current_offset]
2665 dunkaist 798
	call	process_equ_constants
799
      line_preprocessed:
31 halyavin 800
	pop	esi ecx
2665 dunkaist 801
	ret
802
31 halyavin 803
 
804
	push	ebp edi esi
2665 dunkaist 805
	mov	ebp,ecx
806
	shl	ebp,22
807
	movzx	ecx,cl
808
	mov	ebx,hash_tree
809
	mov	edi,10
810
      follow_hashes_roots:
31 halyavin 811
	mov	edx,[ebx]
2665 dunkaist 812
	or	edx,edx
813
	jz	preprocessor_symbol_not_found
814
	xor	eax,eax
815
	shl	ebp,1
816
	adc	eax,0
817
	lea	ebx,[edx+eax*4]
818
	dec	edi
819
	jnz	follow_hashes_roots
820
	mov	edi,ebx
821
	call	calculate_hash
822
	mov	ebp,eax
823
	and	ebp,3FFh
824
	shl	ebp,10
825
	xor	ebp,eax
826
	mov	ebx,edi
827
	mov	edi,22
828
      follow_hashes_tree:
31 halyavin 829
	mov	edx,[ebx]
2665 dunkaist 830
	or	edx,edx
831
	jz	preprocessor_symbol_not_found
832
	xor	eax,eax
833
	shl	ebp,1
834
	adc	eax,0
835
	lea	ebx,[edx+eax*4]
836
	dec	edi
837
	jnz	follow_hashes_tree
838
	mov	al,cl
839
	mov	edx,[ebx]
840
	or	edx,edx
841
	jz	preprocessor_symbol_not_found
842
      compare_with_preprocessor_symbol:
31 halyavin 843
	mov	edi,[edx+4]
2665 dunkaist 844
	cmp	edi,1
845
	jbe	next_equal_hash
846
	repe	cmps byte [esi],[edi]
847
	je	preprocessor_symbol_found
848
	mov	cl,al
849
	mov	esi,[esp]
850
      next_equal_hash:
31 halyavin 851
	mov	edx,[edx]
2665 dunkaist 852
	or	edx,edx
853
	jnz	compare_with_preprocessor_symbol
854
      preprocessor_symbol_not_found:
31 halyavin 855
	pop	esi edi ebp
2665 dunkaist 856
	stc
857
	ret
858
      preprocessor_symbol_found:
31 halyavin 859
	pop	ebx edi ebp
2665 dunkaist 860
	clc
861
	ret
862
      calculate_hash:
31 halyavin 863
	xor	ebx,ebx
2665 dunkaist 864
	mov	eax,2166136261
865
	mov	ebp,16777619
866
      fnv1a_hash:
31 halyavin 867
	xor	al,[esi+ebx]
2665 dunkaist 868
	mul	ebp
869
	inc	bl
870
	cmp	bl,cl
871
	jb	fnv1a_hash
872
	ret
873
add_preprocessor_symbol:
31 halyavin 874
	push	edi esi
2665 dunkaist 875
	xor	eax,eax
4478 dunkaist 876
	or	cl,cl
877
	jz	reshape_hash
878
	cmp	ch,11b
2665 dunkaist 879
	je	preprocessor_symbol_name_ok
880
	push	ecx
881
	movzx	ecx,cl
882
	mov	edi,preprocessor_directives
883
	call	get_directive
884
	jnc	reserved_word_used_as_symbol
885
	pop	ecx
886
      preprocessor_symbol_name_ok:
992 heavyiron 887
	call	calculate_hash
2665 dunkaist 888
      reshape_hash:
4478 dunkaist 889
	mov	ebp,eax
2665 dunkaist 890
	and	ebp,3FFh
891
	shr	eax,10
892
	xor	ebp,eax
893
	shl	ecx,22
894
	or	ebp,ecx
895
	mov	ebx,hash_tree
896
	mov	ecx,32
897
      find_leave_for_symbol:
31 halyavin 898
	mov	edx,[ebx]
2665 dunkaist 899
	or	edx,edx
900
	jz	extend_hashes_tree
901
	xor	eax,eax
902
	rol	ebp,1
903
	adc	eax,0
904
	lea	ebx,[edx+eax*4]
905
	dec	ecx
906
	jnz	find_leave_for_symbol
907
	mov	edx,[ebx]
908
	or	edx,edx
909
	jz	add_symbol_entry
910
	shr	ebp,30
911
	cmp	ebp,11b
912
	je	reuse_symbol_entry
913
	cmp	dword [edx+4],0
914
	jne	add_symbol_entry
915
      find_entry_to_reuse:
31 halyavin 916
	mov	edi,[edx]
2665 dunkaist 917
	or	edi,edi
918
	jz	reuse_symbol_entry
919
	cmp	dword [edi+4],0
920
	jne	reuse_symbol_entry
921
	mov	edx,edi
922
	jmp	find_entry_to_reuse
923
      add_symbol_entry:
31 halyavin 924
	mov	eax,edx
2665 dunkaist 925
	mov	edx,[labels_list]
926
	sub	edx,16
927
	cmp	edx,[free_additional_memory]
928
	jb	out_of_memory
929
	mov	[labels_list],edx
930
	mov	[edx],eax
931
	mov	[ebx],edx
932
      reuse_symbol_entry:
31 halyavin 933
	pop	esi edi
2665 dunkaist 934
	mov	[edx+4],esi
935
	ret
936
      extend_hashes_tree:
31 halyavin 937
	mov	edx,[labels_list]
2665 dunkaist 938
	sub	edx,8
939
	cmp	edx,[free_additional_memory]
940
	jb	out_of_memory
941
	mov	[labels_list],edx
942
	xor	eax,eax
943
	mov	[edx],eax
944
	mov	[edx+4],eax
945
	shl	ebp,1
946
	adc	eax,0
947
	mov	[ebx],edx
948
	lea	ebx,[edx+eax*4]
949
	dec	ecx
950
	jnz	extend_hashes_tree
951
	mov	edx,[labels_list]
952
	sub	edx,16
953
	cmp	edx,[free_additional_memory]
954
	jb	out_of_memory
955
	mov	[labels_list],edx
956
	mov	dword [edx],0
957
	mov	[ebx],edx
958
	pop	esi edi
959
	mov	[edx+4],esi
960
	ret
961
31 halyavin 962
 
963
	add	edx,5
2665 dunkaist 964
	add	esi,2
965
	push	edx
966
	mov	ch,11b
967
	jmp	define_preprocessor_constant
968
define_equ_constant:
31 halyavin 969
	add	esi,3
2665 dunkaist 970
	push	esi
971
	call	process_equ_constants
972
	mov	esi,[struc_name]
973
	mov	ch,10b
974
      define_preprocessor_constant:
109 heavyiron 975
	mov	byte [esi-2],3Bh
2665 dunkaist 976
	mov	cl,[esi-1]
977
	call	add_preprocessor_symbol
978
	pop	ebx
979
	mov	ecx,edi
980
	dec	ecx
981
	sub	ecx,ebx
982
	mov	[edx+8],ebx
983
	mov	[edx+12],ecx
984
	jmp	line_preprocessed
985
define_symbolic_constant:
109 heavyiron 986
	lods	byte [esi]
2665 dunkaist 987
	cmp	al,1Ah
988
	jne	invalid_name
989
	lods	byte [esi]
990
	mov	cl,al
991
	mov	ch,10b
992
	call	add_preprocessor_symbol
993
	movzx	eax,byte [esi-1]
994
	add	esi,eax
995
	lea	ecx,[edi-1]
996
	sub	ecx,esi
997
	mov	[edx+8],esi
998
	mov	[edx+12],ecx
999
	jmp	line_preprocessed
1000
109 heavyiron 1001
 
31 halyavin 1002
	mov	ch,1
2665 dunkaist 1003
	jmp	make_macro
1004
define_macro:
31 halyavin 1005
	xor	ch,ch
2665 dunkaist 1006
      make_macro:
31 halyavin 1007
	lods	byte [esi]
2665 dunkaist 1008
	cmp	al,1Ah
1009
	jne	invalid_name
1010
	lods	byte [esi]
1011
	mov	cl,al
1012
	call	add_preprocessor_symbol
1013
	mov	eax,[current_line]
1014
	mov	[edx+12],eax
1015
	movzx	eax,byte [esi-1]
1016
	add	esi,eax
1017
	mov	[edx+8],esi
1018
	mov	al,[macro_status]
1019
	and	al,0F0h
1020
	or	al,1
1021
	mov	[macro_status],al
1022
	mov	eax,[current_line]
1023
	mov	[error_line],eax
1024
	xor	ebp,ebp
1025
	lods	byte [esi]
1026
	or	al,al
1027
	jz	line_preprocessed
1028
	cmp	al,'{'
1029
	je	found_macro_block
1030
	dec	esi
1031
      skip_macro_arguments:
31 halyavin 1032
	lods	byte [esi]
2665 dunkaist 1033
	cmp	al,1Ah
1034
	je	skip_macro_argument
1035
	cmp	al,'['
1036
	jne	invalid_macro_arguments
1037
	or	ebp,-1
1038
	jz	invalid_macro_arguments
1039
	lods	byte [esi]
1040
	cmp	al,1Ah
1041
	jne	invalid_macro_arguments
1042
      skip_macro_argument:
31 halyavin 1043
	movzx	eax,byte [esi]
2665 dunkaist 1044
	inc	esi
1045
	add	esi,eax
1046
	lods	byte [esi]
1047
	cmp	al,':'
6467 dunkaist 1048
	je	macro_argument_with_default_value
1049
	cmp	al,'='
2665 dunkaist 1050
	je	macro_argument_with_default_value
1051
	cmp	al,'*'
1052
	jne	macro_argument_end
1053
	lods	byte [esi]
1054
      macro_argument_end:
31 halyavin 1055
	cmp	al,','
2665 dunkaist 1056
	je	skip_macro_arguments
1057
	cmp	al,'&'
6467 dunkaist 1058
	je	macro_arguments_finisher
1059
	cmp	al,']'
2665 dunkaist 1060
	jne	end_macro_arguments
1061
	not	ebp
6467 dunkaist 1062
      macro_arguments_finisher:
1063
	lods	byte [esi]
2665 dunkaist 1064
      end_macro_arguments:
31 halyavin 1065
	or	ebp,ebp
2665 dunkaist 1066
	jnz	invalid_macro_arguments
1067
	or	al,al
1068
	jz	line_preprocessed
1069
	cmp	al,'{'
1070
	je	found_macro_block
1071
	jmp	invalid_macro_arguments
1072
      macro_argument_with_default_value:
2664 dunkaist 1073
	or	[skip_default_argument_value],-1
6467 dunkaist 1074
	call	skip_macro_argument_value
2665 dunkaist 1075
	inc	esi
1076
	jmp	macro_argument_end
1077
      skip_macro_argument_value:
2664 dunkaist 1078
	cmp	byte [esi],'<'
2665 dunkaist 1079
	jne	simple_argument
1080
	mov	ecx,1
1081
	inc	esi
1082
      enclosed_argument:
2664 dunkaist 1083
	lods	byte [esi]
2665 dunkaist 1084
	or	al,al
1085
	jz	invalid_macro_arguments
1086
	cmp	al,1Ah
1087
	je	enclosed_symbol
1088
	cmp	al,22h
1089
	je	enclosed_string
1090
	cmp	al,'>'
1091
	je	enclosed_argument_end
1092
	cmp	al,'<'
1093
	jne	enclosed_argument
1094
	inc	ecx
1095
	jmp	enclosed_argument
1096
      enclosed_symbol:
2664 dunkaist 1097
	movzx	eax,byte [esi]
2665 dunkaist 1098
	inc	esi
1099
	add	esi,eax
1100
	jmp	enclosed_argument
1101
      enclosed_string:
2664 dunkaist 1102
	lods	dword [esi]
2665 dunkaist 1103
	add	esi,eax
1104
	jmp	enclosed_argument
1105
      enclosed_argument_end:
2664 dunkaist 1106
	loop	enclosed_argument
2665 dunkaist 1107
	lods	byte [esi]
1108
	or	al,al
1109
	jz	argument_value_end
1110
	cmp	al,','
1111
	je	argument_value_end
1112
	cmp	[skip_default_argument_value],0
6467 dunkaist 1113
	je	invalid_macro_arguments
2665 dunkaist 1114
	cmp	al,'{'
1115
	je	argument_value_end
1116
	cmp	al,'&'
6467 dunkaist 1117
	je	argument_value_end
1118
	or	ebp,ebp
2665 dunkaist 1119
	jz	invalid_macro_arguments
1120
	cmp	al,']'
1121
	je	argument_value_end
1122
	jmp	invalid_macro_arguments
1123
      simple_argument:
2664 dunkaist 1124
	lods	byte [esi]
2665 dunkaist 1125
	or	al,al
1126
	jz	argument_value_end
1127
	cmp	al,','
1128
	je	argument_value_end
1129
	cmp	al,22h
1130
	je	argument_string
1131
	cmp	al,1Ah
1132
	je	argument_symbol
1133
	cmp	[skip_default_argument_value],0
6467 dunkaist 1134
	je	simple_argument
2665 dunkaist 1135
	cmp	al,'{'
1136
	je	argument_value_end
1137
	cmp	al,'&'
6467 dunkaist 1138
	je	argument_value_end
1139
	or	ebp,ebp
2665 dunkaist 1140
	jz	simple_argument
1141
	cmp	al,']'
1142
	je	argument_value_end
1143
      argument_symbol:
2664 dunkaist 1144
	movzx	eax,byte [esi]
2665 dunkaist 1145
	inc	esi
1146
	add	esi,eax
1147
	jmp	simple_argument
1148
      argument_string:
2664 dunkaist 1149
	lods	dword [esi]
2665 dunkaist 1150
	add	esi,eax
1151
	jmp	simple_argument
1152
      argument_value_end:
2664 dunkaist 1153
	dec	esi
2665 dunkaist 1154
	ret
1155
      find_macro_block:
31 halyavin 1156
	add	esi,2
2665 dunkaist 1157
	lods	byte [esi]
1158
	or	al,al
1159
	jz	line_preprocessed
1160
	cmp	al,'{'
1161
	jne	unexpected_characters
1162
      found_macro_block:
31 halyavin 1163
	or	[macro_status],2
2665 dunkaist 1164
      skip_macro_block:
31 halyavin 1165
	lods	byte [esi]
2665 dunkaist 1166
	cmp	al,1Ah
1167
	je	skip_macro_symbol
1168
	cmp	al,3Bh
1169
	je	skip_macro_symbol
1170
	cmp	al,22h
1171
	je	skip_macro_string
1172
	or	al,al
1173
	jz	line_preprocessed
1174
	cmp	al,'}'
1175
	jne	skip_macro_block
1176
	mov	al,[macro_status]
1177
	and	[macro_status],0F0h
1178
	test	al,8
1179
	jnz	use_instant_macro
1180
	cmp	byte [esi],0
1181
	je	line_preprocessed
1182
	mov	ecx,edi
1183
	sub	ecx,esi
1184
	mov	edx,esi
1185
	lea	esi,[esi+ecx-1]
1186
	lea	edi,[edi+1+16]
1187
	mov	ebx,edi
1188
	dec	edi
1189
	std
1190
	rep	movs byte [edi],[esi]
1191
	cld
1192
	mov	edi,edx
1193
	xor	al,al
1194
	stos	byte [edi]
1195
	mov	esi,[current_line]
1196
	mov	[current_line],edi
1197
	mov	ecx,4
1198
	rep	movs dword [edi],[esi]
1199
	mov	edi,ebx
1200
	jmp	initial_preprocessing_ok
1201
      skip_macro_symbol:
31 halyavin 1202
	movzx	eax,byte [esi]
2665 dunkaist 1203
	inc	esi
1204
	add	esi,eax
1205
	jmp	skip_macro_block
1206
      skip_macro_string:
31 halyavin 1207
	lods	dword [esi]
2665 dunkaist 1208
	add	esi,eax
1209
	jmp	skip_macro_block
1210
postpone_directive:
4478 dunkaist 1211
	push	esi
1212
	mov	esi,edx
1213
	xor	ecx,ecx
1214
	call	add_preprocessor_symbol
1215
	mov	eax,[current_line]
1216
	mov	[error_line],eax
6467 dunkaist 1217
	mov	[edx+12],eax
4478 dunkaist 1218
	pop	esi
1219
	mov	[edx+8],esi
1220
	mov	al,[macro_status]
1221
	and	al,0F0h
1222
	or	al,1
1223
	mov	[macro_status],al
1224
	lods	byte [esi]
1225
	or	al,al
1226
	jz	line_preprocessed
1227
	cmp	al,'{'
1228
	jne	unexpected_characters
1229
	jmp	found_macro_block
1230
rept_directive:
31 halyavin 1231
	mov	[base_code],0
2665 dunkaist 1232
	jmp	define_instant_macro
1233
irp_directive:
31 halyavin 1234
	mov	[base_code],1
2665 dunkaist 1235
	jmp	define_instant_macro
1236
irps_directive:
31 halyavin 1237
	mov	[base_code],2
2665 dunkaist 1238
	jmp	define_instant_macro
1239
irpv_directive:
6467 dunkaist 1240
	mov	[base_code],3
1241
	jmp	define_instant_macro
1242
match_directive:
31 halyavin 1243
	mov	[base_code],10h
2665 dunkaist 1244
define_instant_macro:
31 halyavin 1245
	mov	al,[macro_status]
2665 dunkaist 1246
	and	al,0F0h
1247
	or	al,8+1
1248
	mov	[macro_status],al
1249
	mov	eax,[current_line]
1250
	mov	[error_line],eax
1251
	mov	[instant_macro_start],esi
1252
	cmp	[base_code],10h
1253
	je	prepare_match
1254
      skip_parameters:
1189 heavyiron 1255
	lods	byte [esi]
2665 dunkaist 1256
	or	al,al
1257
	jz	parameters_skipped
1258
	cmp	al,'{'
1259
	je	parameters_skipped
1260
	cmp	al,22h
1261
	je	skip_quoted_parameter
1262
	cmp	al,1Ah
1263
	jne	skip_parameters
1264
	lods	byte [esi]
1265
	movzx	eax,al
1266
	add	esi,eax
1267
	jmp	skip_parameters
1268
      skip_quoted_parameter:
1189 heavyiron 1269
	lods	dword [esi]
2665 dunkaist 1270
	add	esi,eax
1271
	jmp	skip_parameters
1272
      parameters_skipped:
1189 heavyiron 1273
	dec	esi
2665 dunkaist 1274
	mov	[parameters_end],esi
1275
	lods	byte [esi]
1276
	cmp	al,'{'
1277
	je	found_macro_block
1278
	or	al,al
1279
	jnz	invalid_macro_arguments
1280
	jmp	line_preprocessed
1281
prepare_match:
31 halyavin 1282
	call	skip_pattern
2665 dunkaist 1283
	mov	[value_type],80h+10b
1284
	call	process_symbolic_constants
1285
	jmp	parameters_skipped
1286
      skip_pattern:
31 halyavin 1287
	lods	byte [esi]
2665 dunkaist 1288
	or	al,al
1289
	jz	invalid_macro_arguments
1290
	cmp	al,','
1291
	je	pattern_skipped
1292
	cmp	al,22h
1293
	je	skip_quoted_string_in_pattern
1294
	cmp	al,1Ah
1295
	je	skip_symbol_in_pattern
1296
	cmp	al,'='
1297
	jne	skip_pattern
1298
	mov	al,[esi]
1299
	cmp	al,1Ah
1300
	je	skip_pattern
1301
	cmp	al,22h
1302
	je	skip_pattern
1303
	inc	esi
1304
	jmp	skip_pattern
1305
      skip_symbol_in_pattern:
31 halyavin 1306
	lods	byte [esi]
2665 dunkaist 1307
	movzx	eax,al
1308
	add	esi,eax
1309
	jmp	skip_pattern
1310
      skip_quoted_string_in_pattern:
31 halyavin 1311
	lods	dword [esi]
2665 dunkaist 1312
	add	esi,eax
1313
	jmp	skip_pattern
1314
      pattern_skipped:
31 halyavin 1315
	ret
2665 dunkaist 1316
31 halyavin 1317
 
1318
	xor	ch,ch
2665 dunkaist 1319
	jmp	restore_preprocessor_symbol
1320
purge_struc:
31 halyavin 1321
	mov	ch,1
2665 dunkaist 1322
	jmp	restore_preprocessor_symbol
1323
restore_equ_constant:
31 halyavin 1324
	mov	ch,10b
2665 dunkaist 1325
      restore_preprocessor_symbol:
31 halyavin 1326
	push	ecx
2665 dunkaist 1327
	lods	byte [esi]
1328
	cmp	al,1Ah
1329
	jne	invalid_name
1330
	lods	byte [esi]
1331
	mov	cl,al
1332
	call	get_preprocessor_symbol
1333
	jc	no_symbol_to_restore
1334
	mov	dword [edx+4],0
1335
	jmp	symbol_restored
1336
      no_symbol_to_restore:
31 halyavin 1337
	add	esi,ecx
2665 dunkaist 1338
      symbol_restored:
31 halyavin 1339
	pop	ecx
2665 dunkaist 1340
	lods	byte [esi]
1341
	cmp	al,','
1342
	je	restore_preprocessor_symbol
1343
	or	al,al
1344
	jnz	extra_characters_on_line
1345
	jmp	line_preprocessed
1346
31 halyavin 1347
 
1348
	mov	[value_type],11b
2665 dunkaist 1349
	jmp	process_symbolic_constants
1350
process_equ_constants:
31 halyavin 1351
	mov	[value_type],10b
2665 dunkaist 1352
      process_symbolic_constants:
31 halyavin 1353
	mov	ebp,esi
2665 dunkaist 1354
	lods	byte [esi]
1355
	cmp	al,1Ah
1356
	je	check_symbol
1357
	cmp	al,22h
1358
	je	ignore_string
1359
	cmp	al,'{'
1360
	je	check_brace
1361
	or	al,al
1362
	jnz	process_symbolic_constants
1363
	ret
1364
      ignore_string:
31 halyavin 1365
	lods	dword [esi]
2665 dunkaist 1366
	add	esi,eax
1367
	jmp	process_symbolic_constants
1368
      check_brace:
31 halyavin 1369
	test	[value_type],80h
2665 dunkaist 1370
	jz	process_symbolic_constants
1371
	ret
1372
      no_replacing:
31 halyavin 1373
	movzx	ecx,byte [esi-1]
2665 dunkaist 1374
	add	esi,ecx
1375
	jmp	process_symbolic_constants
1376
      check_symbol:
31 halyavin 1377
	mov	cl,[esi]
2665 dunkaist 1378
	inc	esi
1379
	mov	ch,[value_type]
1380
	call	get_preprocessor_symbol
1381
	jc	no_replacing
1382
	mov	[current_section],edi
1383
      replace_symbolic_constant:
31 halyavin 1384
	mov	ecx,[edx+12]
2665 dunkaist 1385
	mov	edx,[edx+8]
1386
	xchg	esi,edx
1387
	call	move_data
1388
	mov	esi,edx
1389
      process_after_replaced:
31 halyavin 1390
	lods	byte [esi]
2665 dunkaist 1391
	cmp	al,1Ah
1392
	je	symbol_after_replaced
1393
	stos	byte [edi]
1394
	cmp	al,22h
1395
	je	string_after_replaced
1396
	cmp	al,'{'
1397
	je	brace_after_replaced
1398
	or	al,al
1399
	jnz	process_after_replaced
1400
	mov	ecx,edi
1401
	sub	ecx,esi
1402
	mov	edi,ebp
1403
	call	move_data
1404
	mov	esi,edi
1405
	ret
1406
      move_data:
31 halyavin 1407
	lea	eax,[edi+ecx]
2665 dunkaist 1408
	cmp	eax,[memory_end]
1409
	jae	out_of_memory
1410
	shr	ecx,1
1411
	jnc	movsb_ok
1412
	movs	byte [edi],[esi]
1413
      movsb_ok:
31 halyavin 1414
	shr	ecx,1
2665 dunkaist 1415
	jnc	movsw_ok
1416
	movs	word [edi],[esi]
1417
      movsw_ok:
31 halyavin 1418
	rep	movs dword [edi],[esi]
2665 dunkaist 1419
	ret
1420
      string_after_replaced:
31 halyavin 1421
	lods	dword [esi]
2665 dunkaist 1422
	stos	dword [edi]
1423
	mov	ecx,eax
1424
	call	move_data
1425
	jmp	process_after_replaced
1426
      brace_after_replaced:
31 halyavin 1427
	test	[value_type],80h
2665 dunkaist 1428
	jz	process_after_replaced
1429
	mov	edx,edi
1430
	mov	ecx,[current_section]
1431
	sub	edx,ecx
1432
	sub	ecx,esi
1433
	rep	movs byte [edi],[esi]
1434
	mov	ecx,edi
1435
	sub	ecx,esi
1436
	mov	edi,ebp
1437
	call	move_data
1438
	lea	esi,[ebp+edx]
1439
	ret
1440
      symbol_after_replaced:
31 halyavin 1441
	mov	cl,[esi]
2665 dunkaist 1442
	inc	esi
1443
	mov	ch,[value_type]
1444
	call	get_preprocessor_symbol
1445
	jnc	replace_symbolic_constant
1446
	movzx	ecx,byte [esi-1]
1447
	mov	al,1Ah
1448
	mov	ah,cl
1449
	stos	word [edi]
1450
	call	move_data
1451
	jmp	process_after_replaced
1452
process_macro_operators:
31 halyavin 1453
	xor	dl,dl
2665 dunkaist 1454
	mov	ebp,edi
1455
      before_macro_operators:
31 halyavin 1456
	mov	edi,esi
2665 dunkaist 1457
	lods	byte [esi]
1458
	cmp	al,'`'
1459
	je	symbol_conversion
1460
	cmp	al,'#'
1461
	je	concatenation
1462
	cmp	al,1Ah
1463
	je	symbol_before_macro_operators
1464
	cmp	al,3Bh
1465
	je	no_more_macro_operators
1466
	cmp	al,22h
1467
	je	string_before_macro_operators
1468
	xor	dl,dl
1469
	or	al,al
1470
	jnz	before_macro_operators
1471
	mov	edi,esi
1472
	ret
1473
      no_more_macro_operators:
31 halyavin 1474
	mov	edi,ebp
2665 dunkaist 1475
	ret
1476
      symbol_before_macro_operators:
31 halyavin 1477
	mov	dl,1Ah
2665 dunkaist 1478
	mov	ebx,esi
1479
	lods	byte [esi]
1480
	movzx	ecx,al
1481
	jecxz	symbol_before_macro_operators_ok
1482
	mov	edi,esi
1483
	cmp	byte [esi],'\'
1484
	je	escaped_symbol
1485
      symbol_before_macro_operators_ok:
31 halyavin 1486
	add	esi,ecx
2665 dunkaist 1487
	jmp	before_macro_operators
1488
      string_before_macro_operators:
31 halyavin 1489
	mov	dl,22h
2665 dunkaist 1490
	mov	ebx,esi
1491
	lods	dword [esi]
1492
	add	esi,eax
1493
	jmp	before_macro_operators
1494
      escaped_symbol:
31 halyavin 1495
	dec	byte [edi-1]
2665 dunkaist 1496
	dec	ecx
1497
	inc	esi
1498
	cmp	ecx,1
1499
	rep	movs byte [edi],[esi]
1500
	jne	after_macro_operators
1501
	mov	al,[esi-1]
1502
	mov	ecx,ebx
1503
	mov	ebx,characters
1504
	xlat	byte [ebx]
1505
	mov	ebx,ecx
1506
	or	al,al
1507
	jnz	after_macro_operators
1508
	sub	edi,3
1509
	mov	al,[esi-1]
1510
	stos	byte [edi]
1511
	xor	dl,dl
1512
	jmp	after_macro_operators
1513
      reduce_symbol_conversion:
109 heavyiron 1514
	inc	esi
2665 dunkaist 1515
      symbol_conversion:
31 halyavin 1516
	mov	edx,esi
2665 dunkaist 1517
	mov	al,[esi]
1518
	cmp	al,1Ah
1519
	jne	symbol_character_conversion
1520
	lods	word [esi]
1521
	movzx	ecx,ah
1522
	lea	ebx,[edi+3]
1523
	jecxz	convert_to_quoted_string
1524
	cmp	byte [esi],'\'
1525
	jne	convert_to_quoted_string
1526
	inc	esi
1527
	dec	ecx
1528
	dec	ebx
1529
	jmp	convert_to_quoted_string
1530
      symbol_character_conversion:
109 heavyiron 1531
	cmp	al,22h
2665 dunkaist 1532
	je	after_macro_operators
1533
	cmp	al,'`'
1534
	je	reduce_symbol_conversion
1535
	lea	ebx,[edi+5]
1536
	xor	ecx,ecx
1537
	or	al,al
1538
	jz	convert_to_quoted_string
1539
	cmp	al,'#'
1540
	je	convert_to_quoted_string
1541
	inc	ecx
1542
      convert_to_quoted_string:
109 heavyiron 1543
	sub	ebx,edx
2665 dunkaist 1544
	ja	shift_line_data
1545
	mov	al,22h
1546
	mov	dl,al
1547
	stos	byte [edi]
1548
	mov	ebx,edi
1549
	mov	eax,ecx
1550
	stos	dword [edi]
1551
	rep	movs byte [edi],[esi]
1552
	cmp	edi,esi
1553
	je	before_macro_operators
1554
	jmp	after_macro_operators
1555
      shift_line_data:
31 halyavin 1556
	push	ecx
2665 dunkaist 1557
	mov	edx,esi
1558
	lea	esi,[ebp-1]
1559
	add	ebp,ebx
1560
	lea	edi,[ebp-1]
1561
	lea	ecx,[esi+1]
1562
	sub	ecx,edx
1563
	std
1564
	rep	movs byte [edi],[esi]
1565
	cld
1566
	pop	eax
1567
	sub	edi,3
1568
	mov	dl,22h
1569
	mov	[edi-1],dl
1570
	mov	ebx,edi
1571
	mov	[edi],eax
1572
	lea	esi,[edi+4+eax]
1573
	jmp	before_macro_operators
1574
      concatenation:
31 halyavin 1575
	cmp	dl,1Ah
2665 dunkaist 1576
	je	symbol_concatenation
1577
	cmp	dl,22h
1578
	je	string_concatenation
1579
      no_concatenation:
31 halyavin 1580
	cmp	esi,edi
2665 dunkaist 1581
	je	before_macro_operators
1582
	jmp	after_macro_operators
1583
      symbol_concatenation:
31 halyavin 1584
	cmp	byte [esi],1Ah
2665 dunkaist 1585
	jne	no_concatenation
1586
	inc	esi
1587
	lods	byte [esi]
1588
	movzx	ecx,al
1589
	jecxz	do_symbol_concatenation
1590
	cmp	byte [esi],'\'
1591
	je	concatenate_escaped_symbol
1592
      do_symbol_concatenation:
31 halyavin 1593
	add	[ebx],cl
2665 dunkaist 1594
	jc	name_too_long
1595
	rep	movs byte [edi],[esi]
1596
	jmp	after_macro_operators
1597
      concatenate_escaped_symbol:
242 heavyiron 1598
	inc	esi
2665 dunkaist 1599
	dec	ecx
1600
	jz	do_symbol_concatenation
1601
	movzx	eax,byte [esi]
1602
	cmp	byte [characters+eax],0
1603
	jne	do_symbol_concatenation
1604
	sub	esi,3
1605
	jmp	no_concatenation
1606
      string_concatenation:
31 halyavin 1607
	cmp	byte [esi],22h
2665 dunkaist 1608
	je	do_string_concatenation
1609
	cmp	byte [esi],'`'
1610
	jne	no_concatenation
1611
      concatenate_converted_symbol:
109 heavyiron 1612
	inc	esi
2665 dunkaist 1613
	mov	al,[esi]
1614
	cmp	al,'`'
1615
	je	concatenate_converted_symbol
1616
	cmp	al,22h
1617
	je	do_string_concatenation
1618
	cmp	al,1Ah
1619
	jne	concatenate_converted_symbol_character
1620
	inc	esi
1621
	lods	byte [esi]
1622
	movzx	ecx,al
1623
	jecxz	finish_concatenating_converted_symbol
1624
	cmp	byte [esi],'\'
1625
	jne	finish_concatenating_converted_symbol
1626
	inc	esi
1627
	dec	ecx
1628
      finish_concatenating_converted_symbol:
242 heavyiron 1629
	add	[ebx],ecx
2665 dunkaist 1630
	rep	movs byte [edi],[esi]
1631
	jmp	after_macro_operators
1632
      concatenate_converted_symbol_character:
109 heavyiron 1633
	or	al,al
2665 dunkaist 1634
	jz	after_macro_operators
1635
	cmp	al,'#'
1636
	je	after_macro_operators
1637
	inc	dword [ebx]
1638
	movs	byte [edi],[esi]
1639
	jmp	after_macro_operators
1640
      do_string_concatenation:
31 halyavin 1641
	inc	esi
2665 dunkaist 1642
	lods	dword [esi]
1643
	mov	ecx,eax
1644
	add	[ebx],eax
1645
	rep	movs byte [edi],[esi]
1646
      after_macro_operators:
31 halyavin 1647
	lods	byte [esi]
2665 dunkaist 1648
	cmp	al,'`'
1649
	je	symbol_conversion
1650
	cmp	al,'#'
1651
	je	concatenation
1652
	stos	byte [edi]
1653
	cmp	al,1Ah
1654
	je	symbol_after_macro_operators
1655
	cmp	al,3Bh
1656
	je	no_more_macro_operators
1657
	cmp	al,22h
1658
	je	string_after_macro_operators
1659
	xor	dl,dl
1660
	or	al,al
1661
	jnz	after_macro_operators
1662
	ret
1663
      symbol_after_macro_operators:
31 halyavin 1664
	mov	dl,1Ah
2665 dunkaist 1665
	mov	ebx,edi
1666
	lods	byte [esi]
1667
	stos	byte [edi]
1668
	movzx	ecx,al
1669
	jecxz	symbol_after_macro_operatorss_ok
1670
	cmp	byte [esi],'\'
1671
	je	escaped_symbol
1672
      symbol_after_macro_operatorss_ok:
31 halyavin 1673
	rep	movs byte [edi],[esi]
2665 dunkaist 1674
	jmp	after_macro_operators
1675
      string_after_macro_operators:
31 halyavin 1676
	mov	dl,22h
2665 dunkaist 1677
	mov	ebx,edi
1678
	lods	dword [esi]
1679
	stos	dword [edi]
1680
	mov	ecx,eax
1681
	rep	movs byte [edi],[esi]
1682
	jmp	after_macro_operators
1683
31 halyavin 1684
 
1685
	push	[free_additional_memory]
2665 dunkaist 1686
	push	[macro_symbols]
1687
	mov	[macro_symbols],0
1688
	push	[counter_limit]
1689
	push	dword [edx+4]
1690
	mov	dword [edx+4],1
1691
	push	edx
1692
	mov	ebx,esi
1693
	mov	esi,[edx+8]
1694
	mov	eax,[edx+12]
1695
	mov	[macro_line],eax
1696
	mov	[counter_limit],0
1697
	xor	ebp,ebp
1698
      process_macro_arguments:
31 halyavin 1699
	mov	al,[esi]
2665 dunkaist 1700
	or	al,al
1701
	jz	arguments_end
1702
	cmp	al,'{'
1703
	je	arguments_end
1704
	inc	esi
1705
	cmp	al,'['
1706
	jne	get_macro_arguments
1707
	mov	ebp,esi
1708
	inc	esi
1709
	inc	[counter_limit]
1710
      get_macro_arguments:
31 halyavin 1711
	call	get_macro_argument
2665 dunkaist 1712
	lods	byte [esi]
1713
	cmp	al,','
1714
	je	next_argument
1715
	cmp	al,']'
1716
	je	next_arguments_group
1717
	cmp	al,'&'
6467 dunkaist 1718
	je	arguments_end
1719
	dec	esi
2665 dunkaist 1720
	jmp	arguments_end
1721
      next_argument:
31 halyavin 1722
	cmp	byte [ebx],','
2665 dunkaist 1723
	jne	process_macro_arguments
1724
	inc	ebx
1725
	jmp	process_macro_arguments
1726
      next_arguments_group:
31 halyavin 1727
	cmp	byte [ebx],','
2665 dunkaist 1728
	jne	arguments_end
1729
	inc	ebx
1730
	inc	[counter_limit]
1731
	mov	esi,ebp
1732
	jmp	process_macro_arguments
1733
      get_macro_argument:
31 halyavin 1734
	lods	byte [esi]
2665 dunkaist 1735
	movzx	ecx,al
1736
	mov	eax,[counter_limit]
1737
	call	add_macro_symbol
1738
	add	esi,ecx
1739
	xor	eax,eax
6467 dunkaist 1740
	mov	[default_argument_value],eax
1741
	cmp	byte [esi],'*'
1742
	je	required_value
1743
	cmp	byte [esi],':'
1744
	je	get_default_value
1745
	cmp	byte [esi],'='
1746
	jne	default_value_ok
1747
      get_default_value:
1748
	inc	esi
1749
	mov	[default_argument_value],esi
1750
	or	[skip_default_argument_value],-1
1751
	call	skip_macro_argument_value
1752
	jmp	default_value_ok
1753
      required_value:
1754
	inc	esi
1755
	or	[default_argument_value],-1
1756
      default_value_ok:
1757
	xchg	esi,ebx
2665 dunkaist 1758
	mov	[edx+12],esi
1759
	mov	[skip_default_argument_value],0
6467 dunkaist 1760
	cmp	byte [ebx],'&'
1761
	je	greedy_macro_argument
1762
	call	skip_macro_argument_value
2665 dunkaist 1763
	call	finish_macro_argument
1764
	jmp	got_macro_argument
6467 dunkaist 1765
      greedy_macro_argument:
1766
	call	skip_foreign_line
1767
	dec	esi
1768
	mov	eax,[edx+12]
1769
	mov	ecx,esi
1770
	sub	ecx,eax
1771
	mov	[edx+8],ecx
1772
      got_macro_argument:
1773
	xchg	esi,ebx
2665 dunkaist 1774
	cmp	dword [edx+8],0
6467 dunkaist 1775
	jne	macro_argument_ok
2665 dunkaist 1776
	mov	eax,[default_argument_value]
6467 dunkaist 1777
	or	eax,eax
1778
	jz	macro_argument_ok
1779
	cmp	eax,-1
1780
	je	invalid_macro_arguments
2665 dunkaist 1781
	mov	[edx+12],eax
6467 dunkaist 1782
	call	finish_macro_argument
1783
      macro_argument_ok:
31 halyavin 1784
	ret
2665 dunkaist 1785
      finish_macro_argument:
2664 dunkaist 1786
	mov	eax,[edx+12]
2665 dunkaist 1787
	mov	ecx,esi
1788
	sub	ecx,eax
1789
	cmp	byte [eax],'<'
1790
	jne	argument_value_length_ok
1791
	inc	dword [edx+12]
1792
	sub	ecx,2
1793
	or	ecx,80000000h
1794
      argument_value_length_ok:
2664 dunkaist 1795
	mov	[edx+8],ecx
2665 dunkaist 1796
	ret
1797
      arguments_end:
31 halyavin 1798
	cmp	byte [ebx],0
2665 dunkaist 1799
	jne	invalid_macro_arguments
1800
	mov	eax,[esp+4]
1801
	dec	eax
1802
	call	process_macro
1803
	pop	edx
1804
	pop	dword [edx+4]
1805
	pop	[counter_limit]
1806
	pop	[macro_symbols]
1807
	pop	[free_additional_memory]
1808
	jmp	line_preprocessed
1809
use_instant_macro:
31 halyavin 1810
	push	edi [current_line] esi
2665 dunkaist 1811
	mov	eax,[error_line]
1812
	mov	[current_line],eax
1813
	mov	[macro_line],eax
1814
	mov	esi,[instant_macro_start]
1815
	cmp	[base_code],10h
1816
	jae	do_match
1817
	cmp	[base_code],0
1818
	jne	do_irp
1819
	call	precalculate_value
1820
	cmp	eax,0
1821
	jl	value_out_of_range
1822
	push	[free_additional_memory]
1823
	push	[macro_symbols]
1824
	mov	[macro_symbols],0
1825
	push	[counter_limit]
1826
	mov	[struc_name],0
1827
	mov	[counter_limit],eax
1828
	lods	byte [esi]
1829
	or	al,al
1830
	jz	rept_counters_ok
1831
	cmp	al,'{'
1832
	je	rept_counters_ok
1833
	cmp	al,1Ah
1834
	jne	invalid_macro_arguments
1835
      add_rept_counter:
31 halyavin 1836
	lods	byte [esi]
2665 dunkaist 1837
	movzx	ecx,al
1838
	xor	eax,eax
1839
	call	add_macro_symbol
1840
	add	esi,ecx
1841
	xor	eax,eax
1842
	mov	dword [edx+12],eax
1843
	inc	eax
1844
	mov	dword [edx+8],eax
1845
	lods	byte [esi]
1846
	cmp	al,':'
1847
	jne	rept_counter_added
1848
	push	edx
1849
	call	precalculate_value
1850
	mov	edx,eax
1851
	add	edx,[counter_limit]
1852
	jo	value_out_of_range
1853
	pop	edx
1854
	mov	dword [edx+8],eax
1855
	lods	byte [esi]
1856
      rept_counter_added:
31 halyavin 1857
	cmp	al,','
2665 dunkaist 1858
	jne	rept_counters_ok
1859
	lods	byte [esi]
1860
	cmp	al,1Ah
1861
	jne	invalid_macro_arguments
1862
	jmp	add_rept_counter
1863
      rept_counters_ok:
31 halyavin 1864
	dec	esi
2665 dunkaist 1865
	cmp	[counter_limit],0
1866
	je	instant_macro_finish
1867
      instant_macro_parameters_ok:
31 halyavin 1868
	xor	eax,eax
2665 dunkaist 1869
	call	process_macro
1870
      instant_macro_finish:
872 heavyiron 1871
	pop	[counter_limit]
2665 dunkaist 1872
	pop	[macro_symbols]
1873
	pop	[free_additional_memory]
1874
      instant_macro_done:
31 halyavin 1875
	pop	ebx esi edx
2665 dunkaist 1876
	cmp	byte [ebx],0
1877
	je	line_preprocessed
1878
	mov	[current_line],edi
1879
	mov	ecx,4
1880
	rep	movs dword [edi],[esi]
1881
	test	[macro_status],0Fh
1882
	jz	instant_macro_attached_line
1883
	mov	ax,3Bh
1884
	stos	word [edi]
1885
      instant_macro_attached_line:
31 halyavin 1886
	mov	esi,ebx
2665 dunkaist 1887
	sub	edx,ebx
1888
	mov	ecx,edx
1889
	call	move_data
1890
	jmp	initial_preprocessing_ok
1891
      precalculate_value:
1189 heavyiron 1892
	push	edi
2665 dunkaist 1893
	call	convert_expression
1894
	mov	al,')'
1895
	stosb
1896
	push	esi
1897
	mov	esi,[esp+4]
1898
	mov	[error_line],0
1899
	mov	[value_size],0
1900
	call	calculate_expression
1901
	cmp	[error_line],0
1902
	je	value_precalculated
1903
	jmp	[error]
1904
      value_precalculated:
1905
	mov	eax,[edi]
1906
	mov	ecx,[edi+4]
1907
	cdq
1908
	cmp	edx,ecx
1909
	jne	value_out_of_range
1910
	cmp	dl,[edi+13]
1911
	jne	value_out_of_range
1912
	pop	esi edi
1913
	ret
1914
do_irp:
31 halyavin 1915
	cmp	byte [esi],1Ah
2665 dunkaist 1916
	jne	invalid_macro_arguments
1917
	movzx	eax,byte [esi+1]
1918
	lea	esi,[esi+2+eax]
1919
	lods	byte [esi]
1920
	cmp	[base_code],1
1921
	ja	irps_name_ok
1922
	cmp	al,':'
6467 dunkaist 1923
	je	irp_with_default_value
1924
	cmp	al,'='
2665 dunkaist 1925
	je	irp_with_default_value
1926
	cmp	al,'*'
1927
	jne	irp_name_ok
1928
	lods	byte [esi]
1929
      irp_name_ok:
31 halyavin 1930
	cmp	al,','
2665 dunkaist 1931
	jne	invalid_macro_arguments
1932
	jmp	irp_parameters_start
1933
      irp_with_default_value:
2664 dunkaist 1934
	xor	ebp,ebp
2665 dunkaist 1935
	or	[skip_default_argument_value],-1
6467 dunkaist 1936
	call	skip_macro_argument_value
2665 dunkaist 1937
	cmp	byte [esi],','
6467 dunkaist 1938
	jne	invalid_macro_arguments
1939
	inc	esi
2665 dunkaist 1940
	jmp	irp_parameters_start
4039 heavyiron 1941
      irps_name_ok:
31 halyavin 1942
	cmp	al,','
2665 dunkaist 1943
	jne	invalid_macro_arguments
1944
	cmp	[base_code],3
6467 dunkaist 1945
	je	irp_parameters_start
1946
	mov	al,[esi]
2665 dunkaist 1947
	or	al,al
1948
	jz	instant_macro_done
1949
	cmp	al,'{'
1950
	je	instant_macro_done
1951
      irp_parameters_start:
31 halyavin 1952
	xor	eax,eax
2665 dunkaist 1953
	push	[free_additional_memory]
1954
	push	[macro_symbols]
1955
	mov	[macro_symbols],eax
1956
	push	[counter_limit]
1957
	mov	[counter_limit],eax
1958
	mov	[struc_name],eax
1959
	cmp	[base_code],3
6467 dunkaist 1960
	je	get_irpv_parameter
1961
	mov	ebx,esi
2665 dunkaist 1962
	cmp	[base_code],2
6467 dunkaist 1963
	je	get_irps_parameter
1964
	mov	edx,[parameters_end]
2665 dunkaist 1965
	mov	al,[edx]
1966
	push	eax
1967
	mov	byte [edx],0
1968
      get_irp_parameter:
31 halyavin 1969
	inc	[counter_limit]
2665 dunkaist 1970
	mov	esi,[instant_macro_start]
1971
	inc	esi
1972
	call	get_macro_argument
1973
	cmp	byte [ebx],','
1974
	jne	irp_parameters_end
1975
	inc	ebx
1976
	jmp	get_irp_parameter
1977
      irp_parameters_end:
31 halyavin 1978
	mov	esi,ebx
2665 dunkaist 1979
	pop	eax
1980
	mov	[esi],al
1981
	jmp	instant_macro_parameters_ok
1982
      get_irps_parameter:
31 halyavin 1983
	mov	esi,[instant_macro_start]
2665 dunkaist 1984
	inc	esi
1985
	lods	byte [esi]
1986
	movzx	ecx,al
1987
	inc	[counter_limit]
1988
	mov	eax,[counter_limit]
1989
	call	add_macro_symbol
1990
	mov	[edx+12],ebx
1991
	cmp	byte [ebx],1Ah
1992
	je	irps_symbol
1993
	cmp	byte [ebx],22h
1994
	je	irps_quoted_string
1995
	mov	eax,1
1996
	jmp	irps_parameter_ok
1997
      irps_quoted_string:
31 halyavin 1998
	mov	eax,[ebx+1]
2665 dunkaist 1999
	add	eax,1+4
2000
	jmp	irps_parameter_ok
2001
      irps_symbol:
31 halyavin 2002
	movzx	eax,byte [ebx+1]
2665 dunkaist 2003
	add	eax,1+1
2004
      irps_parameter_ok:
31 halyavin 2005
	mov	[edx+8],eax
2665 dunkaist 2006
	add	ebx,eax
2007
	cmp	byte [ebx],0
2008
	je	irps_parameters_end
2009
	cmp	byte [ebx],'{'
2010
	jne	get_irps_parameter
2011
      irps_parameters_end:
31 halyavin 2012
	mov	esi,ebx
2665 dunkaist 2013
	jmp	instant_macro_parameters_ok
2014
      get_irpv_parameter:
6467 dunkaist 2015
	lods	byte [esi]
2016
	cmp	al,1Ah
2017
	jne	invalid_macro_arguments
2018
	lods	byte [esi]
2019
	mov	ebp,esi
2020
	mov	cl,al
2021
	mov	ch,10b
2022
	call	get_preprocessor_symbol
2023
	jc	instant_macro_finish
2024
	push	edx
2025
      mark_variable_value:
2026
	inc	[counter_limit]
2027
	mov	[edx+4],ebp
2028
      next_variable_value:
2029
	mov	edx,[edx]
2030
	or	edx,edx
2031
	jz	variable_values_marked
2032
	mov	eax,[edx+4]
2033
	cmp	eax,1
2034
	jbe	next_variable_value
2035
	mov	esi,ebp
2036
	movzx	ecx,byte [esi-1]
2037
	xchg	edi,eax
2038
	repe	cmps byte [esi],[edi]
2039
	xchg	edi,eax
2040
	je	mark_variable_value
2041
	jmp	next_variable_value
2042
      variable_values_marked:
2043
	pop	edx
2044
	push	[counter_limit]
2045
      add_irpv_value:
2046
	push	edx
2047
	mov	esi,[instant_macro_start]
2048
	inc	esi
2049
	lods	byte [esi]
2050
	movzx	ecx,al
2051
	mov	eax,[esp+4]
2052
	call	add_macro_symbol
2053
	mov	ebx,edx
2054
	pop	edx
2055
	mov	ecx,[edx+12]
2056
	mov	eax,[edx+8]
2057
	mov	[ebx+12],eax
2058
	mov	[ebx+8],ecx
2059
      collect_next_variable_value:
2060
	mov	edx,[edx]
2061
	or	edx,edx
2062
	jz	variable_values_collected
2063
	cmp	ebp,[edx+4]
2064
	jne	collect_next_variable_value
2065
	dec	dword [esp]
2066
	jnz	add_irpv_value
2067
      variable_values_collected:
2068
	pop	eax
2069
	mov	esi,ebp
2070
	movzx	ecx,byte [esi-1]
2071
	add	esi,ecx
2072
	cmp	byte [esi],0
2073
	je	instant_macro_parameters_ok
2074
	cmp	byte [esi],'{'
2075
	jne	invalid_macro_arguments
2076
	jmp	instant_macro_parameters_ok
2077
2078
 
31 halyavin 2079
	mov	ebx,esi
2665 dunkaist 2080
	call	skip_pattern
2081
	call	exact_match
2082
	mov	edx,edi
2083
	mov	al,[ebx]
2084
	cmp	al,1Ah
2085
	je	free_match
2086
	cmp	al,','
2087
	jne	instant_macro_done
2088
	cmp	esi,[parameters_end]
2089
	je	matched_pattern
2090
	jmp	instant_macro_done
2091
      free_match:
31 halyavin 2092
	add	edx,12
2665 dunkaist 2093
	cmp	edx,[memory_end]
2094
	ja	out_of_memory
2095
	mov	[edx-12],ebx
2096
	mov	[edx-8],esi
2097
	call	skip_match_element
2098
	jc	try_different_matching
2099
	mov	[edx-4],esi
2100
	movzx	eax,byte [ebx+1]
2101
	lea	ebx,[ebx+2+eax]
2102
	cmp	byte [ebx],1Ah
2103
	je	free_match
2104
      find_exact_match:
31 halyavin 2105
	call	exact_match
2665 dunkaist 2106
	cmp	esi,[parameters_end]
2107
	je	end_matching
2108
	cmp	byte [ebx],1Ah
2109
	je	free_match
2110
	mov	ebx,[edx-12]
2111
	movzx	eax,byte [ebx+1]
2112
	lea	ebx,[ebx+2+eax]
2113
	mov	esi,[edx-4]
2114
	jmp	match_more_elements
2115
      try_different_matching:
31 halyavin 2116
	sub	edx,12
2665 dunkaist 2117
	cmp	edx,edi
2118
	je	instant_macro_done
2119
	mov	ebx,[edx-12]
2120
	movzx	eax,byte [ebx+1]
2121
	lea	ebx,[ebx+2+eax]
2122
	cmp	byte [ebx],1Ah
2123
	je	try_different_matching
2124
	mov	esi,[edx-4]
2125
      match_more_elements:
31 halyavin 2126
	call	skip_match_element
2665 dunkaist 2127
	jc	try_different_matching
2128
	mov	[edx-4],esi
2129
	jmp	find_exact_match
2130
      skip_match_element:
31 halyavin 2131
	cmp	esi,[parameters_end]
2665 dunkaist 2132
	je	cannot_match
2133
	mov	al,[esi]
2134
	cmp	al,1Ah
2135
	je	skip_match_symbol
2136
	cmp	al,22h
2137
	je	skip_match_quoted_string
2138
	add	esi,1
2139
	ret
2140
      skip_match_quoted_string:
31 halyavin 2141
	mov	eax,[esi+1]
2665 dunkaist 2142
	add	esi,5
2143
	jmp	skip_match_ok
2144
      skip_match_symbol:
31 halyavin 2145
	movzx	eax,byte [esi+1]
2665 dunkaist 2146
	add	esi,2
2147
      skip_match_ok:
31 halyavin 2148
	add	esi,eax
2665 dunkaist 2149
	ret
2150
      cannot_match:
31 halyavin 2151
	stc
2665 dunkaist 2152
	ret
2153
      exact_match:
31 halyavin 2154
	cmp	esi,[parameters_end]
2665 dunkaist 2155
	je	exact_match_complete
2156
	mov	ah,[esi]
2157
	mov	al,[ebx]
2158
	cmp	al,','
2159
	je	exact_match_complete
2160
	cmp	al,1Ah
2161
	je	exact_match_complete
2162
	cmp	al,'='
2163
	je	match_verbatim
2164
	call	match_elements
2165
	je	exact_match
2166
      exact_match_complete:
31 halyavin 2167
	ret
2665 dunkaist 2168
      match_verbatim:
31 halyavin 2169
	inc	ebx
2665 dunkaist 2170
	call	match_elements
2171
	je	exact_match
2172
	dec	ebx
2173
	ret
2174
      match_elements:
31 halyavin 2175
	mov	al,[ebx]
2665 dunkaist 2176
	cmp	al,1Ah
2177
	je	match_symbols
2178
	cmp	al,22h
2179
	je	match_quoted_strings
2180
	cmp	al,ah
2181
	je	symbol_characters_matched
2182
	ret
2183
      symbol_characters_matched:
31 halyavin 2184
	lea	ebx,[ebx+1]
2665 dunkaist 2185
	lea	esi,[esi+1]
2186
	ret
2187
      match_quoted_strings:
31 halyavin 2188
	mov	ecx,[ebx+1]
2665 dunkaist 2189
	add	ecx,5
2190
	jmp	compare_elements
2191
      match_symbols:
31 halyavin 2192
	movzx	ecx,byte [ebx+1]
2665 dunkaist 2193
	add	ecx,2
2194
      compare_elements:
31 halyavin 2195
	mov	eax,esi
2665 dunkaist 2196
	mov	ebp,edi
2197
	mov	edi,ebx
2198
	repe	cmps byte [esi],[edi]
2199
	jne	elements_mismatch
2200
	mov	ebx,edi
2201
	mov	edi,ebp
2202
	ret
2203
      elements_mismatch:
31 halyavin 2204
	mov	esi,eax
2665 dunkaist 2205
	mov	edi,ebp
2206
	ret
2207
      end_matching:
31 halyavin 2208
	cmp	byte [ebx],','
2665 dunkaist 2209
	jne	instant_macro_done
2210
      matched_pattern:
31 halyavin 2211
	xor	eax,eax
2665 dunkaist 2212
	push	[free_additional_memory]
2213
	push	[macro_symbols]
2214
	mov	[macro_symbols],eax
2215
	push	[counter_limit]
2216
	mov	[counter_limit],eax
2217
	mov	[struc_name],eax
2218
	push	esi edi edx
2219
      add_matched_symbol:
31 halyavin 2220
	cmp	edi,[esp]
2665 dunkaist 2221
	je	matched_symbols_ok
2222
	mov	esi,[edi]
2223
	inc	esi
2224
	lods	byte [esi]
2225
	movzx	ecx,al
2226
	xor	eax,eax
2227
	call	add_macro_symbol
2228
	mov	eax,[edi+4]
2229
	mov	dword [edx+12],eax
2230
	mov	ecx,[edi+8]
2231
	sub	ecx,eax
2232
	mov	dword [edx+8],ecx
2233
	add	edi,12
2234
	jmp	add_matched_symbol
2235
      matched_symbols_ok:
31 halyavin 2236
	pop	edx edi esi
2665 dunkaist 2237
	jmp	instant_macro_parameters_ok
2238
31 halyavin 2239
 
2240
	push	dword [macro_status]
2665 dunkaist 2241
	or	[macro_status],10h
2242
	push	[counter]
2243
	push	[macro_block]
2244
	push	[macro_block_line]
2245
	push	[macro_block_line_number]
2246
	push	[struc_label]
2247
	push	[struc_name]
2248
	push	eax
2249
	push	[current_line]
2250
	lods	byte [esi]
2251
	cmp	al,'{'
2252
	je	macro_instructions_start
2253
	or	al,al
2254
	jnz	unexpected_characters
2255
      find_macro_instructions:
31 halyavin 2256
	mov	[macro_line],esi
2665 dunkaist 2257
	add	esi,16+2
2258
	lods	byte [esi]
2259
	or	al,al
2260
	jz	find_macro_instructions
2261
	cmp	al,'{'
2262
	je	macro_instructions_start
2263
	cmp	al,3Bh
2264
	jne	unexpected_characters
2265
	call	skip_foreign_symbol
2266
	jmp	find_macro_instructions
2267
      macro_instructions_start:
31 halyavin 2268
	mov	ecx,80000000h
2665 dunkaist 2269
	mov	[macro_block],esi
2270
	mov	eax,[macro_line]
2271
	mov	[macro_block_line],eax
2272
	mov	[macro_block_line_number],ecx
2273
	xor	eax,eax
2274
	mov	[counter],eax
2275
	cmp	[counter_limit],eax
2276
	je	process_macro_line
2277
	inc	[counter]
2278
      process_macro_line:
31 halyavin 2279
	lods	byte [esi]
2665 dunkaist 2280
	or	al,al
2281
	jz	process_next_line
2282
	cmp	al,'}'
2283
	je	macro_block_processed
2284
	dec	esi
2285
	mov	[current_line],edi
2286
	lea	eax,[edi+10h]
2287
	cmp	eax,[memory_end]
2288
	jae	out_of_memory
2289
	mov	eax,[esp+4]
2290
	or	eax,eax
2291
	jz	instant_macro_line_header
2292
	stos	dword [edi]
2293
	mov	eax,ecx
2294
	stos	dword [edi]
2295
	mov	eax,[esp]
2296
	stos	dword [edi]
2297
	mov	eax,[macro_line]
2298
	stos	dword [edi]
2299
	jmp	macro_line_header_ok
2300
      instant_macro_line_header:
31 halyavin 2301
	mov	eax,[esp]
4478 dunkaist 2302
	add	eax,16
2303
      find_defining_directive:
2304
	inc	eax
2305
	cmp	byte [eax-1],3Bh
2306
	je	defining_directive_ok
2307
	cmp	byte [eax-1],1Ah
2308
	jne	find_defining_directive
2309
	push	eax
2310
	movzx	eax,byte [eax]
2311
	inc	eax
2312
	add	[esp],eax
2313
	pop	eax
2314
	jmp	find_defining_directive
2315
      defining_directive_ok:
2316
	stos	dword [edi]
2665 dunkaist 2317
	mov	eax,ecx
2318
	stos	dword [edi]
2319
	mov	eax,[macro_line]
2320
	stos	dword [edi]
2321
	stos	dword [edi]
2322
      macro_line_header_ok:
31 halyavin 2323
	or	[macro_status],20h
2665 dunkaist 2324
	push	ebx ecx
2325
	test	[macro_status],0Fh
2326
	jz	process_macro_line_element
2327
	mov	ax,3Bh
2328
	stos	word [edi]
2329
      process_macro_line_element:
31 halyavin 2330
	lea	eax,[edi+100h]
2665 dunkaist 2331
	cmp	eax,[memory_end]
2332
	jae	out_of_memory
2333
	lods	byte [esi]
2334
	cmp	al,'}'
2335
	je	macro_line_processed
2336
	or	al,al
2337
	jz	macro_line_processed
2338
	cmp	al,1Ah
2339
	je	process_macro_symbol
2340
	cmp	al,3Bh
2341
	je	macro_foreign_line
2342
	and	[macro_status],not 20h
2343
	stos	byte [edi]
2344
	cmp	al,22h
2345
	jne	process_macro_line_element
2346
      copy_macro_string:
31 halyavin 2347
	mov	ecx,[esi]
2665 dunkaist 2348
	add	ecx,4
2349
	call	move_data
2350
	jmp	process_macro_line_element
2351
      process_macro_symbol:
31 halyavin 2352
	push	esi edi
2665 dunkaist 2353
	test	[macro_status],20h
2354
	jz	not_macro_directive
2355
	movzx	ecx,byte [esi]
2356
	inc	esi
2357
	mov	edi,macro_directives
2358
	call	get_directive
2359
	jnc	process_macro_directive
2360
	dec	esi
2361
	jmp	not_macro_directive
2362
      process_macro_directive:
31 halyavin 2363
	mov	edx,eax
2665 dunkaist 2364
	pop	edi eax
2365
	mov	byte [edi],0
2366
	inc	edi
2367
	pop	ecx ebx
2368
	jmp	near edx
2369
      not_macro_directive:
31 halyavin 2370
	and	[macro_status],not 20h
2665 dunkaist 2371
	movzx	ecx,byte [esi]
2372
	inc	esi
2373
	mov	eax,[counter]
2374
	call	get_macro_symbol
2375
	jnc	group_macro_symbol
2376
	xor	eax,eax
2377
	cmp	[counter],eax
2378
	je	multiple_macro_symbol_values
2379
	call	get_macro_symbol
2380
	jc	not_macro_symbol
2381
      replace_macro_symbol:
31 halyavin 2382
	pop	edi eax
2665 dunkaist 2383
	mov	ecx,[edx+8]
2384
	mov	edx,[edx+12]
2385
	or	edx,edx
2386
	jz	replace_macro_counter
2387
	and	ecx,not 80000000h
2388
	xchg	esi,edx
2389
	call	move_data
2390
	mov	esi,edx
2391
	jmp	process_macro_line_element
2392
      group_macro_symbol:
31 halyavin 2393
	xor	eax,eax
2665 dunkaist 2394
	cmp	[counter],eax
2395
	je	replace_macro_symbol
2396
	push	esi edx
2397
	sub	esi,ecx
2398
	call	get_macro_symbol
2399
	mov	ebx,edx
2400
	pop	edx esi
2401
	jc	replace_macro_symbol
2402
	cmp	edx,ebx
2403
	ja	replace_macro_symbol
2404
	mov	edx,ebx
2405
	jmp	replace_macro_symbol
2406
      multiple_macro_symbol_values:
31 halyavin 2407
	inc	eax
2665 dunkaist 2408
	push	eax
2409
	call	get_macro_symbol
2410
	pop	eax
2411
	jc	not_macro_symbol
2412
	pop	edi
2413
	push	ecx
2414
	mov	ecx,[edx+8]
2415
	mov	edx,[edx+12]
2416
	xchg	esi,edx
2417
	btr	ecx,31
2418
	jc	enclose_macro_symbol_value
2419
	rep	movs byte [edi],[esi]
2420
	jmp	macro_symbol_value_ok
2421
      enclose_macro_symbol_value:
31 halyavin 2422
	mov	byte [edi],'<'
2665 dunkaist 2423
	inc	edi
2424
	rep	movs byte [edi],[esi]
2425
	mov	byte [edi],'>'
2426
	inc	edi
2427
      macro_symbol_value_ok:
31 halyavin 2428
	cmp	eax,[counter_limit]
2665 dunkaist 2429
	je	multiple_macro_symbol_values_ok
2430
	mov	byte [edi],','
2431
	inc	edi
2432
	mov	esi,edx
2433
	pop	ecx
2434
	push	edi
2435
	sub	esi,ecx
2436
	jmp	multiple_macro_symbol_values
2437
      multiple_macro_symbol_values_ok:
31 halyavin 2438
	pop	ecx eax
2665 dunkaist 2439
	mov	esi,edx
2440
	jmp	process_macro_line_element
2441
      replace_macro_counter:
31 halyavin 2442
	mov	eax,[counter]
2665 dunkaist 2443
	and	eax,not 80000000h
2444
	jz	group_macro_counter
2445
	add	ecx,eax
2446
	dec	ecx
2447
	call	store_number_symbol
2448
	jmp	process_macro_line_element
2449
      group_macro_counter:
31 halyavin 2450
	mov	edx,ecx
2665 dunkaist 2451
	xor	ecx,ecx
2452
      multiple_macro_counter_values:
31 halyavin 2453
	push	ecx edx
2665 dunkaist 2454
	add	ecx,edx
2455
	call	store_number_symbol
2456
	pop	edx ecx
2457
	inc	ecx
2458
	cmp	ecx,[counter_limit]
2459
	je	process_macro_line_element
2460
	mov	byte [edi],','
2461
	inc	edi
2462
	jmp	multiple_macro_counter_values
2463
      store_number_symbol:
31 halyavin 2464
	cmp	ecx,0
2665 dunkaist 2465
	jge	numer_symbol_sign_ok
2466
	neg	ecx
2467
	mov	al,'-'
2468
	stos	byte [edi]
2469
      numer_symbol_sign_ok:
1189 heavyiron 2470
	mov	ax,1Ah
2665 dunkaist 2471
	stos	word [edi]
2472
	push	edi
2473
	mov	eax,ecx
2474
	mov	ecx,1000000000
2475
	xor	edx,edx
2476
	xor	bl,bl
2477
      store_number_digits:
31 halyavin 2478
	div	ecx
2665 dunkaist 2479
	push	edx
2480
	or	bl,bl
2481
	jnz	store_number_digit
2482
	cmp	ecx,1
2483
	je	store_number_digit
2484
	or	al,al
2485
	jz	number_digit_ok
2486
	not	bl
2487
      store_number_digit:
31 halyavin 2488
	add	al,30h
2665 dunkaist 2489
	stos	byte [edi]
2490
      number_digit_ok:
31 halyavin 2491
	mov	eax,ecx
2665 dunkaist 2492
	xor	edx,edx
2493
	mov	ecx,10
2494
	div	ecx
2495
	mov	ecx,eax
2496
	pop	eax
2497
	or	ecx,ecx
2498
	jnz	store_number_digits
2499
	pop	ebx
2500
	mov	eax,edi
2501
	sub	eax,ebx
2502
	mov	[ebx-1],al
2503
	ret
2504
      not_macro_symbol:
31 halyavin 2505
	pop	edi esi
2665 dunkaist 2506
	mov	al,1Ah
2507
	stos	byte [edi]
2508
	mov	al,[esi]
2509
	inc	esi
2510
	stos	byte [edi]
2511
	cmp	byte [esi],'.'
2512
	jne	copy_raw_symbol
2513
	mov	ebx,[esp+8+8]
2514
	or	ebx,ebx
2515
	jz	copy_raw_symbol
2516
	cmp	al,1
2517
	je	copy_struc_name
2518
	xchg	esi,ebx
2519
	movzx	ecx,byte [esi-1]
2520
	add	[edi-1],cl
2521
	jc	name_too_long
2522
	rep	movs byte [edi],[esi]
2523
	xchg	esi,ebx
2524
      copy_raw_symbol:
31 halyavin 2525
	movzx	ecx,al
2665 dunkaist 2526
	rep	movs byte [edi],[esi]
2527
	jmp	process_macro_line_element
2528
      copy_struc_name:
31 halyavin 2529
	inc	esi
2665 dunkaist 2530
	xchg	esi,ebx
2531
	movzx	ecx,byte [esi-1]
2532
	mov	[edi-1],cl
2533
	rep	movs byte [edi],[esi]
2534
	xchg	esi,ebx
2535
	mov	eax,[esp+8+12]
2536
	cmp	byte [eax],3Bh
2537
	je	process_macro_line_element
2538
	cmp	byte [eax],1Ah
2539
	jne	disable_replaced_struc_name
2540
	mov	byte [eax],3Bh
2541
	jmp	process_macro_line_element
2542
      disable_replaced_struc_name:
31 halyavin 2543
	mov	ebx,[esp+8+8]
2665 dunkaist 2544
	push	esi edi
2545
	lea	edi,[ebx-3]
2546
	lea	esi,[edi-2]
2547
	lea	ecx,[esi+1]
2548
	sub	ecx,eax
2549
	std
2550
	rep	movs byte [edi],[esi]
2551
	cld
2552
	mov	word [eax],3Bh
2553
	pop	edi esi
2554
	jmp	process_macro_line_element
2555
      skip_foreign_symbol:
31 halyavin 2556
	lods	byte [esi]
2665 dunkaist 2557
	movzx	eax,al
2558
	add	esi,eax
2559
      skip_foreign_line:
31 halyavin 2560
	lods	byte [esi]
2665 dunkaist 2561
	cmp	al,1Ah
2562
	je	skip_foreign_symbol
2563
	cmp	al,3Bh
2564
	je	skip_foreign_symbol
2565
	cmp	al,22h
2566
	je	skip_foreign_string
2567
	or	al,al
2568
	jnz	skip_foreign_line
2569
	ret
2570
      skip_foreign_string:
31 halyavin 2571
	lods	dword [esi]
2665 dunkaist 2572
	add	esi,eax
2573
	jmp	skip_foreign_line
2574
      macro_foreign_line:
31 halyavin 2575
	call	skip_foreign_symbol
2665 dunkaist 2576
      macro_line_processed:
31 halyavin 2577
	mov	byte [edi],0
2665 dunkaist 2578
	inc	edi
2579
	push	eax
2580
	call	preprocess_line
2581
	pop	eax
2582
	pop	ecx ebx
2583
	cmp	al,'}'
2584
	je	macro_block_processed
2585
      process_next_line:
31 halyavin 2586
	inc	ecx
2665 dunkaist 2587
	mov	[macro_line],esi
2588
	add	esi,16+2
2589
	jmp	process_macro_line
2590
      macro_block_processed:
31 halyavin 2591
	call	close_macro_block
2665 dunkaist 2592
	jc	process_macro_line
2593
	pop	[current_line]
2594
	add	esp,12
2595
	pop	[macro_block_line_number]
2596
	pop	[macro_block_line]
2597
	pop	[macro_block]
2598
	pop	[counter]
2599
	pop	eax
2600
	and	al,0F0h
2601
	and	[macro_status],0Fh
2602
	or	[macro_status],al
2603
	ret
2604
31 halyavin 2605
 
2606
	lods	byte [esi]
2665 dunkaist 2607
	cmp	al,1Ah
2608
	jne	invalid_argument
2609
	mov	byte [edi-1],3Bh
2610
	xor	al,al
2611
	stos	byte [edi]
2612
      make_local_symbol:
31 halyavin 2613
	push	ecx
2665 dunkaist 2614
	lods	byte [esi]
2615
	movzx	ecx,al
2616
	mov	eax,[counter]
2617
	call	add_macro_symbol
2618
	mov	[edx+12],edi
2619
	movzx	eax,[locals_counter]
2620
	add	eax,ecx
2621
	inc	eax
2622
	cmp	eax,100h
2623
	jae	name_too_long
2624
	lea	ebp,[edi+2+eax]
2625
	cmp	ebp,[memory_end]
2626
	jae	out_of_memory
2627
	mov	ah,al
2628
	mov	al,1Ah
2629
	stos	word [edi]
2630
	rep	movs byte [edi],[esi]
2631
	mov	al,'?'
2632
	stos	byte [edi]
2633
	push	esi
2634
	mov	esi,locals_counter+1
2635
	movzx	ecx,[locals_counter]
2636
	rep	movs byte [edi],[esi]
2637
	pop	esi
2638
	mov	eax,edi
2639
	sub	eax,[edx+12]
2640
	mov	[edx+8],eax
2641
	xor	al,al
2642
	stos	byte [edi]
2643
	mov	eax,locals_counter
2644
	movzx	ecx,byte [eax]
2645
      counter_loop:
31 halyavin 2646
	inc	byte [eax+ecx]
2665 dunkaist 2647
	cmp	byte [eax+ecx],'9'+1
2648
	jb	counter_ok
2649
	jne	letter_digit
2650
	mov	byte [eax+ecx],'A'
2651
	jmp	counter_ok
2652
      letter_digit:
31 halyavin 2653
	cmp	byte [eax+ecx],'Z'+1
2665 dunkaist 2654
	jb	counter_ok
2655
	jne	small_letter_digit
2656
	mov	byte [eax+ecx],'a'
2657
	jmp	counter_ok
2658
      small_letter_digit:
692 heavyiron 2659
	cmp	byte [eax+ecx],'z'+1
2665 dunkaist 2660
	jb	counter_ok
2661
	mov	byte [eax+ecx],'0'
2662
	loop	counter_loop
2663
	inc	byte [eax]
2664
	movzx	ecx,byte [eax]
2665
	mov	byte [eax+ecx],'0'
2666
      counter_ok:
31 halyavin 2667
	pop	ecx
2665 dunkaist 2668
	lods	byte [esi]
2669
	cmp	al,'}'
2670
	je	macro_block_processed
2671
	or	al,al
2672
	jz	process_next_line
2673
	cmp	al,','
2674
	jne	extra_characters_on_line
2675
	dec	edi
2676
	lods	byte [esi]
2677
	cmp	al,1Ah
2678
	je	make_local_symbol
2679
	jmp	invalid_argument
2680
common_block:
31 halyavin 2681
	call	close_macro_block
2665 dunkaist 2682
	jc	process_macro_line
2683
	mov	[counter],0
2684
	jmp	new_macro_block
2685
forward_block:
31 halyavin 2686
	cmp	[counter_limit],0
2665 dunkaist 2687
	je	common_block
2688
	call	close_macro_block
2689
	jc	process_macro_line
2690
	mov	[counter],1
2691
	jmp	new_macro_block
2692
reverse_block:
31 halyavin 2693
	cmp	[counter_limit],0
2665 dunkaist 2694
	je	common_block
2695
	call	close_macro_block
2696
	jc	process_macro_line
2697
	mov	eax,[counter_limit]
2698
	or	eax,80000000h
2699
	mov	[counter],eax
2700
      new_macro_block:
31 halyavin 2701
	mov	[macro_block],esi
2665 dunkaist 2702
	mov	eax,[macro_line]
2703
	mov	[macro_block_line],eax
2704
	mov	[macro_block_line_number],ecx
2705
	jmp	process_macro_line
2706
close_macro_block:
31 halyavin 2707
	cmp	esi,[macro_block]
6467 dunkaist 2708
	je	block_closed
2709
	cmp	[counter],0
2665 dunkaist 2710
	je	block_closed
2711
	jl	reverse_counter
2712
	mov	eax,[counter]
2713
	cmp	eax,[counter_limit]
2714
	je	block_closed
2715
	inc	[counter]
2716
	jmp	continue_block
2717
      reverse_counter:
31 halyavin 2718
	mov	eax,[counter]
2665 dunkaist 2719
	dec	eax
2720
	cmp	eax,80000000h
2721
	je	block_closed
2722
	mov	[counter],eax
2723
      continue_block:
31 halyavin 2724
	mov	esi,[macro_block]
2665 dunkaist 2725
	mov	eax,[macro_block_line]
2726
	mov	[macro_line],eax
2727
	mov	ecx,[macro_block_line_number]
2728
	stc
2729
	ret
2730
      block_closed:
31 halyavin 2731
	clc
2665 dunkaist 2732
	ret
2733
get_macro_symbol:
31 halyavin 2734
	push	ecx
2665 dunkaist 2735
	call	find_macro_symbol_leaf
2736
	jc	macro_symbol_not_found
2737
	mov	edx,[ebx]
2738
	mov	ebx,esi
2739
      try_macro_symbol:
31 halyavin 2740
	or	edx,edx
2665 dunkaist 2741
	jz	macro_symbol_not_found
2742
	mov	ecx,[esp]
2743
	mov	edi,[edx+4]
2744
	repe	cmps byte [esi],[edi]
2745
	je	macro_symbol_found
2746
	mov	esi,ebx
2747
	mov	edx,[edx]
2748
	jmp	try_macro_symbol
2749
      macro_symbol_found:
31 halyavin 2750
	pop	ecx
2665 dunkaist 2751
	clc
2752
	ret
2753
      macro_symbol_not_found:
31 halyavin 2754
	pop	ecx
2665 dunkaist 2755
	stc
2756
	ret
2757
      find_macro_symbol_leaf:
31 halyavin 2758
	shl	eax,8
2665 dunkaist 2759
	mov	al,cl
2760
	mov	ebp,eax
2761
	mov	ebx,macro_symbols
2762
      follow_macro_symbols_tree:
31 halyavin 2763
	mov	edx,[ebx]
2665 dunkaist 2764
	or	edx,edx
2765
	jz	no_such_macro_symbol
2766
	xor	eax,eax
2767
	shr	ebp,1
2768
	adc	eax,0
2769
	lea	ebx,[edx+eax*4]
2770
	or	ebp,ebp
2771
	jnz	follow_macro_symbols_tree
2772
	add	ebx,8
2773
	clc
2774
	ret
2775
      no_such_macro_symbol:
31 halyavin 2776
	stc
2665 dunkaist 2777
	ret
2778
add_macro_symbol:
31 halyavin 2779
	push	ebx ebp
2665 dunkaist 2780
	call	find_macro_symbol_leaf
2781
	jc	extend_macro_symbol_tree
2782
	mov	eax,[ebx]
2783
      make_macro_symbol:
31 halyavin 2784
	mov	edx,[free_additional_memory]
2665 dunkaist 2785
	add	edx,16
2786
	cmp	edx,[labels_list]
2787
	ja	out_of_memory
2788
	xchg	edx,[free_additional_memory]
2789
	mov	[ebx],edx
2790
	mov	[edx],eax
2791
	mov	[edx+4],esi
2792
	pop	ebp ebx
2793
	ret
2794
      extend_macro_symbol_tree:
31 halyavin 2795
	mov	edx,[free_additional_memory]
2665 dunkaist 2796
	add	edx,16
2797
	cmp	edx,[labels_list]
2798
	ja	out_of_memory
2799
	xchg	edx,[free_additional_memory]
2800
	xor	eax,eax
2801
	mov	[edx],eax
2802
	mov	[edx+4],eax
2803
	mov	[edx+8],eax
2804
	mov	[edx+12],eax
2805
	shr	ebp,1
2806
	adc	eax,0
2807
	mov	[ebx],edx
2808
	lea	ebx,[edx+eax*4]
2809
	or	ebp,ebp
2810
	jnz	extend_macro_symbol_tree
2811
	add	ebx,8
2812
	xor	eax,eax
2813
	jmp	make_macro_symbol
2814
31 halyavin 2815
 
2816
	lods	byte [esi]
2665 dunkaist 2817
	cmp	al,22h
2818
	jne	invalid_argument
2819
	lods	dword [esi]
2820
	cmp	byte [esi+eax],0
2821
	jne	extra_characters_on_line
2822
	push	esi
2823
	push	edi
2824
	mov	ebx,[current_line]
2825
      find_current_file_path:
31 halyavin 2826
	mov	esi,[ebx]
2665 dunkaist 2827
	test	byte [ebx+7],80h
2828
	jz	copy_current_file_path
2829
	mov	ebx,[ebx+8]
2830
	jmp	find_current_file_path
2831
      copy_current_file_path:
31 halyavin 2832
	lods	byte [esi]
2665 dunkaist 2833
	stos	byte [edi]
2834
	or	al,al
2835
	jnz	copy_current_file_path
2836
      cut_current_file_name:
31 halyavin 2837
	cmp	edi,[esp]
2665 dunkaist 2838
	je	current_file_path_ok
2839
	cmp	byte [edi-1],'\'
2840
	je	current_file_path_ok
2841
	cmp	byte [edi-1],'/'
2842
	je	current_file_path_ok
2843
	dec	edi
2844
	jmp	cut_current_file_name
2845
      current_file_path_ok:
31 halyavin 2846
	mov	esi,[esp+4]
2665 dunkaist 2847
	call	expand_path
2848
	pop	edx
2849
	mov	esi,edx
2850
	call	open
2851
	jnc	include_path_ok
2852
	mov	ebp,[include_paths]
2853
      try_include_directories:
31 halyavin 2854
	mov	edi,esi
2665 dunkaist 2855
	mov	esi,ebp
2856
	cmp	byte [esi],0
2857
	je	try_in_current_directory
2858
	push	ebp
2859
	push	edi
2860
	call	get_include_directory
2861
	mov	[esp+4],esi
2862
	mov	esi,[esp+8]
2863
	call	expand_path
2864
	pop	edx
2865
	mov	esi,edx
2866
	call	open
2867
	pop	ebp
2868
	jnc	include_path_ok
2869
	jmp	try_include_directories
2870
	mov	edi,esi
2871
      try_in_current_directory:
31 halyavin 2872
	mov	esi,[esp]
2665 dunkaist 2873
	push	edi
2874
	call	expand_path
2875
	pop	edx
2876
	mov	esi,edx
2877
	call	open
2878
	jc	file_not_found
2879
      include_path_ok:
31 halyavin 2880
	mov	edi,[esp]
2665 dunkaist 2881
      copy_preprocessed_path:
31 halyavin 2882
	lods	byte [esi]
2665 dunkaist 2883
	stos	byte [edi]
2884
	or	al,al
2885
	jnz	copy_preprocessed_path
2886
	pop	esi
2887
	lea	ecx,[edi-1]
2888
	sub	ecx,esi
2889
	mov	[esi-4],ecx
2890
	push	dword [macro_status]
2891
	and	[macro_status],0Fh
2892
	call	preprocess_file
2893
	pop	eax
2894
	and	al,0F0h
2895
	and	[macro_status],0Fh
2896
	or	[macro_status],al
2897
	jmp	line_preprocessed
2898
>