Subversion Repositories Kolibri OS

Rev

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

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