Subversion Repositories Kolibri OS

Rev

Rev 2287 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2287 Rev 2664
1
; flat assembler
1
; flat assembler
2
; Copyright (c) 1999-2007, Tomasz Grysztar
2
; Copyright (c) 1999-2012, Tomasz Grysztar
3
; All rights reserved.
3
; All rights reserved.
4
 
4
 
5
struc FILEIO
5
struc FILEIO
6
{   .cmd            dd ?
6
{   .cmd            dd ?
7
    .offset         dd ?
7
    .offset         dd ?
8
                    dd ?
8
                    dd ?
9
    .count          dd ?
9
    .count          dd ?
10
    .buff           dd ?
10
    .buff           dd ?
11
                    db ?
11
                    db ?
12
    .name           dd ?
12
    .name           dd ?
13
};
13
};
14
 
14
 
15
struc FILEINFO
15
struc FILEINFO
16
{   .attr           dd ?
16
{   .attr           dd ?
17
    .flags          dd ?
17
    .flags          dd ?
18
    .cr_time        dd ?
18
    .cr_time        dd ?
19
    .cr_date        dd ?
19
    .cr_date        dd ?
20
    .acc_time       dd ?
20
    .acc_time       dd ?
21
    .acc_date       dd ?
21
    .acc_date       dd ?
22
    .mod_time       dd ?
22
    .mod_time       dd ?
23
    .mod_date       dd ?
23
    .mod_date       dd ?
24
    .size           dd ?
24
    .size           dd ?
25
}
25
}
26
 
26
 
27
 
27
 
28
 
28
 
29
;file_info_open:  dd 0,0,0xffffff,0x20000,0xf0000
29
;file_info_open:  dd 0,0,0xffffff,0x20000,0xf0000
30
fullpath_open:  ;  db '/RD/1/EXAMPLE.ASM'
30
fullpath_open:  ;  db '/RD/1/EXAMPLE.ASM'
31
		    times MAX_PATH db 0
31
		    times MAX_PATH db 0
32
 
32
 
33
 
33
 
34
;file_info_write: dd 1,0,0,0,0xf0000
34
;file_info_write: dd 1,0,0,0,0xf0000
35
fullpath_write:; db '/RD/1/EXAMPLE'
35
fullpath_write:; db '/RD/1/EXAMPLE'
36
		    times MAX_PATH db 0
36
		    times MAX_PATH db 0
37
 
37
 
38
file_info_start:
38
file_info_start:
39
    dd 7
39
    dd 7
40
    dd 0
40
    dd 0
41
    dd 0
41
    dd 0
42
    dd 0
42
    dd 0
43
    dd 0
43
    dd 0
44
fullpath_start:  ; db '/RD/1/EXAMPLE'
44
fullpath_start:  ; db '/RD/1/EXAMPLE'
45
		    times MAX_PATH db 0
45
		    times MAX_PATH db 0
46
 
46
 
47
file_info_debug:
47
file_info_debug:
48
	dd	7
48
	dd	7
49
	dd	0
49
	dd	0
50
	dd	fullpath_start
50
	dd	fullpath_start
51
	dd	0, 0
51
	dd	0, 0
52
	db	'/SYS/DEVELOP/MTDBG',0
52
	db	'/SYS/DEVELOP/MTDBG',0
53
 
53
 
54
_ramdisk	 db '/RD/1/'
54
_ramdisk	 db '/RD/1/'
55
filepos 	 dd 0x0
55
filepos 	 dd 0x0
56
 
56
 
57
 
57
 
58
init_memory:
58
init_memory:
59
 
59
 
60
;        mov ecx, 16*1024*1024
60
;        mov ecx, 16*1024*1024
61
;
61
;
62
; allocate_memory:
62
; allocate_memory:
63
	mcall	18, 16
63
	mcall	18, 16
64
	cmp	eax, 0x38000000 shr 9
64
	cmp	eax, 0x38000000 shr 9
65
	jbe	@f
65
	jbe	@f
66
	mov	eax, 0x38000000 shr 9
66
	mov	eax, 0x38000000 shr 9
67
@@:
67
@@:
68
	shl	eax, 9
68
	shl	eax, 9
69
	xchg	eax, ecx
69
	xchg	eax, ecx
70
	mov	[memory_setting],ecx
70
	mov	[memory_setting],ecx
71
	mcall	68, 12
71
	mcall	68, 12
72
	or	eax,eax
72
	or	eax,eax
73
	jz	out_of_memory
73
	jz	out_of_memory
74
	mov	[memblock], eax
74
	mov	[memblock], eax
75
	mov	[additional_memory],eax
75
	mov	[additional_memory],eax
76
	add	eax,[memory_setting]
76
	add	eax,[memory_setting]
77
	mov	[memory_end],eax
77
	mov	[memory_end],eax
78
	mov	eax,[memory_setting]
78
	mov	eax,[memory_setting]
