Subversion Repositories Kolibri OS

Rev

Rev 743 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 743 Rev 5098
1
include "macros.inc"
1
include "MACROS.INC"
2
;
2
;
3
; OS function implementation
3
; OS function implementation
4
; SmallC for KolibriOS
4
; SmallC for KolibriOS
5
;
5
;
6
 
6
 
7
;B+ General definitions
7
;B+ General definitions
8
 
8
 
9
;B+ File defs
9
;B+ File defs
10
 ;const
10
 ;const
11
  ;param
11
  ;param
12
  BAD	equ -1
12
  BAD	equ -1
13
  files equ 100
13
  files equ 100
14
  save_buffer		equ 0x20000 ;32
14
  save_buffer		equ 0x20000 ;32
15
  save_buffer_w 	equ 0x400000 ;32
15
  save_buffer_w 	equ 0x400000 ;32
16
  save_file_name	equ 0x20000
16
  save_file_name	equ 0x20000
17
 
17
 
18
  ;system
18
  ;system
19
  EOF equ -1
19
  EOF equ -1
20
 
20
 
21
 ;memory
21
 ;memory
22
 fileinfo     equ I_END
22
 fileinfo     equ I_END
23
 start_data   equ (fileinfo+16384)
23
 start_data   equ (fileinfo+16384)
24
 ;
24
 ;
25
 mem_heap equ 0x100000
25
 mem_heap equ 0x100000
26
 ;
26
 ;
27
 g_handle equ 0x300000
27
 g_handle equ 0x300000
28
  ;dword - pointer - relative to file
28
  ;dword - pointer - relative to file
29
  ;dword - begin of file
29
  ;dword - begin of file
30
  ;dword - file size
30
  ;dword - file size
31
  ;dword - 0/1 <=> read/write
31
  ;dword - 0/1 <=> read/write
32
;E:.
32
;E:.
33
 
33
 
34
;E:.
34
;E:.
35
 
35
 
36
init_osfunc:
36
init_osfunc:
37
;B+ Init OS functions
37
;B+ Init OS functions
38
;B+ Clear file handles
38
;B+ Clear file handles
39
  mov  edi,g_handle
39
  mov  edi,g_handle
40
  mov  ecx,files
40
  mov  ecx,files
41
  shl  ecx,2 ;*4
41
  shl  ecx,2 ;*4
42
  xor  eax,eax
42
  xor  eax,eax
43
  cld
43
  cld
44
rep stosd
44
rep stosd
45
;E:.
45
;E:.
46
  ret
46
  ret
47
;E:.
47
;E:.
48
 
48
 
49
;B+ Main OS functions
49
;B+ Main OS functions
50
ppp dd 70
50
ppp dd 70
51
 
51
 
52
_OS_fopen:
52
_OS_fopen:
53
;B+ Implement "fopen"
53
;B+ Implement "fopen"
54
  ;esp+4 - mode
54
  ;esp+4 - mode
55
  ;esp+8 - file name
55
  ;esp+8 - file name
56
 
56
 
57
;  mov  eax,-1
57
;  mov  eax,-1
58
;  int  0x40
58
;  int  0x40
59
 
59
 
60
;  mov  ebx,[esp+8];
60
;  mov  ebx,[esp+8];
61
; push dword 10
61
; push dword 10
62
; push dword [ppp]
62
; push dword [ppp]
63
; push ebx
63
; push ebx
64
; push dword 12
64
; push dword 12
65
;  call _outstrg
65
;  call _outstrg
66
;  add  esp,4*4
66
;  add  esp,4*4
67
;  add  [ppp],10
67
;  add  [ppp],10
68
 
68
 
69
;  cmp  byte [ebx+8],0
69
;  cmp  byte [ebx+8],0
70
;  jne .l
70
;  jne .l
71
;  mov  byte [ebx+8],'?'
71
;  mov  byte [ebx+8],'?'
72
;.l:
72
;.l:
73
;  cmp  [ppp],80
73
;  cmp  [ppp],80
74
;  je   .l
74
;  je   .l
75
 
75
 
76
	mov ecx , [esp+4] ; file mode
76
	mov ecx , [esp+4] ; file mode
77
    mov [file_mode],ecx
77
    mov [file_mode],ecx
78
;B+ Copy file name
78
;B+ Copy file name
79
 
79
 
80
 
80
 
81
  mov  esi,[esp+8]
81
  mov  esi,[esp+8]
82
  mov  edi,[p_filename]
82
  mov  edi,[p_filename]
83
  mov  ecx,12
83
  mov  ecx,12
84
.next_copy:
84
.next_copy:
85
lodsb
85
lodsb
86
  ;fill name (space)
86
  ;fill name (space)
87
  or   al,al
