Subversion Repositories Kolibri OS

Rev

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