79
	shr	eax,2
79
	shr	eax,2
80
	add	eax,[additional_memory]
80
	add	eax,[additional_memory]
81
	mov	[additional_memory_end],eax
81
	mov	[additional_memory_end],eax
82
	mov	[memory_start],eax
82
	mov	[memory_start],eax
83
	ret
83
	ret
84
 
84
 
85
exit_program:
85
exit_program:
86
	cmp	[_mode],NORMAL_MODE
86
	cmp	[_mode],NORMAL_MODE
87
	jne	@f
87
	jne	@f
88
	mcall	68, 13, [memblock]
88
	mcall	68, 13, [memblock]
89
	jmp	still
89
	jmp	still
90
@@:
90
@@:
91
	or	eax,-1
91
	or	eax,-1
92
	mcall
92
	mcall
93
 
93
 
94
make_timestamp:
94
make_timestamp:
95
	push	ebx
95
	push	ebx
96
	mcall	26,9
96
	mcall	26,9
97
	imul	eax,10
97
	imul	eax,10
98
	pop	ebx
98
	pop	ebx
99
	ret
99
	ret
100
 
100
 
101
symbol_dump:
101
symbol_dump:
102
 
102
 
103
	push	edi
103
	push	edi
104
	mov	edx,[memory_end]
104
	mov	edx,[memory_end]
105
      symb_dump:
105
      symb_dump:
106
	cmp	edx,[labels_list]
106
	cmp	edx,[labels_list]
107
	jbe	symbols_dumped
107
	jbe	symbols_dumped
108
	sub	edx,LABEL_STRUCTURE_SIZE
108
	sub	edx,LABEL_STRUCTURE_SIZE
109
	cmp	dword [edx+24],0
109
	cmp	dword [edx+24],0
110
	je	symb_dump	; do not dump anonymous symbols
110
	je	symb_dump	; do not dump anonymous symbols
111
	test	byte [edx+8],1
111
	test	byte [edx+8],1
112
	jz	symb_dump	; do not dump symbols that didn't get defined
112
	jz	symb_dump	; do not dump symbols that didn't get defined
113
	mov	ax,[current_pass]
113
	mov	ax,[current_pass]
114
	cmp	ax,[edx+16]
114
	cmp	ax,[edx+16]
115
	jne	symb_dump
115
	jne	symb_dump
116
	test	byte [edx+8],4 or 2
116
	test	byte [edx+8],4 or 2
117
	jnz	symb_dump	; do not dump assembly-time variables
117
	jnz	symb_dump	; do not dump assembly-time variables
118
				; do not dump variables defined with '='
118
				; do not dump variables defined with '='
119
	cmp	word [edx+12], 0
119
	cmp	word [edx+12], 0
120
	jnz	symb_dump	; do not dump register-based variables
120
	jnz	symb_dump	; do not dump register-based variables
121
 
121
 
122
	mov	al, '0'
122
	mov	al, '0'
123
	stosb
123
	stosb
124
	mov	al, 'x'
124
	mov	al, 'x'
125
	stosb
125
	stosb
126
	mov	eax, [edx+4]
126
	mov	eax, [edx+4]
127
	mov	ecx, 8
127
	mov	ecx, 8
128
@@:
128
@@:
129
	rol	eax, 4
129
	rol	eax, 4
130
	test	al, 0xF
130
	test	al, 0xF
131
	loopz	@b
131
	loopz	@b
132
	jz	.nohigh
132
	jz	.nohigh
133
	inc	ecx
133
	inc	ecx
134
@@:
134
@@:
135
	push	eax
135
	push	eax
136
	and	al, 0xF
136
	and	al, 0xF
137
	cmp	al, 10
137
	cmp	al, 10
138
	sbb	al, 69h
138
	sbb	al, 69h
139
	das
139
	das
140
	stosb
140
	stosb
141
	pop	eax
141
	pop	eax
142
	rol	eax, 4
142
	rol	eax, 4
143
	loop	@b
143
	loop	@b
144
	mov	eax, [edx]
144
	mov	eax, [edx]
145
	mov	ecx, 8
145
	mov	ecx, 8
146
	jmp	.low
146
	jmp	.low
147
.nohigh:
147
.nohigh:
148
	mov	eax, [edx]
148
	mov	eax, [edx]
149
	mov	ecx, 8
149
	mov	ecx, 8
150
@@:
150
@@:
151
	rol	eax, 4
151
	rol	eax, 4
152
	test	al, 0xF
152
	test	al, 0xF
153
	loopz	@b
153
	loopz	@b
154
	inc	ecx
154
	inc	ecx
155
.low:
155
.low:
156
	push	eax
156
	push	eax
157
	and	al, 0xF
157
	and	al, 0xF
158
	cmp	al, 10
158
	cmp	al, 10
159
	sbb	al, 69h
159
	sbb	al, 69h
160
	das
160
	das
