Subversion Repositories Kolibri OS

Rev

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

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