87
  or   al,al
88
  jz   .fill_space
88
  jz   .fill_space
89
  ;set upper case
89
  ;set upper case
90
  cmp  al,'a'
90
  cmp  al,'a'
91
  jb   .good_char
91
  jb   .good_char
92
  cmp  al,'z'
92
  cmp  al,'z'
93
  ja   .good_char
93
  ja   .good_char
94
  add  al,'A'-'a'
94
  add  al,'A'-'a'
95
.good_char:
95
.good_char:
96
stosb
96
stosb
97
  dec  ecx
97
  dec  ecx
98
  jnz  .next_copy
98
  jnz  .next_copy
99
.fill_space:
99
.fill_space:
100
  mov  al,' '
100
  mov  al,' '
101
  cld
101
  cld
102
rep stosb
102
rep stosb
103
 
103
 
104
mov  eax,[file_mode]
104
mov  eax,[file_mode]
105
  cmp  byte [eax],'w'
105
  cmp  byte [eax],'w'
106
  jne	.no_wri
106
  jne	.no_wri
107
 
107
 
108
 
108
 
109
;B+ Copy file name
109
;B+ Copy file name
110
  mov  esi,[esp+8]
110
  mov  esi,[esp+8]
111
  mov  edi,[w_file_name]
111
  mov  edi,[w_file_name]
112
  mov  ecx,12
112
  mov  ecx,12
113
.next_copy2:
113
.next_copy2:
114
lodsb
114
lodsb
115
  ;fill name (space)
115
  ;fill name (space)
116
  or   al,al
116
  or   al,al
117
  jz   .fill_space2
117
  jz   .fill_space2
118
  ;set upper case
118
  ;set upper case
119
  cmp  al,'a'
119
  cmp  al,'a'
120
  jb   .good_char2
120
  jb   .good_char2
121
  cmp  al,'z'
121
  cmp  al,'z'
122
  ja   .good_char2
122
  ja   .good_char2
123
  add  al,'A'-'a'
123
  add  al,'A'-'a'
124
.good_char2:
124
.good_char2:
125
stosb
125
stosb
126
  dec  ecx
126
  dec  ecx
127
  jnz  .next_copy2
127
  jnz  .next_copy2
128
.fill_space2:
128
.fill_space2:
129
  ;mov  al,' '
129
  ;mov  al,' '
130
  ;cld
130
  ;cld
131
rep stosb
131
rep stosb
132
 
132
 
133
.no_wri:
133
.no_wri:
134
 
134
 
135
 
135
 
136
 
136
 
137
;E:.
137
;E:.
138
;B+ Find file handle
138
;B+ Find file handle
139
  mov  eax,g_handle
139
  mov  eax,g_handle
140
.new_handle:
140
.new_handle:
141
  cmp  dword [eax+4],0
141
  cmp  dword [eax+4],0
142
  je   .find_place
142
  je   .find_place
143
  add  eax,16
143
  add  eax,16
144
  cmp  eax,g_handle+files*16-16
144
  cmp  eax,g_handle+files*16-16
145
  jne  .new_handle
145
  jne  .new_handle
146
  xor  eax,eax ; no free handle
146
  xor  eax,eax ; no free handle
147
  ret
147
  ret
148
.find_place:
148
.find_place:
149
; TMP:  mov  eax,[.ccc]
149
; TMP:  mov  eax,[.ccc]
150
; TMP:  add  [.ccc],16
150
; TMP:  add  [.ccc],16
151
;E:.
151
;E:.
152
 push eax
152
 push eax
153
;B+ Test open mode
153
;B+ Test open mode
154
  mov  eax,[esp+4+4]
154
  mov  eax,[esp+4+4]
155
  cmp  byte [eax],'r'
155
  cmp  byte [eax],'r'
156
  je   .open_read
156
  je   .open_read
157
  cmp  byte [eax],'w'
157
  cmp  byte [eax],'w'
158
  je   .open_write
158
  je   .open_write
159
  ;bad mode
159
  ;bad mode
160
  add  esp,4
160
  add  esp,4
161
  mov  eax,eax ; invalid open mode
161
  mov  eax,eax ; invalid open mode
162
  ret
162
  ret
163
;E:.
163
;E:.
164
 
164
 
165
; TMP:.ccc dd g_handle
165
; TMP:.ccc dd g_handle
166
 
166
 
167
.open_read:
167
.open_read:
168
;B+ Open for read
168
;B+ Open for read
169
;B+ Read file
169
;B+ Read file
170
 
170
 
171
  ;Wait to read correct
171
  ;Wait to read correct
172
  mov  ebx,100
172
  mov  ebx,100
173
  mov  eax,5
173
  mov  eax,5
174
  int  0x40
174
  int  0x40