161
	stosb
161
	stosb
162
	pop	eax
162
	pop	eax
163
	rol	eax, 4
163
	rol	eax, 4
164
	loop	.low
164
	loop	.low
165
 
165
 
166
	mov	al, ' '
166
	mov	al, ' '
167
	stosb
167
	stosb
168
 
168
 
169
	mov	esi,[edx+24]
169
	mov	esi,[edx+24]
170
	movzx	ecx,byte [esi-1]
170
	movzx	ecx,byte [esi-1]
171
	rep	movsb
171
	rep	movsb
172
 
172
 
173
	mov	ax,0A0Dh
173
	mov	ax,0A0Dh
174
	stosw
174
	stosw
175
 
175
 
176
	jmp	symb_dump
176
	jmp	symb_dump
177
 
177
 
178
      symbols_dumped:
178
      symbols_dumped:
179
	mov	edx,dbgfilename
179
	mov	edx,dbgfilename
180
        push    esi edi
180
        push    esi edi
181
	mov     esi, outfile
181
	mov     esi, outfile
182
	mov     edi, edx
182
	mov     edi, edx
183
@@:
183
@@:
184
	lodsb
184
	lodsb
185
	stosb
185
	stosb
186
	test	al, al
186
	test	al, al
187
	jnz	@b
187
	jnz	@b
188
	lea	ecx, [edi-1]
188
	lea	ecx, [edi-1]
189
@@:
189
@@:
190
	dec	edi
190
	dec	edi
191
	cmp	edi, edx
191
	cmp	edi, edx
192
	jb	@f
192
	jb	@f
193
	cmp	byte [edi], '/'
193
	cmp	byte [edi], '/'
194
	jz	@f
194
	jz	@f
195
	cmp	byte [edi], '.'
195
	cmp	byte [edi], '.'
196
	jnz	@b
196
	jnz	@b
197
	mov	ecx, edi
197
	mov	ecx, edi
198
@@:
198
@@:
199
	mov	dword [ecx], '.dbg'
199
	mov	dword [ecx], '.dbg'
200
	mov     byte [ecx+4], 0
200
	mov     byte [ecx+4], 0
201
	pop	edi esi
201
	pop	edi esi
202
	call	create
202
	call	create
203
	mov	edx,[esp]
203
	mov	edx,[esp]
204
	mov	ecx,edi
204
	mov	ecx,edi
205
	sub	ecx,edx
205
	sub	ecx,edx
206
	call	write
206
	call	write
207
	call	close
207
	call	close
208
	pop	edi
208
	pop	edi
209
 
209
 
210
	ret
210
	ret
211
 
211
 
212
get_environment_variable:
212
get_environment_variable:
213
	mov	ecx,[memory_end]
213
	mov	ecx,[memory_end]
214
	sub	ecx,edi
214
	sub	ecx,edi
215
	cmp	ecx,7
215
	cmp	ecx,7
216
	jb	out_of_memory
216
	jb	out_of_memory
217
	cmp	dword[esi],'INCL'
217
	cmp	dword[esi],'INCL'
218
	jne	.finish
218
	jne	.finish
219
	mov	esi,_ramdisk
219
	mov	esi,_ramdisk
220
	mov	ecx,6
220
	mov	ecx,6
221
	cld
221
	cld
222
	rep	movsb
222
	rep	movsb
223
  .finish:
223
  .finish:
224
;       stc
224
;       stc
225
	ret
225
	ret
226
 
226
 
227
alloc_handle:
227
alloc_handle:
228
        call    make_fullpaths
228
        call    make_fullpaths
229
        mov     ebx, fileinfos+4
229
        mov     ebx, fileinfos+4
230
@@:
230
@@:
231
        cmp     dword [ebx], -1
231
        cmp     dword [ebx], -1
232
        jz      .found
232
        jz      .found
233
        add     ebx, 4+20+MAX_PATH
233
        add     ebx, 4+20+MAX_PATH
234
        cmp     ebx, fileinfos_end
234
        cmp     ebx, fileinfos_end
235
        jb      @b
235
        jb      @b
236
        stc
236
        stc
237
        ret
237
        ret
238
.found:
238
.found:
239
        and     dword [ebx+4], 0
239
        and     dword [ebx+4], 0
240
        and     dword [ebx+8], 0
240
        and     dword [ebx+8], 0
241
        push    esi edi ecx
241
        push    esi edi ecx
242
        mov     esi, fullpath_open
242
        mov     esi, fullpath_open
243
        lea     edi, [ebx+20]
243
        lea     edi, [ebx+20]
244
        mov     ecx, MAX_PATH
244
        mov     ecx, MAX_PATH
245
        rep     movsb
245
        rep     movsb
246
        pop     ecx edi esi
246
        pop     ecx edi esi
247
        ret	; CF=0
247
        ret	; CF=0
248
 
248
 
249
create:
249
create:
250
        call    alloc_handle
