Subversion Repositories Kolibri OS

Rev

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