175
 
175
 
176
  mov  eax,[g_fileend]
176
  mov  eax,[g_fileend]
177
  mov  dword [file_parameters+2*4],2000 ;read all
177
  mov  dword [file_parameters+2*4],2000 ;read all
178
  mov  dword [file_parameters+3*4],eax
178
  mov  dword [file_parameters+3*4],eax
179
 
179
 
180
  mov  dword [file_parameters],0
180
  mov  dword [file_parameters],0
181
  mov  ebx,file_parameters
181
  mov  ebx,file_parameters
182
  mov  eax,58
182
  mov  eax,58
183
  int  0x40
183
  int  0x40
184
;E:.
184
;E:.
185
 
185
 
186
;B+ TEST FILE FOUND
186
;B+ TEST FILE FOUND
187
  or   eax,eax
187
  or   eax,eax
188
  jz   .file_found
188
  jz   .file_found
189
  cmp  eax,5
189
  cmp  eax,5
190
  je   .file_found
190
  je   .file_found
191
 
191
 
192
;  mov  ecx,eax ; eax
192
;  mov  ecx,eax ; eax
193
;  mov  ebx,8 shl 16 + 0x0100
193
;  mov  ebx,8 shl 16 + 0x0100
194
;  mov  edx,100 shl 16 + 120
194
;  mov  edx,100 shl 16 + 120
195
;  mov  esi,0xffffff
195
;  mov  esi,0xffffff
196
;  mov  eax,47
196
;  mov  eax,47
197
;  int  0x40
197
;  int  0x40
198
 
198
 
199
  ;file not found - return 0
199
  ;file not found - return 0
200
  add  esp,4
200
  add  esp,4
201
  xor  eax,eax
201
  xor  eax,eax
202
  ret
202
  ret
203
.file_found:
203
.file_found:
204
;E:.
204
;E:.
205
 pop  eax
205
 pop  eax
206
 push ebx
206
 push ebx
207
  xchg eax,ebx
207
  xchg eax,ebx
208
;B+ Fill file handle
208
;B+ Fill file handle
209
  ;save current pointer
209
  ;save current pointer
210
  xor  eax,eax
210
  xor  eax,eax
211
  mov  [ebx],eax
211
  mov  [ebx],eax
212
 
212
 
213
  ;save file begin
213
  ;save file begin
214
  mov  eax,[g_fileend]
214
  mov  eax,[g_fileend]
215
  mov  [ebx+4],eax
215
  mov  [ebx+4],eax
216
 
216
 
217
  ;save file size
217
  ;save file size
218
 pop  eax
218
 pop  eax
219
  mov  [ebx+8],eax
219
  mov  [ebx+8],eax
220
  ;reserve file zone
220
  ;reserve file zone
221
  add  eax,7
221
  add  eax,7
222
  and  eax,not 7
222
  and  eax,not 7
223
  add  [g_fileend],eax
223
  add  [g_fileend],eax
224
 
224
 
225
  ;save file mode
225
  ;save file mode
226
  mov  eax,0 ;read
226
  mov  eax,0 ;read
227
  mov  [ebx+12],eax
227
  mov  [ebx+12],eax
228
;E:.
228
;E:.
229
  xchg eax,ebx ;return pointer place
229
  xchg eax,ebx ;return pointer place
230
  ret
230
  ret
231
;E:.
231
;E:.
232
 
232
 
233
.open_write:
233
.open_write:
234
;B+ Open for write
234
;B+ Open for write
235
;B+ Reserve filename
235
;B+ Reserve filename
236
 
236
 
237
; p_filename -> w_file_name
237
; p_filename -> w_file_name
238
 
238
 
239
;pusha
239
;pusha
240
;  mov eax, w_file_name
240
;  mov eax, w_file_name
241
;  mov ebx, [p_filename]
241
;  mov ebx, [p_filename]
242
;.ncpy:
242
;.ncpy:
243
;  mov ch, byte [ebx]
243
;  mov ch, byte [ebx]
244
;  cmp ch, 0
244
;  cmp ch, 0
245
;  je .ecpy
245
;  je .ecpy
246
;  mov [eax], ch
246
;  mov [eax], ch
247
;  inc dword [eax]
247
;  inc dword [eax]
248
;  inc dword [ebx]
248
;  inc dword [ebx]
249
;jmp .ncpy
249
;jmp .ncpy
250
;
250
;
251
;.ecpy:
251
;.ecpy:
252
;
252
;
253
;popa
253
;popa
254
 
254
 
255
  mov [save_buffer_p], save_buffer_w
255
  mov [save_buffer_p], save_buffer_w
256
 
256
 
257
  mov  esi,[p_filename]
257
  mov  esi,[p_filename]
258
  mov  edi,[g_fileend]