250
        call    alloc_handle
251
        jc      .ret
251
        jc      .ret
252
        and     dword [ebx-4], 0
252
        and     dword [ebx-4], 0
253
        mov     dword [ebx], 2
253
        mov     dword [ebx], 2
254
.ret:
254
.ret:
255
        ret
255
        ret
256
 
256
 
257
 
257
 
258
open:
258
open:
259
;        call    make_fullpaths
259
;        call    make_fullpaths
260
 
260
 
261
;;       mov     eax,fullpath_open
261
;;       mov     eax,fullpath_open
262
;;       DEBUGF  '"%s"\n',eax
262
;;       DEBUGF  '"%s"\n',eax
263
 
263
 
264
;        mov     dword[file_info_open+8],-1
264
;        mov     dword[file_info_open+8],-1
265
;        mcall   58,file_info_open
265
;        mcall   58,file_info_open
266
;        or      eax,eax                 ; found
266
;        or      eax,eax                 ; found
267
;        jz      @f
267
;        jz      @f
268
;        cmp     eax,6
268
;        cmp     eax,6
269
;        jne     file_error
269
;        jne     file_error
270
;@@: mov [filesize],ebx
270
;@@: mov [filesize],ebx
271
;        clc
271
;        clc
272
;        ret
272
;        ret
273
;file_error:
273
;file_error:
274
;        stc
274
;        stc
275
;        ret
275
;        ret
276
 
276
 
277
        call    alloc_handle
277
        call    alloc_handle
278
        jc      .ret
278
        jc      .ret
279
        mov     dword [ebx], 5
279
        mov     dword [ebx], 5
280
        and     dword [ebx+12], 0
280
        and     dword [ebx+12], 0
281
        mov     dword [ebx+16], fileinfo
281
        mov     dword [ebx+16], fileinfo
282
        mov     eax, 70
282
        mov     eax, 70
283
        push    ebx
283
        push    ebx
284
        mcall
284
        mcall
285
        pop     ebx
285
        pop     ebx
286
        test    eax, eax
286
        test    eax, eax
287
        jnz     .fail
287
        jnz     .fail
288
        mov     eax, [fileinfo.size]
288
        mov     eax, [fileinfo.size]
289
        mov     [ebx-4], eax
289
        mov     [ebx-4], eax
290
        and     dword [ebx], 0
290
        and     dword [ebx], 0
291
.ret:
291
.ret:
292
        ret
292
        ret
293
.fail:
293
.fail:
294
	or	dword [ebx], -1	; close handle
294
	or	dword [ebx], -1	; close handle
295
        stc
295
        stc
296
        ret
296
        ret
297
 
297
 
298
read:
298
read:
299
;          pusha
299
;          pusha
300
;          mov     edi,edx
300
;          mov     edi,edx
301
;          mov     esi,[filepos]
301
;          mov     esi,[filepos]
302
;          add     esi,0x20000
302
;          add     esi,0x20000
303
;          cld
303
;          cld
304
;          rep     movsb
304
;          rep     movsb
305
;          popa
305
;          popa
306
;;         ret
306
;;         ret
307
 
307
 
308
        mov     [ebx+12], ecx
308
        mov     [ebx+12], ecx
309
        mov     [ebx+16], edx
309
        mov     [ebx+16], edx
310
        push    ebx
310
        push    ebx
311
        mov     eax, 70
311
        mov     eax, 70
312
        mcall
312
        mcall
313
        xchg    eax, [esp]
313
        xchg    eax, [esp]
314
        add     [eax+4], ebx
314
        add     [eax+4], ebx
315
        adc     [eax+8], dword 0
315
        adc     [eax+8], dword 0
316
        mov     ebx, eax
316
        mov     ebx, eax
317
        pop     eax
317
        pop     eax
318
        test    eax, eax
318
        test    eax, eax
319
        jz      .ok
319
        jz      .ok
320
        cmp     eax, 6
320
        cmp     eax, 6
321
        jz      .ok
321
        jz      .ok
322
        stc
322
        stc
323
.ok:
323
.ok:
324
        ret
324
        ret
325
 
325
 
326
close:
326
close:
327
        or      dword [ebx], -1
327
        or      dword [ebx], -1
328
        ret
328
        ret
329
 
329
 
330
 
330
 
331
; ebx file handle
331
; ebx file handle
332
; ecx count of bytes to write
332
; ecx count of bytes to write
333
; edx pointer to buffer
333
; edx pointer to buffer
334
write:
334
write:
335
;        pusha
335
;        pusha
336
;        mov     [file_info_write+8],ecx
336
;        mov     [file_info_write+8],ecx
337
;        mov     [file_info_write+12],edx
337
;        mov     [file_info_write+12],edx
338
;        mov     [filesize],edx
338
;        mov     [filesize],edx
339
;        mov     eax,58
339
;        mov     eax,58
340
;        mov     ebx,file_info_write
340
;        mov     ebx,file_info_write
341
;        mcall
341
;        mcall
342
;        popa
342
;        popa
343
;        ret
343
;        ret
344
 
