Subversion Repositories Kolibri OS

Rev

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