258
  mov  edi,[g_fileend]
259
  mov  ecx,12
259
  mov  ecx,12
260
  cld
260
  cld
261
rep movsb
261
rep movsb
262
  add  [g_fileend],16
262
  add  [g_fileend],16
263
;E:.
263
;E:.
264
 pop  ebx
264
 pop  ebx
265
;B+ Fill file handle
265
;B+ Fill file handle
266
  ;save begin pointer
266
  ;save begin pointer
267
  xor  eax,eax
267
  xor  eax,eax
268
  mov  [ebx],eax
268
  mov  [ebx],eax
269
 
269
 
270
  ;save file begin
270
  ;save file begin
271
  mov  eax,[g_fileend]
271
  mov  eax,[g_fileend]
272
  mov  [ebx+4],eax
272
  mov  [ebx+4],eax
273
 
273
 
274
  ;save file zone
274
  ;save file zone
275
  mov  dword [ebx+8],save_buffer
275
  mov  dword [ebx+8],save_buffer
276
  ;reserve file zone
276
  ;reserve file zone
277
  add  [g_fileend],save_buffer
277
  add  [g_fileend],save_buffer
278
 
278
 
279
  ;save file mode
279
  ;save file mode
280
  mov  eax,1 ;write
280
  mov  eax,1 ;write
281
  mov  [ebx+12],eax
281
  mov  [ebx+12],eax
282
;E:.
282
;E:.
283
  xchg eax,ebx ;return pointer place
283
  xchg eax,ebx ;return pointer place
284
  ret
284
  ret
285
;E:.
285
;E:.
286
 
286
 
287
;E:.
287
;E:.
288
 
288
 
289
_OS_fclos:
289
_OS_fclos:
290
;B+ Close file
290
;B+ Close file
291
 ;esp+4 - file handle
291
 ;esp+4 - file handle
292
 
292
 
293
;B+ Test write mode - save file
293
;B+ Test write mode - save file
294
  mov  eax,[esp+4]
294
  mov  eax,[esp+4]
295
  mov  eax,[eax+12]
295
  mov  eax,[eax+12]
296
  cmp  eax,1
296
  cmp  eax,1
297
;E:.
297
;E:.
298
  jne  .no_write
298
  jne  .no_write
299
 
299
 
300
   mov eax, [esp+4]
300
   mov eax, [esp+4]
301
   mov ecx, [eax]
301
   mov ecx, [eax]
302
   mov ebx, [eax+8]
302
   mov ebx, [eax+8]
303
 
303
 
304
   mov ebx, [save_buffer_p]
304
   mov ebx, [save_buffer_p]
305
   sub ebx, save_buffer_w
305
   sub ebx, save_buffer_w
306
	; ebx = number of read bytes = file size
306
	; ebx = number of read bytes = file size
307
    ; save loaded file
307
    ; save loaded file
308
    mov  [dest_info.bytes],ebx ; file size in bytes
308
    mov  [dest_info.bytes],ebx ; file size in bytes
309
 
309
 
310
    mov  [dest_info.bytes+4], save_buffer_w
310
    mov  [dest_info.bytes+4], save_buffer_w
311
    ;mov eax, [p_filename];[w_file_name]
311
    ;mov eax, [p_filename];[w_file_name]
312
    ;mov [destination],eax
312
    ;mov [destination],eax
313
    mov  eax,70
313
    mov  eax,70
314
    mov  ebx,dest_info
314
    mov  ebx,dest_info
315
    mcall
315
    mcall
316
 
316
 
317
    ; check if 58 function failed
317
    ; check if 58 function failed
318
    test eax,eax
318
    test eax,eax
319
    je	 .ok_write
319
    je	 .ok_write
320
    add  eax,7	      ; error number += 7
320
    add  eax,7	      ; error number += 7
321
    cmp  eax,6+7
321
    cmp  eax,6+7
322
    jna  .copy_error
322
    jna  .copy_error
323
    mov  eax,7+7
323
    mov  eax,7+7
324
    jmp  .copy_error
324
    jmp  .copy_error
325
 
325
 
326
.copy_error:
326
.copy_error:
327
  .ok_write:
327
  .ok_write:
328
 
328
 
329
 
329
 
330
;E:.
330
;E:.
331
  jmp  .read
331
  jmp  .read
332
 
332
 
333
 .no_write:
333
 .no_write:
334
;B+ Test read mode - if no error end
334
;B+ Test read mode - if no error end
335
  cmp  eax,0
335
  cmp  eax,0
336
  je   .read
336
  je   .read
337
  mov  eax,BAD
337
  mov  eax,BAD
338
  ret
338
  ret
339
;E:.
339
;E:.
340
.read:
340
.read:
341
 