344
 
345
        mov     [ebx+12], ecx
345
        mov     [ebx+12], ecx
346
        mov     [ebx+16], edx
346
        mov     [ebx+16], edx
347
        push    ebx
347
        push    ebx
348
        mov     eax, 70
348
        mov     eax, 70
349
        mcall
349
        mcall
350
        xchg    eax, [esp]
350
        xchg    eax, [esp]
351
        add     [eax+4], ebx
351
        add     [eax+4], ebx
352
        adc     [eax+8], dword 0
352
        adc     [eax+8], dword 0
353
        mov     ebx, eax
353
        mov     ebx, eax
354
        pop     eax
354
        pop     eax
355
        mov     byte [ebx], 3
355
        mov     byte [ebx], 3
356
        cmp     eax, 1
356
        cmp     eax, 1
357
        cmc
357
        cmc
358
        ret
358
        ret
359
 
359
 
360
make_fullpaths:
360
make_fullpaths:
361
	pusha
361
	pusha
362
	push	edx
362
	push	edx
363
 
363
 
364
	mov	esi,path	      ; open
364
	mov	esi,path	      ; open
365
;       DEBUGF  "   '%s'",esi
365
;       DEBUGF  "   '%s'",esi
366
	mov	edi,fullpath_open
366
	mov	edi,fullpath_open
367
	cld
367
	cld
368
      newc1:
368
      newc1:
369
	movsb
369
	movsb
370
	cmp	byte[esi],0;' '
370
	cmp	byte[esi],0;' '
371
	jne	newc1
371
	jne	newc1
372
	mov	esi,[esp]
372
	mov	esi,[esp]
373
 
373
 
374
	cmp	byte[esi],'/'
374
	cmp	byte[esi],'/'
375
	jne	@f
375
	jne	@f
376
	mov	edi,fullpath_open
376
	mov	edi,fullpath_open
377
 
377
 
378
    @@:
378
    @@:
379
	lodsb
379
	lodsb
380
	stosb
380
	stosb
381
	cmp	al,0
381
	cmp	al,0
382
	jne	@b
382
	jne	@b
383
;       mov     ecx,12
383
;       mov     ecx,12
384
;       cld
384
;       cld
385
;       rep     movsb
385
;       rep     movsb
386
;       mov     byte[edi],0
386
;       mov     byte[edi],0
387
 
387
 
388
	mov	esi,path	      ; write
388
	mov	esi,path	      ; write
389
	mov	edi,fullpath_write
389
	mov	edi,fullpath_write
390
	cld
390
	cld
391
      newc2:
391
      newc2:
392
	movsb
392
	movsb
393
	cmp	byte[esi],0;' '
393
	cmp	byte[esi],0;' '
394
	jne	newc2
394
	jne	newc2
395
	mov	esi,[esp]
395
	mov	esi,[esp]
396
 
396
 
397
	cmp	byte[esi],'/'
397
	cmp	byte[esi],'/'
398
	jne	@f
398
	jne	@f
399
	mov	edi,fullpath_write
399
	mov	edi,fullpath_write
400
 
400
 
401
    @@:
401
    @@:
402
	lodsb
402
	lodsb
403
	stosb
403
	stosb
404
	cmp	al,0
404
	cmp	al,0
405
	jne	@b
405
	jne	@b
406
;        mov     ecx,12
406
;        mov     ecx,12
407
;        cld
407
;        cld
408
;        rep     movsb
408
;        rep     movsb
409
;        mov     byte[edi],0
409
;        mov     byte[edi],0
410
 
410
 
411
	mov	esi,path	      ; start
411
	mov	esi,path	      ; start
412
	mov	edi,fullpath_start
412
	mov	edi,fullpath_start
413
	cld
413
	cld
414
      newc3:
414
      newc3:
415
	movsb
415
	movsb
416
	cmp  byte[esi],0;' '
416
	cmp  byte[esi],0;' '
417
	jne  newc3
417
	jne  newc3
418
;        mov  esi,[esp]
418
;        mov  esi,[esp]
419
	pop	esi
419
	pop	esi
420
 
420
 
421
	cmp	byte[esi],'/'
421
	cmp	byte[esi],'/'
422
	jne	@f
422
	jne	@f
423
	mov	edi,fullpath_start
423
	mov	edi,fullpath_start
424
 
424
 
425
    @@:
425
    @@:
426
	lodsb
426
	lodsb
427
	stosb
427
	stosb
428
	cmp	al,0
428
	cmp	al,0
429
	jne	@b
429
	jne	@b
430
;        mov  ecx,12
430
;        mov  ecx,12
431
;        cld
431
;        cld
432
;        rep  movsb
432
;        rep  movsb
433
;        mov  byte[edi],0
433
;        mov  byte[edi],0
434
 
