Subversion Repositories Kolibri OS

Rev

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