Subversion Repositories Kolibri OS

Rev

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