434
 
435
;        add  esp,4
435
;        add  esp,4
436
	popa
436
	popa
437
	ret
437
	ret
438
 
438
 
439
 
439
 
440
 
440
 
441
lseek:
441
lseek:
442
	cmp	al,0
442
	cmp	al,0
443
	jnz	@f
443
	jnz	@f
444
	and	dword [ebx+4], 0
444
	and	dword [ebx+4], 0
445
	and     dword [ebx+8], 0
445
	and     dword [ebx+8], 0
446
    @@: cmp	al,2
446
    @@: cmp	al,2
447
	jnz	@f
447
	jnz	@f
448
	mov	eax, [ebx-4]
448
	mov	eax, [ebx-4]
449
	mov	[ebx+4], eax
449
	mov	[ebx+4], eax
450
	and     dword [ebx+8], 0
450
	and     dword [ebx+8], 0
451
    @@: add	dword [ebx+4], edx
451
    @@: add	dword [ebx+4], edx
452
        adc     dword [ebx+8], 0
452
        adc     dword [ebx+8], 0
453
	ret
453
	ret
454
 
454
 
455
display_character:
455
display_character:
456
	pusha
456
	pusha
457
	cmp	[_mode],NORMAL_MODE
457
	cmp	[_mode],NORMAL_MODE
458
	jne	@f
458
	jne	@f
459
	cmp	dl,13
459
	cmp	dl,13
460
	jz	dc2
460
	jz	dc2
461
	cmp	dl,0xa
461
	cmp	dl,0xa
462
	jnz	dc1
462
	jnz	dc1
463
	and	[textxy],0x0000FFFF
463
	and	[textxy],0x0000FFFF
464
	add	[textxy], 7 shl 16 +53 and 0xFFFF0000 + 10
464
	add	[textxy], 7 shl 16 +53 and 0xFFFF0000 + 10
465
dc2:
465
dc2:
466
  popa
466
  popa
467
	ret
467
	ret
468
dc1:
468
dc1:
469
  mov eax,[textxy]
469
  mov eax,[textxy]
470
	cmp	ax,word[bottom_right]
470
	cmp	ax,word[bottom_right]
471
	ja	dc2
471
	ja	dc2
472
	shr	eax,16
472
	shr	eax,16
473
	cmp	ax,word[bottom_right+2]
473
	cmp	ax,word[bottom_right+2]
474
	ja	dc2
474
	ja	dc2
475
	mov	[dc],dl
475
	mov	[dc],dl
476
	mcall	4,[textxy],[sc.work_text],dc,1
476
	mcall	4,[textxy],[sc.work_text],dc,1
477
	add	[textxy],0x00060000
477
	add	[textxy],0x00060000
478
	popa
478
	popa
479
	ret
479
	ret
480
@@:
480
@@:
481
  mov	eax,63
481
  mov	eax,63
482
	mov	ebx,1
482
	mov	ebx,1
483
	mov	cl,dl
483
	mov	cl,dl
484
	mcall
484
	mcall
485
	popa
485
	popa
486
	ret
486
	ret
487
 
487
 
488
 
488
 
489
display_string:
489
display_string:
490
	pusha
490
	pusha
491
@@:
491
@@:
492
  cmp	byte[esi],0
492
  cmp	byte[esi],0
493
	je	@f
493
	je	@f
494
	mov	dl,[esi]
494
	mov	dl,[esi]
495
	call	display_character
495
	call	display_character
496
	add	esi,1
496
	add	esi,1
497
	jmp	@b
497
	jmp	@b
498
@@:
498
@@:
499
  popa
499
  popa
500
	ret
500
	ret
501
 
501
 
502
display_number:
502
display_number:
503
	push	ebx
503
	push	ebx
504
	mov	ecx,1000000000
504
	mov	ecx,1000000000
505
	xor	edx,edx
505
	xor	edx,edx
506
	xor	bl,bl
506
	xor	bl,bl
507
display_loop:
507
display_loop:
508
	div	ecx
508
	div	ecx
509
	push	edx
509
	push	edx
510
	cmp	ecx,1
510
	cmp	ecx,1
511
	je	display_digit
511
	je	display_digit
512
	or	bl,bl
512
	or	bl,bl
513
	jnz	display_digit
513
	jnz	display_digit
514
	or	al,al
514
	or	al,al
515
	jz	digit_ok
515
	jz	digit_ok
516
	not	bl
516
	not	bl
517
display_digit:
517
display_digit:
518
	mov	dl,al
518
	mov	dl,al
519
	add	dl,30h
519
	add	dl,30h
520
	push	ebx ecx
520
	push	ebx ecx
521
	call	display_character
521
	call	display_character
522
	pop	ecx ebx
522
	pop	ecx ebx
523
digit_ok:
523
digit_ok:
524
	mov	eax,ecx