341
 
342
;B+ Relace memory
342
;B+ Relace memory
343
  ;find file size
343
  ;find file size
344
  mov  eax,[esp+4]
344
  mov  eax,[esp+4]
345
  mov  ecx,[eax+8]
345
  mov  ecx,[eax+8]
346
  add  ecx,7
346
  add  ecx,7
347
  and  ecx,not 7
347
  and  ecx,not 7
348
 push ecx
348
 push ecx
349
 
349
 
350
  ;mov memory
350
  ;mov memory
351
  mov  esi,[eax+4]
351
  mov  esi,[eax+4]
352
  mov  edi,esi
352
  mov  edi,esi
353
  add  esi,ecx
353
  add  esi,ecx
354
  mov  ecx,[g_fileend]
354
  mov  ecx,[g_fileend]
355
  sub  ecx,edi
355
  sub  ecx,edi
356
  jz   .is_last
356
  jz   .is_last
357
  shr  ecx,2
357
  shr  ecx,2
358
  inc  ecx ;not neccessery
358
  inc  ecx ;not neccessery
359
  cld
359
  cld
360
rep movsd
360
rep movsd
361
  ;update gl. memory
361
  ;update gl. memory
362
.is_last:
362
.is_last:
363
 pop  ecx
363
 pop  ecx
364
  sub  dword [g_fileend],ecx
364
  sub  dword [g_fileend],ecx
365
 
365
 
366
  ;update file pointers
366
  ;update file pointers
367
  mov  edx,ecx
367
  mov  edx,ecx
368
  mov  ecx,[eax+4]
368
  mov  ecx,[eax+4]
369
  mov  eax,g_handle
369
  mov  eax,g_handle
370
.new_handle1:
370
.new_handle1:
371
  mov  ebx,[eax+4]
371
  mov  ebx,[eax+4]
372
  cmp  ebx,ecx
372
  cmp  ebx,ecx
373
  jbe  .no_update
373
  jbe  .no_update
374
  sub  ebx,edx
374
  sub  ebx,edx
375
  mov  [eax+4],ebx
375
  mov  [eax+4],ebx
376
.no_update:
376
.no_update:
377
  add  eax,16
377
  add  eax,16
378
  cmp  eax,g_handle+files*16
378
  cmp  eax,g_handle+files*16
379
  jne  .new_handle1
379
  jne  .new_handle1
380
 
380
 
381
  ;clear handle
381
  ;clear handle
382
  mov  edi,[esp+4]
382
  mov  edi,[esp+4]
383
  xor  eax,eax
383
  xor  eax,eax
384
  cld
384
  cld
385
  stosd
385
  stosd
386
  stosd
386
  stosd
387
  stosd
387
  stosd
388
  stosd
388
  stosd
389
;E:.
389
;E:.
390
  ret
390
  ret
391
;E:.
391
;E:.
392
 
392
 
393
_OS_fgetc:
393
_OS_fgetc:
394
;B+ Load char from file
394
;B+ Load char from file
395
 ;esp+4 - input file
395
 ;esp+4 - input file
396
 
396
 
397
  mov  eax,[esp+4]
397
  mov  eax,[esp+4]
398
  mov  ebx,[eax]
398
  mov  ebx,[eax]
399
  cmp  ebx,[eax+8]
399
  cmp  ebx,[eax+8]
400
  je   .eof
400
  je   .eof
401
  inc  dword [eax]
401
  inc  dword [eax]
402
  add  ebx,[eax+4]
402
  add  ebx,[eax+4]
403
  movzx eax,byte [ebx]
403
  movzx eax,byte [ebx]
404
  ret
404
  ret
405
.eof:
405
.eof:
406
  mov  eax,EOF
406
  mov  eax,EOF
407
  ret
407
  ret
408
;E:.
408
;E:.
409
 
409
 
410
;rrr db 'g',0
410
;rrr db 'g',0
411
 
411
 
412
_OS_fputc:
412
_OS_fputc:
413
;B+ Save char to file
413
;B+ Save char to file
414
 ;esp+4 - output file
414
 ;esp+4 - output file
415
 ;esp+8 - char to write
415
 ;esp+8 - char to write
416
 
416
 
417
;push dword '<'
417
;push dword '<'
418
;mov  cl,1
418
;mov  cl,1
419
;push dword 0
419
;push dword 0
420
;call test_outch
420
;call test_outch
421
;add  esp,8
421
;add  esp,8
422
 
422
 
423
 
423
 
424
 
424
 
425
;B+ Temp - write direct.
425
;B+ Temp - write direct.
426
  cmp  dword [esp+4],__iob
426
  cmp  dword [esp+4],__iob
427
  jne  .real_write0
427
  jne  .real_write0