524
	mov	eax,ecx
525
	xor	edx,edx
525
	xor	edx,edx
526
	mov	ecx,10
526
	mov	ecx,10
527
	div	ecx
527
	div	ecx
528
	mov	ecx,eax
528
	mov	ecx,eax
529
	pop	eax
529
	pop	eax
530
	or	ecx,ecx
530
	or	ecx,ecx
531
	jnz	display_loop
531
	jnz	display_loop
532
	pop	ebx
532
	pop	ebx
533
	ret
533
	ret
534
 
534
 
535
display_user_messages:
535
display_user_messages:
536
;    push   [skinh]
536
;    push   [skinh]
537
;    pop    [textxy]
537
;    pop    [textxy]
538
;    add    [textxy], 7 shl 16 +53
538
;    add    [textxy], 7 shl 16 +53
539
	mov	[displayed_count],0
539
	mov	[displayed_count],0
540
	call	show_display_buffer
540
	call	show_display_buffer
541
	cmp	[displayed_count],1
541
	cmp	[displayed_count],1
542
	jb	line_break_ok
542
	jb	line_break_ok
543
	je	make_line_break
543
	je	make_line_break
544
	mov	ax,word[last_displayed]
544
	mov	ax,word[last_displayed]
545
	cmp	ax,0A0Dh
545
	cmp	ax,0A0Dh
546
	je	line_break_ok
546
	je	line_break_ok
547
	cmp	ax,0D0Ah
547
	cmp	ax,0D0Ah
548
	je	line_break_ok
548
	je	line_break_ok
549
make_line_break:
549
make_line_break:
550
	mov	esi,lf
550
	mov	esi,lf
551
	call	display_string
551
	call	display_string
552
line_break_ok:
552
line_break_ok:
553
	ret
553
	ret
554
 
554
 
555
display_block:
555
display_block:
556
	pusha
556
	pusha
557
@@: mov dl,[esi]
557
@@: mov dl,[esi]
558
	call	display_character
558
	call	display_character
559
	inc	esi
559
	inc	esi
560
	loop	@b
560
	loop	@b
561
	popa
561
	popa
562
	ret
562
	ret
563
 
563
 
564
fatal_error:
564
fatal_error:
565
	mov	esi,error_prefix
565
	mov	esi,error_prefix
566
	call	display_string
566
	call	display_string
567
	pop	esi
567
	pop	esi
568
	call	display_string
568
	call	display_string
569
	mov	esi,error_suffix
569
	mov	esi,error_suffix
570
	call	display_string
570
	call	display_string
571
	mov	esi,lf
571
	mov	esi,lf
572
	call	display_string
572
	call	display_string
573
	mov	al,0FFh
573
	mov	al,0FFh
574
	jmp	exit_program
574
	jmp	exit_program
575
 
575
 
576
assembler_error:
576
assembler_error:
577
	call	display_user_messages
577
	call	display_user_messages
578
	push	dword 0
578
	push	dword 0
579
	mov	ebx,[current_line]
579
	mov	ebx,[current_line]
580
get_error_lines:
580
get_error_lines:
581
	push	ebx
581
	push	ebx
582
	test	byte [ebx+7],80h
582
	test	byte [ebx+7],80h
583
	jz	display_error_line
583
	jz	display_error_line
584
	mov	edx,ebx
584
	mov	edx,ebx
585
find_definition_origin:
585
find_definition_origin:
586
	mov	edx,[edx+12]
586
	mov	edx,[edx+12]
587
	test	byte [edx+7],80h
587
	test	byte [edx+7],80h
588
	jnz	find_definition_origin
588
	jnz	find_definition_origin
589
	push	edx
589
	push	edx
590
	mov	ebx,[ebx+8]
590
	mov	ebx,[ebx+8]
591
	jmp	get_error_lines
591
	jmp	get_error_lines
592
display_error_line:
592
display_error_line:
593
	mov	esi,[ebx]
593
	mov	esi,[ebx]
594
	call	display_string
594
	call	display_string
595
	mov	esi,line_number_start
595
	mov	esi,line_number_start
596
	call	display_string
596
	call	display_string
597
	mov	eax,[ebx+4]
597
	mov	eax,[ebx+4]
598
	and	eax,7FFFFFFFh
598
	and	eax,7FFFFFFFh
599
	call	display_number
599
	call	display_number
600
	mov	dl,']'
600
	mov	dl,']'
601
	call	display_character
601
	call	display_character
602
	pop	esi
602
	pop	esi
603
	cmp	ebx,esi
603
	cmp	ebx,esi
604
	je	line_number_ok
604
	je	line_number_ok
605
	mov	dl,20h
605
	mov	dl,20h
606
	call	display_character
606
	call	display_character
607
	push	esi
607
	push	esi
608
	mov	esi,[esi]
608
	mov	esi,[esi]
609
	movzx	ecx,byte [esi]
609
	movzx	ecx,byte [esi]
610
	inc	esi
610
	inc	esi
611
	call	display_block
611
	call	display_block
612
	mov	esi,line_number_start
612
	mov	esi,line_number_start
613
	call	display_string
613
	call	display_string
614
	pop	esi
614
	pop	esi
615
	mov	eax,[esi+4]
615
	mov	eax,[esi+4]
616
	and	eax,7FFFFFFFh
616
	and	eax,7FFFFFFFh
617
	call	display_number
617
	call	display_number
618
	mov	dl,']'
618
	mov	dl,']'
619
	call	display_character
619
	call	display_character
620
line_number_ok:
620
line_number_ok:
621
	mov	esi,line_data_start
621
	mov	esi,line_data_start
622
	call	display_string
622
	call	display_string
623
	mov	esi,ebx
623
	mov	esi,ebx
624
	mov	edx,[esi]
624
	mov	edx,[esi]
625
	call	open
625
	call	open
626
	mov	al,2
626
	mov	al,2
627
	xor	edx,edx
627
	xor	edx,edx
628
	call	lseek
628
	call	lseek
629
	mov	edx,[esi+8]
629
	mov	edx,[esi+8]
630
	sub	eax,edx
630
	sub	eax,edx
631
	push	eax
631
	push	eax
632
	xor	al,al
632
	xor	al,al
633
	call	lseek
633
	call	lseek
634
	mov	ecx,[esp]
634
	mov	ecx,[esp]
635
	mov	edx,[additional_memory]
635
	mov	edx,[additional_memory]
636
	lea	eax,[edx+ecx]
636
	lea	eax,[edx+ecx]
637
	cmp	eax,[additional_memory_end]
637
	cmp	eax,[additional_memory_end]
638
	ja	out_of_memory
638
	ja	out_of_memory
639
	call	read
639
	call	read
640
	call	close
640
	call	close
641
	pop	ecx
641
	pop	ecx
642
	mov	esi,[additional_memory]
642
	mov	esi,[additional_memory]
643
get_line_data:
643
get_line_data:
644
	mov	al,[esi]
644
	mov	al,[esi]
645
	cmp	al,0Ah
645
	cmp	al,0Ah
646
	je	display_line_data
646
	je	display_line_data
647
	cmp	al,0Dh
647
	cmp	al,0Dh
648
	je	display_line_data
648
	je	display_line_data
649
	cmp	al,1Ah
649
	cmp	al,1Ah
650
	je	display_line_data
650
	je	display_line_data
651
	or	al,al
651
	or	al,al
652
	jz	display_line_data
652
	jz	display_line_data
653
	inc	esi
653
	inc	esi
654
	loop	get_line_data
654
	loop	get_line_data
655
display_line_data:
655
display_line_data:
656
	mov	ecx,esi
656
	mov	ecx,esi
657
	mov	esi,[additional_memory]
657
	mov	esi,[additional_memory]
658
	sub	ecx,esi
658
	sub	ecx,esi
659
	call	display_block
659
	call	display_block
660
	mov	esi,cr_lf
660
	mov	esi,cr_lf
661
	call	display_string
661
	call	display_string
662
	pop	ebx
662
	pop	ebx
663
	or	ebx,ebx
663
	or	ebx,ebx
664
	jnz	display_error_line
664
	jnz	display_error_line
665
	mov	esi,error_prefix
665
	mov	esi,error_prefix
666
	call	display_string
666
	call	display_string
667
	pop	esi
667
	pop	esi
668
	call	display_string
668
	call	display_string
669
	mov	esi,error_suffix
669
	mov	esi,error_suffix
670
	call	display_string
670
	call	display_string
671
	jmp	exit_program
671
	jmp	exit_program
672
 
672
 
673
align 4
673
align 4
674
fileinfo FILEINFO
674
fileinfo FILEINFO
675
 
675
 
676
character   db ?,0
676
character   db ?,0
677
bytes_count dd ?
677
bytes_count dd ?
678
 
678
 
679
textxy	 dd 0x000500A0
679
textxy	 dd 0x000500A0
680
dc	 db 0x0
680
dc	 db 0x0
681
filesize dd 0x0
681
filesize dd 0x0
682
 
682
 
683
displayed_count dd ?
683
displayed_count dd ?
684
last_displayed	rb 2
684
last_displayed	rb 2
685
 
685
 
686
error_prefix	  db 'error: ',0
686
error_prefix	  db 'error: ',0
687
error_suffix	  db '.',0
687
error_suffix	  db '.',0
688
line_data_start   db ':'
688
line_data_start   db ':'
689
cr_lf		  db 0Dh,0Ah,0
689
cr_lf		  db 0Dh,0Ah,0
690
line_number_start db ' [',0
690
line_number_start db ' [',0
691
 
691
 
692
macro dm string { db string,0 }
692
macro dm string { db string,0 }