428
  jmp  _OS_exit
428
  jmp  _OS_exit
429
.real_write0:
429
.real_write0:
430
  cmp  dword [esp+4],__iob+32
430
  cmp  dword [esp+4],__iob+32
431
  jne  .real_write1
431
  jne  .real_write1
432
  mov  [print_textcolor],0x00ffff
432
  mov  [print_textcolor],0x00ffff
433
  jmp  test_outch
433
  jmp  test_outch
434
.real_write1:
434
.real_write1:
435
  cmp  dword [esp+4],__iob+64
435
  cmp  dword [esp+4],__iob+64
436
  jne  .real_write2
436
  jne  .real_write2
437
  mov  [print_textcolor],0x77ffff
437
  mov  [print_textcolor],0x77ffff
438
  jmp  test_outch
438
  jmp  test_outch
439
.real_write2:
439
.real_write2:
440
;E:.
440
;E:.
441
 
441
 
442
mov ebx,[save_buffer_p]
442
mov ebx,[save_buffer_p]
443
mov eax,[esp+8]
443
mov eax,[esp+8]
444
mov [ebx],eax
444
mov [ebx],eax
445
inc dword [save_buffer_p]
445
inc dword [save_buffer_p]
446
 
446
 
447
 
447
 
448
ret
448
ret
449
 
449
 
450
;push dword '<'
450
;push dword '<'
451
;mov  cl,1
451
;mov  cl,1
452
;push dword 0
452
;push dword 0
453
;call test_outch
453
;call test_outch
454
;add  esp,8
454
;add  esp,8
455
 
455
 
456
  mov  eax,[esp+4]
456
  mov  eax,[esp+4]
457
  mov  ebx,[eax]
457
  mov  ebx,[eax]
458
 push ebx
458
 push ebx
459
  cmp  ebx,[eax+8]
459
  cmp  ebx,[eax+8]
460
  jne  .write_normal
460
  jne  .write_normal
461
 
461
 
462
 
462
 
463
 
463
 
464
;B+ Alloc save_buffer bytes
464
;B+ Alloc save_buffer bytes
465
  ;mov memory
465
  ;mov memory
466
  mov  ebx,[esp+4+4]
466
  mov  ebx,[esp+4+4]
467
  mov  esi,[g_fileend]
467
  mov  esi,[g_fileend]
468
  mov  edi,esi
468
  mov  edi,esi
469
  add  edi,save_buffer-4
469
  add  edi,save_buffer-4
470
  mov  ecx,esi
470
  mov  ecx,esi
471
  sub  ecx,[ebx+4]
471
  sub  ecx,[ebx+4]
472
  sub  ecx,[ebx+8]
472
  sub  ecx,[ebx+8]
473
  shr  ecx,2
473
  shr  ecx,2
474
  jz   .is_last
474
  jz   .is_last
475
  sub  esi,4
475
  sub  esi,4
476
  std
476
  std
477
rep movsd
477
rep movsd
478
.is_last:
478
.is_last:
479
 
479
 
480
  ;expand file size
480
  ;expand file size
481
  add  dword [eax+8],save_buffer
481
  add  dword [eax+8],save_buffer
482
 
482
 
483
  ;update file pointers
483
  ;update file pointers
484
  mov  ebx,g_handle
484
  mov  ebx,g_handle
485
.new_handle:
485
.new_handle:
486
  mov  ecx,[ebx+4]
486
  mov  ecx,[ebx+4]
487
  cmp  [eax+4],ecx
487
  cmp  [eax+4],ecx
488
  jae  .no_update
488
  jae  .no_update
489
  add  dword [ebx+4],save_buffer
489
  add  dword [ebx+4],save_buffer
490
.no_update:
490
.no_update:
491
  add  ebx,16
491
  add  ebx,16
492
  cmp  ebx,g_handle+files*16-16
492
  cmp  ebx,g_handle+files*16-16
493
  jne  .new_handle
493
  jne  .new_handle
494
;E:.
494
;E:.
495
 
495
 
496
.write_normal:
496
.write_normal:
497
 pop  ebx
497
 pop  ebx
498
  inc  dword [eax]
498
  inc  dword [eax]
499
  add  ebx,[eax+4]
499
  add  ebx,[eax+4]
500
  mov  cl,[esp+8]
500
  mov  cl,[esp+8]
501
  mov  byte [ebx],cl
501
  mov  byte [ebx],cl
502
 
502
 
503
;sub  [test_outch.x_coord],2
503
;sub  [test_outch.x_coord],2
504
;
504
;
505
;push dword '>'
505
;push dword '>'
506
;mov  cl,1
506
;mov  cl,1
507
;push dword 0
507
;push dword 0
508
;call test_outch
508
;call test_outch
509
;add  esp,8
509
;add  esp,8
510
;
510
;
511
;sub  [test_outch.x_coord],6
511
;sub  [test_outch.x_coord],6
512
 
512
 
513
  xor  eax,eax
513
  xor  eax,eax
514
  ret
514
  ret
515
;E:.
515
;E:.
516
 
516
 
517
_OS_callo:
517
_OS_callo:
518
;B+ Alloc memory
518
;B+ Alloc memory
519
  ;find all size
519
  ;find all size
520
  mov  eax,[esp+4]
520
  mov  eax,[esp+4]
521
  mov  ebx,[esp+8]
521
  mov  ebx,[esp+8]
522
  mul  ebx
522
  mul  ebx
523
 push eax
523
 push eax
524
 
524
 
525
  ;clear memory
525
  ;clear memory
526
  mov  edi,[.mem_p]
526
  mov  edi,[.mem_p]
527
  xor  eax,eax
527
  xor  eax,eax
528
  mov  ecx,[esp]
528
  mov  ecx,[esp]
529
  cld
529
  cld
530
rep  stosb
530
rep  stosb
531
 
531
 
532
  ;update new memory pointer
532
  ;update new memory pointer
533
 pop  ebx
533
 pop  ebx
534
 push dword [.mem_p]
534
 push dword [.mem_p]
535
  add  ebx,7
535
  add  ebx,7
536
  and  ebx,not 7
536
  and  ebx,not 7
537
  add  [.mem_p],ebx
537
  add  [.mem_p],ebx
538
 
538
 
539
  ;return value
539
  ;return value
540
 pop  eax
540
 pop  eax
541
  ret
541
  ret
542
 
542
 
543
.mem_p dd mem_heap
543
.mem_p dd mem_heap
544
;E:.
544
;E:.
545
 
545
 
546
_OS_exit:
546
_OS_exit:
547
;B+ Exit program
547
;B+ Exit program
548
;  ;TMP
548
;  ;TMP
549
;  mov  eax,-1
549
;  mov  eax,-1
550
;  int  0x40
550
;  int  0x40
551
  mov  esp,[exit_esp]
551
  mov  esp,[exit_esp]
552
  sub  esp,4
552
  sub  esp,4
553
  ret
553
  ret
554
;E:.
554
;E:.
555
 
555
 
556
;E:.
556
;E:.
557
 
557
 
558
 
558
 
559
 
559
 
560
 
560
 
561
;B+ Test procedures
561
;B+ Test procedures
562
 
562
 
563
;B+ Definitions
563
;B+ Definitions
564
LEFTMARGIN equ 11
564
LEFTMARGIN equ 11
565
BEGIN_CHARS equ 20
565
BEGIN_CHARS equ 20
566
NL equ 10
566
NL equ 10
567
;E:.
567
;E:.
568
 
568
 
569
print_textcolor dd 0x00ffff
569
print_textcolor dd 0x00ffff
570
 
570
 
571
_file_beg:
571
_file_beg:
572
;B+ Show begin of file - test fopen
572
;B+ Show begin of file - test fopen
573
 ;esp+4 - file handle (descriptor)
573
 ;esp+4 - file handle (descriptor)
574
 
574
 
575
  mov  eax,[esp+4]
575
  mov  eax,[esp+4]
576
  mov  ebx,10 shl 16 + 30
576
  mov  ebx,10 shl 16 + 30
577
  mov  ecx,[print_textcolor]
577
  mov  ecx,[print_textcolor]
578
  mov  edx,[eax+4]
578
  mov  edx,[eax+4]
579
  mov  esi,BEGIN_CHARS
579
  mov  esi,BEGIN_CHARS
580
  mov  eax,4
580
  mov  eax,4
581
  int  0x40
581
  int  0x40
582
  ret
582
  ret
583
;E:.
583
;E:.
584
 
584
 
585
_outstrg:
585
_outstrg:
586
;B+ Draw black text - test function call
586
;B+ Draw black text - test function call
587
 ;esp+4*4 - x
587
 ;esp+4*4 - x
588
 ;esp+4*3 - y
588
 ;esp+4*3 - y
589
 ;esp+4*2 - *c
589
 ;esp+4*2 - *c
590
 ;esp+4*1 - len
590
 ;esp+4*1 - len
591
 
591
 
592
  mov  ebx,[esp+4*4]
592
  mov  ebx,[esp+4*4]
593
  shl  ebx,16
593
  shl  ebx,16
594
  mov  bx,[esp+4*3]
594
  mov  bx,[esp+4*3]
595
  mov  ecx,[print_textcolor]
595
  mov  ecx,[print_textcolor]
596
  mov  edx,[esp+4*2]
596
  mov  edx,[esp+4*2]
597
  mov  esi,[esp+4]
597
  mov  esi,[esp+4]
598
  mov  eax,4
598
  mov  eax,4
599
  int  0x40
599
  int  0x40
600
  ret
600
  ret
601
;E:.
601
;E:.
602
 
602
 
603
test_outch:
603
test_outch:
604
;B+ Draw one char - use as _OS_fputc, to test printf(...)
604
;B+ Draw one char - use as _OS_fputc, to test printf(...)
605
 ;esp+8 - char to write
605
 ;esp+8 - char to write
606
 
606
 
607
  ;this is test! \b \r - not nesessary
607
  ;this is test! \b \r - not nesessary
608
 
608
 
609
  mov  al,[esp+8]
609
  mov  al,[esp+8]
610
  cmp  al,NL
610
  cmp  al,NL
611
  jne  .no_newline
611
  jne  .no_newline
612
  add  [.y_coord],10
612
  add  [.y_coord],10
613
  mov  [.x_coord],LEFTMARGIN
613
  mov  [.x_coord],LEFTMARGIN
614
  ret
614
  ret
615
.no_newline:
615
.no_newline:
616
 
616
 
617
  mov  ebx,[.x_coord]
617
  mov  ebx,[.x_coord]
618
  shl  ebx,16
618
  shl  ebx,16
619
  mov  bx,word [.y_coord]
619
  mov  bx,word [.y_coord]
620
  mov  ecx,[print_textcolor]
620
  mov  ecx,[print_textcolor]
621
  mov  [.out_char],al
621
  mov  [.out_char],al
622
  mov  edx,.out_char
622
  mov  edx,.out_char
623
  mov  esi,1
623
  mov  esi,1
624
  mov  eax,4
624
  mov  eax,4
625
  int  0x40
625
  int  0x40
626
 
626
 
627
  add  [.x_coord],6
627
  add  [.x_coord],6
628
;mov  eax,5
628
;mov  eax,5
629
;mov  ebx,5
629
;mov  ebx,5
630
;int  0x40
630
;int  0x40
631
  ret
631
  ret
632
 
632
 
633
.x_coord dd LEFTMARGIN
633
.x_coord dd LEFTMARGIN
634
.y_coord dd 60
634
.y_coord dd 60
635
.out_char db 0
635
.out_char db 0
636
;E:.
636
;E:.
637
 
637
 
638
;E:.
638
;E:.
639
 
639
 
640
;B+ Data section
640
;B+ Data section
641
;B+ Memory managment
641
;B+ Memory managment
642
g_fileend dd g_handle+files*4*4 ;from 2MB+100*4*4
642
g_fileend dd g_handle+files*4*4 ;from 2MB+100*4*4
643
;w_buff dd
643
;w_buff dd
644
;E:.
644
;E:.
645
 
645
 
646
save_buffer_p dd save_buffer_w
646
save_buffer_p dd save_buffer_w
647
;B+ File parameters
647
;B+ File parameters
648
file_parameters:
648
file_parameters:
649
 dd 0x0 ; mode
649
 dd 0x0 ; mode
650
 dd 0x0  ; first block
650
 dd 0x0  ; first block
651
 dd 1000 ; block read
651
 dd 1000 ; block read
652
 dd -1	 ; return place
652
 dd -1	 ; return place
653
 dd fileinfo ; work area
653
 dd fileinfo ; work area
654
filepath: times 100 db 0
654
filepath: times 100 db 0
655
 
655
 
656
file_mode dd 0 ;file mode
656
file_mode dd 0 ;file mode
657
 
657
 
658
dest_info:		     ; DESTINATION FILEINFO
658
dest_info:		     ; DESTINATION FILEINFO
659
	dd	2
659
	dd	2
660
	dd	0
660
	dd	0
661
	dd	0
661
	dd	0
662
.bytes	dd	?
662
.bytes	dd	?
663
	dd	save_buffer
663
	dd	save_buffer
664
	db	0
664
	db	0
665
destination:
665
destination:
666
	dd  save_file_name
666
	dd  save_file_name
667
	;db     "EXAMPLE.ASM",0
667
	;db     "EXAMPLE.ASM",0
668
 
668
 
669
 
669
 
670
 
670
 
671
w_file_name dd	save_file_name
671
w_file_name dd	save_file_name
672
 
672
 
673
p_filename dd 0x0
673
p_filename dd 0x0
674
;E:.
674
;E:.
675
;E:.
675
;E:.
676
 
676
 
677
  ;TO DO
677
  ;TO DO
678
  mov  eax,-1
678
  mov  eax,-1
679
  int  0x40
679
  int  0x40
680
  ;TO DO
680
  ;TO DO
681
;mov>
681
;mov>
682
;mov>
682
;mov>