Subversion Repositories Kolibri OS

Rev

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

Rev 1568 Rev 1573
1
;;================================================================================================;;
1
;;================================================================================================;;
2
;;//// libini_p.asm //// (c) mike.dld, 2006-2008 /////////////////////////////////////////////////;;
2
;;//// libini_p.asm //// (c) mike.dld, 2006-2008 /////////////////////////////////////////////////;;
3
;;================================================================================================;;
3
;;================================================================================================;;
4
;;                                                                                                ;;
4
;;                                                                                                ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
6
;;                                                                                                ;;
6
;;                                                                                                ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
9
;; of the License, or (at your option) any later version.                                         ;;
9
;; of the License, or (at your option) any later version.                                         ;;
10
;;                                                                                                ;;
10
;;                                                                                                ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
13
;; Lesser General Public License for more details.                                                ;;
13
;; Lesser General Public License for more details.                                                ;;
14
;;                                                                                                ;;
14
;;                                                                                                ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; If not, see .                                                    ;;
16
;; If not, see .                                                    ;;
17
;;                                                                                                ;;
17
;;                                                                                                ;;
18
;;================================================================================================;;
18
;;================================================================================================;;
19
 
19
 
20
mem.alloc   dd ?
20
mem.alloc   dd ?
21
mem.free    dd ?
21
mem.free    dd ?
22
mem.realloc dd ?
22
mem.realloc dd ?
23
dll.load    dd ?
23
dll.load    dd ?
24
 
24
 
25
;;================================================================================================;;
25
;;================================================================================================;;
26
proc libini._.init ;//////////////////////////////////////////////////////////////////////////////;;
26
proc libini._.init ;//////////////////////////////////////////////////////////////////////////////;;
27
;;------------------------------------------------------------------------------------------------;;
27
;;------------------------------------------------------------------------------------------------;;
28
;? Library entry point (called after library load)                                                ;;
28
;? Library entry point (called after library load)                                                ;;
29
;;------------------------------------------------------------------------------------------------;;
29
;;------------------------------------------------------------------------------------------------;;
30
;> eax = memory allocation routine                                                    ;;
30
;> eax = memory allocation routine                                                    ;;
31
;> ebx = memory freeing routine                                                        ;;
31
;> ebx = memory freeing routine                                                        ;;
32
;> ecx = memory reallocation routine                                                ;;
32
;> ecx = memory reallocation routine                                                ;;
33
;> edx = library loading routine                                                       ;;
33
;> edx = library loading routine                                                       ;;
34
;;------------------------------------------------------------------------------------------------;;
34
;;------------------------------------------------------------------------------------------------;;
35
;< eax = 1 (fail) / 0 (ok) (library initialization result)                                        ;;
35
;< eax = 1 (fail) / 0 (ok) (library initialization result)                                        ;;
36
;;================================================================================================;;
36
;;================================================================================================;;
37
	mov	[mem.alloc], eax
37
	mov	[mem.alloc], eax
38
	mov	[mem.free], ebx
38
	mov	[mem.free], ebx
39
	mov	[mem.realloc], ecx
39
	mov	[mem.realloc], ecx
40
	mov	[dll.load], edx
40
	mov	[dll.load], edx
41
 
41
 
42
	invoke	dll.load, @IMPORT
42
	invoke	dll.load, @IMPORT
43
	or	eax, eax
43
	or	eax, eax
44
	jz	.ok
44
	jz	.ok
45
 
45
 
46
	xor	eax, eax
46
	xor	eax, eax
47
	inc	eax
47
	inc	eax
48
	ret
48
	ret
49
 
49
 
50
  .ok:	xor	eax,eax
50
  .ok:	xor	eax,eax
51
	ret
51
	ret
52
endp
52
endp
53
 
53
 
54
;;================================================================================================;;
54
;;================================================================================================;;
55
proc libini._.unget_char _f ;/////////////////////////////////////////////////////////////////////;;
55
proc libini._.unget_char _f ;/////////////////////////////////////////////////////////////////////;;
56
;;------------------------------------------------------------------------------------------------;;
56
;;------------------------------------------------------------------------------------------------;;
57
;? --- TBD ---                                                                                    ;;
57
;? --- TBD ---                                                                                    ;;
58
;;------------------------------------------------------------------------------------------------;;
58
;;------------------------------------------------------------------------------------------------;;
59
;> --- TBD ---                                                                                    ;;
59
;> --- TBD ---                                                                                    ;;
60
;;------------------------------------------------------------------------------------------------;;
60
;;------------------------------------------------------------------------------------------------;;
61
;< --- TBD ---                                                                                    ;;
61
;< --- TBD ---                                                                                    ;;
62
;;================================================================================================;;
62
;;================================================================================================;;
63
	push	eax ecx
63
	push	eax ecx
64
	mov	ecx, [_f]
64
	mov	ecx, [_f]
65
	inc	[ecx + IniFile.cnt]
65
	inc	[ecx + IniFile.cnt]
66
	dec	esi
66
	dec	esi
67
	mov	eax, [ecx + IniFile.bsize]
67
	mov	eax, [ecx + IniFile.bsize]
68
	cmp	[ecx + IniFile.cnt], eax
68
	cmp	[ecx + IniFile.cnt], eax
69
	jle	@f
69
	jle	@f
70
	stdcall libini._.unload_block, [_f]
70
	stdcall libini._.unload_block, [_f]
71
    @@: pop	ecx eax
71
    @@: pop	ecx eax
72
	ret
72
	ret
73
endp
73
endp
74
 
74
 
75
;;================================================================================================;;
75
;;================================================================================================;;
76
proc libini._.get_char _f ;///////////////////////////////////////////////////////////////////////;;
76
proc libini._.get_char _f ;///////////////////////////////////////////////////////////////////////;;
77
;;------------------------------------------------------------------------------------------------;;
77
;;------------------------------------------------------------------------------------------------;;
78
;? --- TBD ---                                                                                    ;;
78
;? --- TBD ---                                                                                    ;;
79
;;------------------------------------------------------------------------------------------------;;
79
;;------------------------------------------------------------------------------------------------;;
80
;> --- TBD ---                                                                                    ;;
80
;> --- TBD ---                                                                                    ;;
81
;;------------------------------------------------------------------------------------------------;;
81
;;------------------------------------------------------------------------------------------------;;
82
;< --- TBD ---                                                                                    ;;
82
;< --- TBD ---                                                                                    ;;
83
;;================================================================================================;;
83
;;================================================================================================;;
-
 
84
	push ecx
84
	mov	ecx, [_f]
85
	mov	ecx, [_f]
85
	dec	[ecx + IniFile.cnt]
86
	dec	[ecx + IniFile.cnt]
86
	jns	@f
87
	jns	@f
87
	stdcall libini._.preload_block, [_f]
88
	stdcall libini._.preload_block, [_f]
88
	dec	[ecx + IniFile.cnt]
89
	dec	[ecx + IniFile.cnt]
89
    @@: lodsb
90
    @@: lodsb
-
 
91
	pop ecx
90
	ret
92
	ret
91
endp
93
endp
92
 
94
 
93
;;================================================================================================;;
95
;;================================================================================================;;
94
proc libini._.skip_nonblanks _f ;/////////////////////////////////////////////////////////////////;;
96
proc libini._.skip_nonblanks _f ;/////////////////////////////////////////////////////////////////;;
95
;;------------------------------------------------------------------------------------------------;;
97
;;------------------------------------------------------------------------------------------------;;
96
;? --- TBD ---                                                                                    ;;
98
;? --- TBD ---                                                                                    ;;
97
;;------------------------------------------------------------------------------------------------;;
99
;;------------------------------------------------------------------------------------------------;;
98
;> --- TBD ---                                                                                    ;;
100
;> --- TBD ---                                                                                    ;;
99
;;------------------------------------------------------------------------------------------------;;
101
;;------------------------------------------------------------------------------------------------;;
100
;< --- TBD ---                                                                                    ;;
102
;< --- TBD ---                                                                                    ;;
101
;;================================================================================================;;
103
;;================================================================================================;;
-
 
104
	push ecx
102
	mov	ecx, [_f]
105
	mov	ecx, [_f]
103
    @@: stdcall libini._.get_char, [_f]
106
    @@: stdcall libini._.get_char, [_f]
104
	cmp	al, 32
107
	cmp	al, 32
105
	je	@b
108
	je	@b
106
	cmp	al, 13
109
	cmp	al, 13
107
	je	@b
110
	je	@b
108
	cmp	al, 10
111
	cmp	al, 10
109
	je	@b
112
	je	@b
110
	cmp	al, 9
113
	cmp	al, 9
111
	je	@b
114
	je	@b
112
	cmp	al, ini.COMMENT_CHAR
115
	cmp	al, ini.COMMENT_CHAR
113
	jne	@f
116
	jne	@f
114
	stdcall libini._.skip_line, [_f]
117
	stdcall libini._.skip_line, [_f]
115
	jmp	@b
118
	jmp	@b
116
    @@: stdcall libini._.unget_char, [_f]
119
    @@: stdcall libini._.unget_char, [_f]
-
 
120
	pop ecx
117
	ret
121
	ret
118
endp
122
endp
119
 
123
 
120
;;================================================================================================;;
124
;;================================================================================================;;
121
proc libini._.skip_spaces _f ;////////////////////////////////////////////////////////////////////;;
125
proc libini._.skip_spaces _f ;////////////////////////////////////////////////////////////////////;;
122
;;------------------------------------------------------------------------------------------------;;
126
;;------------------------------------------------------------------------------------------------;;
123
;? --- TBD ---                                                                                    ;;
127
;? --- TBD ---                                                                                    ;;
124
;;------------------------------------------------------------------------------------------------;;
128
;;------------------------------------------------------------------------------------------------;;
125
;> --- TBD ---                                                                                    ;;
129
;> --- TBD ---                                                                                    ;;
126
;;------------------------------------------------------------------------------------------------;;
130
;;------------------------------------------------------------------------------------------------;;
127
;< --- TBD ---                                                                                    ;;
131
;< --- TBD ---                                                                                    ;;
128
;;================================================================================================;;
132
;;================================================================================================;;
-
 
133
	push ecx
129
	mov	ecx, [_f]
134
	mov	ecx, [_f]
130
    @@: stdcall libini._.get_char, [_f]
135
    @@: stdcall libini._.get_char, [_f]
131
	cmp	al, 32
136
	cmp	al, 32
132
	je	@b
137
	je	@b
133
	cmp	al, 9
138
	cmp	al, 9
134
	je	@b
139
	je	@b
135
    @@: stdcall libini._.unget_char, [_f]
140
    @@: stdcall libini._.unget_char, [_f]
-
 
141
	pop ecx
136
	ret
142
	ret
137
endp
143
endp
138
 
144
 
139
;;================================================================================================;;
145
;;================================================================================================;;
140
proc libini._.skip_line _f ;//////////////////////////////////////////////////////////////////////;;
146
proc libini._.skip_line _f ;//////////////////////////////////////////////////////////////////////;;
141
;;------------------------------------------------------------------------------------------------;;
147
;;------------------------------------------------------------------------------------------------;;
142
;? --- TBD ---                                                                                    ;;
148
;? --- TBD ---                                                                                    ;;
143
;;------------------------------------------------------------------------------------------------;;
149
;;------------------------------------------------------------------------------------------------;;
144
;> --- TBD ---                                                                                    ;;
150
;> --- TBD ---                                                                                    ;;
145
;;------------------------------------------------------------------------------------------------;;
151
;;------------------------------------------------------------------------------------------------;;
146
;< --- TBD ---                                                                                    ;;
152
;< --- TBD ---                                                                                    ;;
147
;;================================================================================================;;
153
;;================================================================================================;;
-
 
154
	push ecx
148
	mov	ecx, [_f]
155
	mov	ecx, [_f]
149
    @@: stdcall libini._.get_char, [_f]
156
    @@: stdcall libini._.get_char, [_f]
150
	or	al, al
157
	or	al, al
151
	jz	@f
158
	jz	@f
152
	cmp	al, 13
159
	cmp	al, 13
153
	je	@f
160
	je	@f
154
	cmp	al, 10
161
	cmp	al, 10
155
	jne	@b
162
	jne	@b
156
    @@: stdcall libini._.unget_char, [_f]
163
    @@: stdcall libini._.unget_char, [_f]
-
 
164
	pop ecx
157
	ret
165
	ret
158
endp
166
endp
159
 
167
 
160
;;================================================================================================;;
168
;;================================================================================================;;
161
proc libini._.unload_block _f ;///////////////////////////////////////////////////////////////////;;
169
proc libini._.unload_block _f ;///////////////////////////////////////////////////////////////////;;
162
;;------------------------------------------------------------------------------------------------;;
170
;;------------------------------------------------------------------------------------------------;;
163
;? --- TBD ---                                                                                    ;;
171
;? --- TBD ---                                                                                    ;;
164
;;------------------------------------------------------------------------------------------------;;
172
;;------------------------------------------------------------------------------------------------;;
165
;> --- TBD ---                                                                                    ;;
173
;> --- TBD ---                                                                                    ;;
166
;;------------------------------------------------------------------------------------------------;;
174
;;------------------------------------------------------------------------------------------------;;
167
;< --- TBD ---                                                                                    ;;
175
;< --- TBD ---                                                                                    ;;
168
;;================================================================================================;;
176
;;================================================================================================;;
169
	push	eax ebx ecx
177
	push	eax ebx ecx
170
	mov	ebx, [_f]
178
	mov	ebx, [_f]
171
	mov	eax, [ebx + IniFile.pos]
179
	mov	eax, [ebx + IniFile.pos]
172
	add	eax, -ini.BLOCK_SIZE
180
	add	eax, -ini.BLOCK_SIZE
173
	invoke	file.seek, [ebx + IniFile.fh], eax, SEEK_SET
181
	invoke	file.seek, [ebx + IniFile.fh], eax, SEEK_SET
174
	stdcall libini._.preload_block, ebx
182
	stdcall libini._.preload_block, ebx
175
	add	esi, eax
183
	add	esi, eax
176
	mov	[ebx + IniFile.cnt], 0
184
	mov	[ebx + IniFile.cnt], 0
177
	pop	ecx ebx eax
185
	pop	ecx ebx eax
178
	ret
186
	ret
179
endp
187
endp
180
 
188
 
181
;;================================================================================================;;
189
;;================================================================================================;;
182
proc libini._.preload_block _f ;//////////////////////////////////////////////////////////////////;;
190
proc libini._.preload_block _f ;//////////////////////////////////////////////////////////////////;;
183
;;------------------------------------------------------------------------------------------------;;
191
;;------------------------------------------------------------------------------------------------;;
184
;? --- TBD ---                                                                                    ;;
192
;? --- TBD ---                                                                                    ;;
185
;;------------------------------------------------------------------------------------------------;;
193
;;------------------------------------------------------------------------------------------------;;
186
;> --- TBD ---                                                                                    ;;
194
;> --- TBD ---                                                                                    ;;
187
;;------------------------------------------------------------------------------------------------;;
195
;;------------------------------------------------------------------------------------------------;;
188
;< --- TBD ---                                                                                    ;;
196
;< --- TBD ---                                                                                    ;;
189
;;================================================================================================;;
197
;;================================================================================================;;
190
	push	eax ebx ecx
198
	push	eax ebx ecx
191
	mov	ebx, [_f]
199
	mov	ebx, [_f]
192
    @@: mov	esi, [ebx + IniFile.buf]
200
    @@: mov	esi, [ebx + IniFile.buf]
193
	push	edi
201
	push	edi
194
	mov	edi, esi
202
	mov	edi, esi
195
	mov	ecx, ini.BLOCK_SIZE / 4
203
	mov	ecx, ini.BLOCK_SIZE / 4
196
	xor	eax, eax
204
	xor	eax, eax
197
	rep	stosd
205
	rep	stosd
198
	pop	edi
206
	pop	edi
199
	invoke	file.tell, [ebx + IniFile.fh]
207
	invoke	file.tell, [ebx + IniFile.fh]
200
	mov	[ebx + IniFile.pos], eax
208
	mov	[ebx + IniFile.pos], eax
201
	invoke	file.read, [ebx + IniFile.fh], esi, ini.BLOCK_SIZE
209
	invoke	file.read, [ebx + IniFile.fh], esi, ini.BLOCK_SIZE
202
	mov	esi,[ebx + IniFile.buf]
210
	mov	esi,[ebx + IniFile.buf]
203
	cmp	eax,ini.BLOCK_SIZE
211
	cmp	eax,ini.BLOCK_SIZE
204
	jl	@f
212
	jl	@f
205
    @@: mov	[ebx + IniFile.cnt], eax
213
    @@: mov	[ebx + IniFile.cnt], eax
206
	mov	[ebx + IniFile.bsize], eax
214
	mov	[ebx + IniFile.bsize], eax
207
	pop	ecx ebx eax
215
	pop	ecx ebx eax
208
	ret
216
	ret
209
endp
217
endp
210
 
218
 
211
;;================================================================================================;;
219
;;================================================================================================;;
212
proc libini._.reload_block _f ;///////////////////////////////////////////////////////////////////;;
220
proc libini._.reload_block _f ;///////////////////////////////////////////////////////////////////;;
213
;;------------------------------------------------------------------------------------------------;;
221
;;------------------------------------------------------------------------------------------------;;
214
;? --- TBD ---                                                                                    ;;
222
;? --- TBD ---                                                                                    ;;
215
;;------------------------------------------------------------------------------------------------;;
223
;;------------------------------------------------------------------------------------------------;;
216
;> --- TBD ---                                                                                    ;;
224
;> --- TBD ---                                                                                    ;;
217
;;------------------------------------------------------------------------------------------------;;
225
;;------------------------------------------------------------------------------------------------;;
218
;< --- TBD ---                                                                                    ;;
226
;< --- TBD ---                                                                                    ;;
219
;;================================================================================================;;
227
;;================================================================================================;;
220
	push	eax ebx ecx
228
	push	eax ebx ecx
221
	mov	ebx, [_f]
229
	mov	ebx, [_f]
222
	push	[ebx + IniFile.bsize]
230
	push	[ebx + IniFile.bsize]
223
	push	esi [ebx + IniFile.cnt]
231
	push	esi [ebx + IniFile.cnt]
224
	invoke	file.seek, [ebx + IniFile.fh], [ebx + IniFile.pos], SEEK_SET
232
	invoke	file.seek, [ebx + IniFile.fh], [ebx + IniFile.pos], SEEK_SET
225
	stdcall libini._.preload_block, ebx
233
	stdcall libini._.preload_block, ebx
226
	pop	[ebx + IniFile.cnt] esi
234
	pop	[ebx + IniFile.cnt] esi
227
	pop	eax
235
	pop	eax
228
	sub	eax,[ebx + IniFile.bsize]
236
	sub	eax,[ebx + IniFile.bsize]
229
	sub	[ebx + IniFile.cnt], eax
237
	sub	[ebx + IniFile.cnt], eax
230
	pop	ecx ebx eax
238
	pop	ecx ebx eax
231
	ret
239
	ret
232
endp
240
endp
233
 
241
 
234
; f_info - contains current file block number
242
; f_info - contains current file block number
235
; esi    - position in block from where to shift
243
; esi    - position in block from where to shift
236
; ecx    - number of bytes to shift by
244
; ecx    - number of bytes to shift by
237
 
245
 
238
;;================================================================================================;;
246
;;================================================================================================;;
239
proc libini._.shift_content _f, _delta ;//////////////////////////////////////////////////////////;;
247
proc libini._.shift_content _f, _delta ;//////////////////////////////////////////////////////////;;
240
;;------------------------------------------------------------------------------------------------;;
248
;;------------------------------------------------------------------------------------------------;;
241
;? Shift file content starting from cursor position (~ delete)                                    ;;
249
;? Shift file content starting from cursor position (~ delete)                                    ;;
242
;? Content is copied by 'delta' bytes up/down                                                     ;;
250
;? Content is copied by 'delta' bytes up/down                                                     ;;
243
;;------------------------------------------------------------------------------------------------;;
251
;;------------------------------------------------------------------------------------------------;;
244
;> --- TBD ---                                                                                    ;;
252
;> --- TBD ---                                                                                    ;;
245
;;------------------------------------------------------------------------------------------------;;
253
;;------------------------------------------------------------------------------------------------;;
246
;< eax = -1 (fail) / 0 (ok)                                                                       ;;
254
;< eax = -1 (fail) / 0 (ok)                                                                       ;;
247
;;================================================================================================;;
255
;;================================================================================================;;
248
locals
256
locals
249
  buf dd ?
257
  buf dd ?
250
endl
258
endl
251
 
259
 
252
	xor	eax, eax
260
	xor	eax, eax
253
	cmp	[_delta], 0
261
	cmp	[_delta], 0
254
	je	.skip
262
	je	.skip
255
 
263
 
256
	push	ebx ecx
264
	push	ebx ecx
257
	invoke	mem.alloc, ini.BLOCK_SIZE
265
	invoke	mem.alloc, ini.BLOCK_SIZE
258
	or	eax, eax
266
	or	eax, eax
259
	jz	.fail
267
	jz	.fail
260
	mov	[buf], eax
268
	mov	[buf], eax
261
 
269
 
262
	cmp	[_delta], 0
270
	cmp	[_delta], 0
263
	jl	.down
271
	jl	.down
264
 
272
 
265
	mov	ebx, [_f]
273
	mov	ebx, [_f]
266
	mov	ecx, [ebx + IniFile.cnt]
274
	mov	ecx, [ebx + IniFile.cnt]
267
	mov	ebx, [ebx + IniFile.fh]
275
	mov	ebx, [ebx + IniFile.fh]
268
	invoke	file.tell, ebx
276
	invoke	file.tell, ebx
269
	sub	eax, ecx
277
	sub	eax, ecx
270
	invoke	file.seek, ebx, eax, SEEK_SET
278
	invoke	file.seek, ebx, eax, SEEK_SET
271
    @@: invoke	file.seek, ebx, [_delta], SEEK_CUR
279
    @@: invoke	file.seek, ebx, [_delta], SEEK_CUR
272
	invoke	file.eof?, ebx
280
	invoke	file.eof?, ebx
273
	or	eax, eax
281
	or	eax, eax
274
	jnz	.done
282
	jnz	.done
275
	invoke	file.read, ebx, [buf], ini.BLOCK_SIZE
283
	invoke	file.read, ebx, [buf], ini.BLOCK_SIZE
276
	mov	ecx, eax
284
	mov	ecx, eax
277
	mov	eax, [_delta]
285
	mov	eax, [_delta]
278
	neg	eax
286
	neg	eax
279
	sub	eax, ecx
287
	sub	eax, ecx
280
	invoke	file.seek, ebx, eax, SEEK_CUR
288
	invoke	file.seek, ebx, eax, SEEK_CUR
281
	push	ecx
289
	push	ecx
282
	invoke	file.write, ebx, [buf], ecx
290
	invoke	file.write, ebx, [buf], ecx
283
	pop	ecx
291
	pop	ecx
284
	cmp	eax, ecx
292
	cmp	eax, ecx
285
	jz	@b
293
	jz	@b
286
  .fail:
294
  .fail:
287
	or	eax, -1
295
	or	eax, -1
288
	pop	ecx ebx
296
	pop	ecx ebx
289
	ret
297
	ret
290
  .done:
298
  .done:
291
	mov	eax, [_delta]
299
	mov	eax, [_delta]
292
	neg	eax
300
	neg	eax
293
	invoke	file.seek, ebx, eax, SEEK_CUR
301
	invoke	file.seek, ebx, eax, SEEK_CUR
294
	invoke	file.seteof, ebx
302
	invoke	file.seteof, ebx
295
	stdcall libini._.reload_block, [_f]
303
	stdcall libini._.reload_block, [_f]
296
	invoke	mem.free, [buf]
304
	invoke	mem.free, [buf]
297
	pop	ecx ebx
305
	pop	ecx ebx
298
  .skip:
306
  .skip:
299
	ret
307
	ret
300
 
308
 
301
  .down:
309
  .down:
302
	neg	[_delta]
310
	neg	[_delta]
303
 
311
 
304
	mov	ebx, [_f]
312
	mov	ebx, [_f]
305
	mov	ecx, [ebx + IniFile.cnt]
313
	mov	ecx, [ebx + IniFile.cnt]
306
	mov	ebx, [ebx + IniFile.fh]
314
	mov	ebx, [ebx + IniFile.fh]
307
	invoke	file.tell, ebx
315
	invoke	file.tell, ebx
308
	sub	eax, ecx
316
	sub	eax, ecx
309
	lea	edx, [eax - 1]
317
	lea	edx, [eax - 1]
310
	push	edx
318
	push	edx
311
    @@: invoke	file.seek, ebx, edx, SEEK_SET
319
    @@: invoke	file.seek, ebx, edx, SEEK_SET
312
	invoke	file.eof?, ebx
320
	invoke	file.eof?, ebx
313
	or	eax, eax
321
	or	eax, eax
314
	jnz	@f
322
	jnz	@f
315
	add	edx, ini.BLOCK_SIZE
323
	add	edx, ini.BLOCK_SIZE
316
	jmp	@b
324
	jmp	@b
317
    @@: cmp	edx, [esp]
325
    @@: cmp	edx, [esp]
318
	je	.skip.2
326
	je	.skip.2
319
	add	edx, -ini.BLOCK_SIZE
327
	add	edx, -ini.BLOCK_SIZE
320
	cmp	edx, [esp]
328
	cmp	edx, [esp]
321
	jl	@f
329
	jl	@f
322
	invoke	file.seek, ebx, edx, SEEK_SET
330
	invoke	file.seek, ebx, edx, SEEK_SET
323
	invoke	file.read, ebx, [buf], ini.BLOCK_SIZE
331
	invoke	file.read, ebx, [buf], ini.BLOCK_SIZE
324
	mov	ecx, eax
332
	mov	ecx, eax
325
	mov	eax, [_delta]
333
	mov	eax, [_delta]
326
	sub	eax, ecx
334
	sub	eax, ecx
327
	invoke	file.seek, ebx, eax, SEEK_CUR
335
	invoke	file.seek, ebx, eax, SEEK_CUR
328
	invoke	file.write, ebx, [buf], ecx
336
	invoke	file.write, ebx, [buf], ecx
329
	jmp	@b
337
	jmp	@b
330
    @@:
338
    @@:
331
  .skip.2:
339
  .skip.2:
332
	add	esp, 4
340
	add	esp, 4
333
	stdcall libini._.reload_block, [_f]
341
	stdcall libini._.reload_block, [_f]
334
	invoke	mem.free, [buf]
342
	invoke	mem.free, [buf]
335
	pop	ecx ebx
343
	pop	ecx ebx
336
	ret
344
	ret
337
endp
345
endp
338
 
346
 
339
;;================================================================================================;;
347
;;================================================================================================;;
340
proc libini._.get_value_length _f ;///////////////////////////////////////////////////////////////;;
348
proc libini._.get_value_length _f ;///////////////////////////////////////////////////////////////;;
341
;;------------------------------------------------------------------------------------------------;;
349
;;------------------------------------------------------------------------------------------------;;
342
;? --- TBD ---                                                                                    ;;
350
;? --- TBD ---                                                                                    ;;
343
;;------------------------------------------------------------------------------------------------;;
351
;;------------------------------------------------------------------------------------------------;;
344
;> --- TBD ---                                                                                    ;;
352
;> --- TBD ---                                                                                    ;;
345
;;------------------------------------------------------------------------------------------------;;
353
;;------------------------------------------------------------------------------------------------;;
346
;< --- TBD ---                                                                                    ;;
354
;< --- TBD ---                                                                                    ;;
347
;;================================================================================================;;
355
;;================================================================================================;;
348
	push	ebx ecx edx eax
356
	push	ebx ecx edx eax
349
	mov	ebx, [_f]
357
	mov	ebx, [_f]
350
	invoke	file.tell, [ebx + IniFile.fh]
358
	invoke	file.tell, [ebx + IniFile.fh]
351
	push	esi [ebx + IniFile.cnt] [ebx + IniFile.pos]
359
	push	esi [ebx + IniFile.cnt] [ebx + IniFile.pos]
352
	sub	eax, [ebx + IniFile.cnt]
360
	sub	eax, [ebx + IniFile.cnt]
353
	mov	edx, eax
361
	mov	edx, eax
354
 
362
 
355
	stdcall libini._.skip_line, [_f]
363
	stdcall libini._.skip_line, [_f]
356
	invoke	file.tell, [ebx + IniFile.fh]
364
	invoke	file.tell, [ebx + IniFile.fh]
357
	sub	eax, [ebx + IniFile.cnt]
365
	sub	eax, [ebx + IniFile.cnt]
358
	sub	eax, edx
366
	sub	eax, edx
359
	mov	[esp + 4 * 3], eax
367
	mov	[esp + 4 * 3], eax
360
 
368
 
361
	pop	eax
369
	pop	eax
362
	invoke	file.seek, [ebx + IniFile.fh], eax, SEEK_SET
370
	invoke	file.seek, [ebx + IniFile.fh], eax, SEEK_SET
363
	stdcall libini._.preload_block, [_f]
371
	stdcall libini._.preload_block, [_f]
364
	pop	[ebx + IniFile.cnt] esi
372
	pop	[ebx + IniFile.cnt] esi
365
	pop	eax edx ecx ebx
373
	pop	eax edx ecx ebx
366
	ret
374
	ret
367
endp
375
endp
368
 
376
 
369
;;================================================================================================;;
377
;;================================================================================================;;
370
proc libini._.string_copy ;///////////////////////////////////////////////////////////////////////;;
378
proc libini._.string_copy ;///////////////////////////////////////////////////////////////////////;;
371
;;------------------------------------------------------------------------------------------------;;
379
;;------------------------------------------------------------------------------------------------;;
372
;? --- TBD ---                                                                                    ;;
380
;? --- TBD ---                                                                                    ;;
373
;;------------------------------------------------------------------------------------------------;;
381
;;------------------------------------------------------------------------------------------------;;
374
;> --- TBD ---                                                                                    ;;
382
;> --- TBD ---                                                                                    ;;
375
;;------------------------------------------------------------------------------------------------;;
383
;;------------------------------------------------------------------------------------------------;;
376
;< --- TBD ---                                                                                    ;;
384
;< --- TBD ---                                                                                    ;;
377
;;================================================================================================;;
385
;;================================================================================================;;
378
    @@: lodsb
386
    @@: lodsb
379
	or	al, al
387
	or	al, al
380
	jz	@f
388
	jz	@f
381
	stosb
389
	stosb
382
	jmp	@b
390
	jmp	@b
383
    @@: ret
391
    @@: ret
384
endp
392
endp
385
 
393
 
386
;;================================================================================================;;
394
;;================================================================================================;;
387
proc libini._.find_next_section _f ;//////////////////////////////////////////////////////////////;;
395
proc libini._.find_next_section _f ;//////////////////////////////////////////////////////////////;;
388
;;------------------------------------------------------------------------------------------------;;
396
;;------------------------------------------------------------------------------------------------;;
389
;? --- TBD ---                                                                                    ;;
397
;? --- TBD ---                                                                                    ;;
390
;;------------------------------------------------------------------------------------------------;;
398
;;------------------------------------------------------------------------------------------------;;
391
;> --- TBD ---                                                                                    ;;
399
;> --- TBD ---                                                                                    ;;
392
;;------------------------------------------------------------------------------------------------;;
400
;;------------------------------------------------------------------------------------------------;;
393
;< --- TBD ---                                                                                    ;;
401
;< --- TBD ---                                                                                    ;;
394
;;================================================================================================;;
402
;;================================================================================================;;
395
	push	ebx edi
403
	push	ebx edi
396
 
404
 
397
    @@: stdcall libini._.skip_nonblanks, [_f]
405
    @@: stdcall libini._.skip_nonblanks, [_f]
398
	cmp	al, '['
406
	cmp	al, '['
399
	je	@f
407
	je	@f
400
	or	al, al
408
	or	al, al
401
	jz	.exit_error
409
	jz	.exit_error
402
	stdcall libini._.skip_line, [_f]
410
	stdcall libini._.skip_line, [_f]
403
	or	al, al
411
	or	al, al
404
	jz	.exit_error
412
	jz	.exit_error
405
	jmp	@b
413
	jmp	@b
406
    @@:
414
    @@:
407
	pop	edi ebx
415
	pop	edi ebx
408
	xor	eax, eax
416
	xor	eax, eax
409
	ret
417
	ret
410
 
418
 
411
  .exit_error:
419
  .exit_error:
412
	pop	edi ebx
420
	pop	edi ebx
413
	or	eax, -1
421
	or	eax, -1
414
	ret
422
	ret
415
endp
423
endp
416
 
424
 
417
;;================================================================================================;;
425
;;================================================================================================;;
418
proc libini._.find_section _f, _sec_name ;////////////////////////////////////////////////////////;;
426
proc libini._.find_section _f, _sec_name ;////////////////////////////////////////////////////////;;
419
;;------------------------------------------------------------------------------------------------;;
427
;;------------------------------------------------------------------------------------------------;;
420
;? Find section in file                                                                           ;;
428
;? Find section in file                                                                           ;;
421
;? Search is performed from the beginning of file                                                 ;;
429
;? Search is performed from the beginning of file                                                 ;;
422
;;------------------------------------------------------------------------------------------------;;
430
;;------------------------------------------------------------------------------------------------;;
423
;> --- TBD ---                                                                                    ;;
431
;> --- TBD ---                                                                                    ;;
424
;;------------------------------------------------------------------------------------------------;;
432
;;------------------------------------------------------------------------------------------------;;
425
;< eax = -1 (fail) / 0 (ok)                                                                       ;;
433
;< eax = -1 (fail) / 0 (ok)                                                                       ;;
426
;< [_f.pos] = new cursor position (right after ']' char if eax = 0, at the end of file otherwise) ;;
434
;< [_f.pos] = new cursor position (right after ']' char if eax = 0, at the end of file otherwise) ;;
427
;;================================================================================================;;
435
;;================================================================================================;;
428
	push	ebx edi
436
	push	ebx ecx edi
429
 
437
 
430
	mov	ecx, [_f]
438
	mov	ecx, [_f]
431
	invoke	file.seek, [ecx + IniFile.fh], 0, SEEK_SET
439
	invoke	file.seek, [ecx + IniFile.fh], 0, SEEK_SET
432
	stdcall libini._.preload_block, [_f]
440
	stdcall libini._.preload_block, [_f]
433
 
441
 
434
  .next_section:
442
  .next_section:
435
	stdcall libini._.find_next_section, [_f]
443
	stdcall libini._.find_next_section, [_f]
436
	or	eax, eax
444
	or	eax, eax
437
	jnz	.exit_error
445
	jnz	.exit_error
438
 
446
 
439
	stdcall libini._.get_char, [_f]
447
	stdcall libini._.get_char, [_f]
440
	stdcall libini._.skip_spaces, [_f]
448
	stdcall libini._.skip_spaces, [_f]
441
	mov	edi, [_sec_name]
449
	mov	edi, [_sec_name]
442
    @@: stdcall libini._.get_char, [_f]
450
    @@: stdcall libini._.get_char, [_f]
443
	cmp	al, ']'
451
	cmp	al, ']'
444
	je	@f
452
	je	@f
445
	or	al, al
453
	or	al, al
446
	jz	.exit_error
454
	jz	.exit_error
447
	cmp	al, 13
455
	cmp	al, 13
448
	je	.next_section
456
	je	.next_section
449
	cmp	al, 10
457
	cmp	al, 10
450
	je	.next_section
458
	je	.next_section
451
	scasb
459
	scasb
452
	je	@b
460
	je	@b
453
	cmp	byte[edi - 1], 0
461
	cmp	byte[edi - 1], 0
454
	jne	.next_section
462
	jne	.next_section
455
	dec	edi
463
	dec	edi
456
	stdcall libini._.unget_char, [_f]
464
	stdcall libini._.unget_char, [_f]
457
	stdcall libini._.skip_spaces, [_f]
465
	stdcall libini._.skip_spaces, [_f]
458
	stdcall libini._.get_char, [_f]
466
	stdcall libini._.get_char, [_f]
459
	cmp	al, ']'
467
	cmp	al, ']'
460
	jne	.next_section
468
	jne	.next_section
461
    @@:
469
    @@:
462
	cmp	byte[edi], 0
470
	cmp	byte[edi], 0
463
	jne	.next_section
471
	jne	.next_section
464
	pop	edi ebx
472
	pop	edi ecx ebx
465
	xor	eax, eax
473
	xor	eax, eax
466
	ret
474
	ret
467
 
475
 
468
  .exit_error:
476
  .exit_error:
469
	pop	edi ebx
477
	pop	edi ecx ebx
470
	or	eax, -1
478
	or	eax, -1
471
	ret
479
	ret
472
endp
480
endp
473
 
481
 
474
;;================================================================================================;;
482
;;================================================================================================;;
475
proc libini._.find_key _f, _key_name ;////////////////////////////////////////////////////////////;;
483
proc libini._.find_key _f, _key_name ;////////////////////////////////////////////////////////////;;
476
;;------------------------------------------------------------------------------------------------;;
484
;;------------------------------------------------------------------------------------------------;;
477
;? Find key in section                                                                            ;;
485
;? Find key in section                                                                            ;;
478
;? Search is performed within current section starting from cursor position                       ;;
486
;? Search is performed within current section starting from cursor position                       ;;
479
;;------------------------------------------------------------------------------------------------;;
487
;;------------------------------------------------------------------------------------------------;;
480
;> --- TBD ---                                                                                    ;;
488
;> --- TBD ---                                                                                    ;;
481
;;------------------------------------------------------------------------------------------------;;
489
;;------------------------------------------------------------------------------------------------;;
482
;< eax = -1 (fail) / 0 (ok)                                                                       ;;
490
;< eax = -1 (fail) / 0 (ok)                                                                       ;;
483
;< [_f.pos] = new cursor position (right after '=' char if eax = 0, at the end of file or right   ;;
491
;< [_f.pos] = new cursor position (right after '=' char if eax = 0, at the end of file or right   ;;
484
;<            before '[' char otherwise)                                                          ;;
492
;<            before '[' char otherwise)                                                          ;;
485
;;================================================================================================;;
493
;;================================================================================================;;
486
	push	ebx edi
494
	push	ebx edi
487
 
495
 
488
  .next_value:
496
  .next_value:
489
	mov	edi, [_key_name]
497
	mov	edi, [_key_name]
490
	stdcall libini._.skip_line, [_f]
498
	stdcall libini._.skip_line, [_f]
491
	stdcall libini._.skip_nonblanks, [_f]
499
	stdcall libini._.skip_nonblanks, [_f]
492
	or	al, al
500
	or	al, al
493
	jz	.exit_error
501
	jz	.exit_error
494
	cmp	al, '['
502
	cmp	al, '['
495
	je	.exit_error
503
	je	.exit_error
496
    @@: stdcall libini._.get_char, [_f]
504
    @@: stdcall libini._.get_char, [_f]
497
	or	al, al
505
	or	al, al
498
	jz	.exit_error
506
	jz	.exit_error
499
	cmp	al, '='
507
	cmp	al, '='
500
	je	@f
508
	je	@f
501
	scasb
509
	scasb
502
	je	@b
510
	je	@b
503
	cmp	byte[edi - 1], 0
511
	cmp	byte[edi - 1], 0
504
	jne	.next_value
512
	jne	.next_value
505
	dec	edi
513
	dec	edi
506
	stdcall libini._.unget_char, [_f]
514
	stdcall libini._.unget_char, [_f]
507
	stdcall libini._.skip_spaces, [_f]
515
	stdcall libini._.skip_spaces, [_f]
508
	stdcall libini._.get_char, [_f]
516
	stdcall libini._.get_char, [_f]
509
	cmp	al, '='
517
	cmp	al, '='
510
	je	@f
518
	je	@f
511
	jmp	.next_value
519
	jmp	.next_value
512
    @@:
520
    @@:
513
	cmp	byte[edi], 0
521
	cmp	byte[edi], 0
514
	jne	.next_value
522
	jne	.next_value
515
 
523
 
516
	pop	edi ebx
524
	pop	edi ebx
517
	xor	eax, eax
525
	xor	eax, eax
518
	ret
526
	ret
519
 
527
 
520
  .exit_error:
528
  .exit_error:
521
	pop	edi ebx
529
	pop	edi ebx
522
	or	eax, -1
530
	or	eax, -1
523
	ret
531
	ret
524
endp
532
endp
525
 
533
 
526
;;================================================================================================;;
534
;;================================================================================================;;
527
proc libini._.low.read_value _f_addr, _buffer, _buf_len ;/////////////////////////////////////////;;
535
proc libini._.low.read_value _f_addr, _buffer, _buf_len ;/////////////////////////////////////////;;
528
;;------------------------------------------------------------------------------------------------;;
536
;;------------------------------------------------------------------------------------------------;;
529
;? --- TBD ---                                                                                    ;;
537
;? --- TBD ---                                                                                    ;;
530
;;------------------------------------------------------------------------------------------------;;
538
;;------------------------------------------------------------------------------------------------;;
531
;> --- TBD ---                                                                                    ;;
539
;> --- TBD ---                                                                                    ;;
532
;;------------------------------------------------------------------------------------------------;;
540
;;------------------------------------------------------------------------------------------------;;
533
;< --- TBD ---                                                                                    ;;
541
;< --- TBD ---                                                                                    ;;
534
;;================================================================================================;;
542
;;================================================================================================;;
535
	push	edi eax
543
	push	edi eax
536
	mov	edi, [_buffer]
544
	mov	edi, [_buffer]
537
	stdcall libini._.skip_spaces, [_f_addr]
545
	stdcall libini._.skip_spaces, [_f_addr]
538
    @@: dec	[_buf_len]
546
    @@: dec	[_buf_len]
539
	jz	@f
547
	jz	@f
540
	stdcall libini._.get_char, [_f_addr]
548
	stdcall libini._.get_char, [_f_addr]
541
	cmp	al, 13
549
	cmp	al, 13
542
	je	@f
550
	je	@f
543
	cmp	al, 10
551
	cmp	al, 10
544
	je	@f
552
	je	@f
545
	stosb
553
	stosb
546
	or	al, al
554
	or	al, al
547
	jnz	@b
555
	jnz	@b
548
    @@: stdcall libini._.unget_char, [_f_addr]
556
    @@: stdcall libini._.unget_char, [_f_addr]
549
	mov	byte[edi], 0
557
	mov	byte[edi], 0
550
	dec	edi
558
	dec	edi
551
    @@: cmp	edi, [_buffer]
559
    @@: cmp	edi, [_buffer]
552
	jb	@f
560
	jb	@f
553
	cmp	byte[edi], 32
561
	cmp	byte[edi], 32
554
	ja	@f
562
	ja	@f
555
	mov	byte[edi], 0
563
	mov	byte[edi], 0
556
	dec	edi
564
	dec	edi
557
	jmp	@b
565
	jmp	@b
558
    @@: pop	eax edi
566
    @@: pop	eax edi
559
	ret
567
	ret
560
endp
568
endp
561
 
569
 
562
;;================================================================================================;;
570
;;================================================================================================;;
563
proc libini._.str_to_int ;////////////////////////////////////////////////////////////////////////;;
571
proc libini._.str_to_int ;////////////////////////////////////////////////////////////////////////;;
564
;;------------------------------------------------------------------------------------------------;;
572
;;------------------------------------------------------------------------------------------------;;
565
;? --- TBD ---                                                                                    ;;
573
;? --- TBD ---                                                                                    ;;
566
;;------------------------------------------------------------------------------------------------;;
574
;;------------------------------------------------------------------------------------------------;;
567
;> esi = string buffer address                                                                    ;;
575
;> esi = string buffer address                                                                    ;;
568
;;------------------------------------------------------------------------------------------------;;
576
;;------------------------------------------------------------------------------------------------;;
569
;< eax = binary number representation (no overflow checks made)                                   ;;
577
;< eax = binary number representation (no overflow checks made)                                   ;;
570
;;================================================================================================;;
578
;;================================================================================================;;
571
	push	edx
579
	push	edx
572
 
580
 
573
	xor	eax, eax
581
	xor	eax, eax
574
	xor	edx, edx
582
	xor	edx, edx
575
 
583
 
576
    @@: lodsb
584
    @@: lodsb
577
	cmp	al, '0'
585
	cmp	al, '0'
578
	jb	@f
586
	jb	@f
579
	cmp	al, '9'
587
	cmp	al, '9'
580
	ja	@f
588
	ja	@f
581
	add	eax, -'0'
589
	add	eax, -'0'
582
	imul	edx, 10
590
	imul	edx, 10
583
	add	edx, eax
591
	add	edx, eax
584
	jmp	@b
592
	jmp	@b
585
 
593
 
586
    @@: dec	esi
594
    @@: dec	esi
587
	mov	eax, edx
595
	mov	eax, edx
588
	pop	edx
596
	pop	edx
589
	ret
597
	ret
590
endp
598
endp
591
 
599
 
592
;;================================================================================================;;
600
;;================================================================================================;;
593
proc libini._.int_to_str ;////////////////////////////////////////////////////////////////////////;;
601
proc libini._.int_to_str ;////////////////////////////////////////////////////////////////////////;;
594
;;------------------------------------------------------------------------------------------------;;
602
;;------------------------------------------------------------------------------------------------;;
595
;? --- TBD ---                                                                                    ;;
603
;? --- TBD ---                                                                                    ;;
596
;;------------------------------------------------------------------------------------------------;;
604
;;------------------------------------------------------------------------------------------------;;
597
;> eax = number to convert                                                                        ;;
605
;> eax = number to convert                                                                        ;;
598
;> ecx = base                                                                                     ;;
606
;> ecx = base                                                                                     ;;
599
;> edi = string buffer address                                                                    ;;
607
;> edi = string buffer address                                                                    ;;
600
;;------------------------------------------------------------------------------------------------;;
608
;;------------------------------------------------------------------------------------------------;;
601
;< --- TBD ---                                                                                    ;;
609
;< --- TBD ---                                                                                    ;;
602
;;================================================================================================;;
610
;;================================================================================================;;
603
	push	ecx edx
611
	push	ecx edx
604
 
612
 
605
	or	eax, eax
613
	or	eax, eax
606
	jns	@f
614
	jns	@f
607
	mov	byte[edi], '-'
615
	mov	byte[edi], '-'
608
	inc	edi
616
	inc	edi
609
    @@: call	.recurse
617
    @@: call	.recurse
610
	pop	edx ecx
618
	pop	edx ecx
611
	ret
619
	ret
612
 
620
 
613
  .recurse:
621
  .recurse:
614
	cmp	eax,ecx
622
	cmp	eax,ecx
615
	jb	@f
623
	jb	@f
616
	xor	edx,edx
624
	xor	edx,edx
617
	div	ecx
625
	div	ecx
618
	push	edx
626
	push	edx
619
	call	.recurse
627
	call	.recurse
620
	pop	eax
628
	pop	eax
621
    @@: cmp	al,10
629
    @@: cmp	al,10
622
	sbb	al,0x69
630
	sbb	al,0x69
623
	das
631
	das
624
	stosb
632
	stosb
625
	retn
633
	retn
626
endp
634
endp
627
 
635
 
628
;;================================================================================================;;
636
;;================================================================================================;;
629
proc libini._.ascii_to_scan ;_ascii_code ;////////////////////////////////////////////////////////;;
637
proc libini._.ascii_to_scan ;_ascii_code ;////////////////////////////////////////////////////////;;
630
;;------------------------------------------------------------------------------------------------;;
638
;;------------------------------------------------------------------------------------------------;;
631
;? Translate ASCII code of key to scancode using standard mapping from keymap.key                 ;;
639
;? Translate ASCII code of key to scancode using standard mapping from keymap.key                 ;;
632
;;------------------------------------------------------------------------------------------------;;
640
;;------------------------------------------------------------------------------------------------;;
633
;> _ascii_code = [esp+4] = ASCII code to convert                                                  ;;
641
;> _ascii_code = [esp+4] = ASCII code to convert                                                  ;;
634
;;------------------------------------------------------------------------------------------------;;
642
;;------------------------------------------------------------------------------------------------;;
635
;< eax = 0 (error) / scancode (success)                                                           ;;
643
;< eax = 0 (error) / scancode (success)                                                           ;;
636
;;================================================================================================;;
644
;;================================================================================================;;
637
; /sys/keymap.key
645
; /sys/keymap.key
638
	sub	esp, 256
646
	sub	esp, 256
639
	mov	eax, esp
647
	mov	eax, esp
640
	push	ebx
648
	push	ebx
641
	push	'key'
649
	push	'key'
642
	push	'map.'
650
	push	'map.'
643
	push	'/key'
651
	push	'/key'
644
	push	'/sys'
652
	push	'/sys'
645
	push	eax	; buffer in the stack
653
	push	eax	; buffer in the stack
646
	push	0x100	; read 0x100 bytes
654
	push	0x100	; read 0x100 bytes
647
	push	0
655
	push	0
648
	push	0	; from position zero
656
	push	0	; from position zero
649
	push	0	; subfunction: read
657
	push	0	; subfunction: read
650
	mov	ebx, esp
658
	mov	ebx, esp
651
	push	70
659
	push	70
652
	pop	eax
660
	pop	eax
653
	mcall
661
	mcall
654
	add	esp, 36
662
	add	esp, 36
655
	pop	ebx
663
	pop	ebx
656
	test	eax, eax
664
	test	eax, eax
657
	jnz	.die
665
	jnz	.die
658
	mov	al, [esp+256+4]	; get ASCII code
666
	mov	al, [esp+256+4]	; get ASCII code
659
	push	edi
667
	push	edi
660
; first keytable - no modifiers pressed
668
; first keytable - no modifiers pressed
661
; check scancodes from 1 to 36h (inclusive)
669
; check scancodes from 1 to 36h (inclusive)
662
	lea	edi, [esp+4+1]
670
	lea	edi, [esp+4+1]
663
	mov	edx, edi
671
	mov	edx, edi
664
	mov	ecx, 36h
672
	mov	ecx, 36h
665
	repnz	scasb
673
	repnz	scasb
666
	jz	.found
674
	jz	.found
667
; second keytable - Shift pressed
675
; second keytable - Shift pressed
668
	lea	edi, [esp+4+128+1]
676
	lea	edi, [esp+4+128+1]
669
	mov	edx, edi
677
	mov	edx, edi
670
	mov	ecx, 36h
678
	mov	ecx, 36h
671
	repnz	scasb
679
	repnz	scasb
672
	jz	.found
680
	jz	.found
673
	pop	edi
681
	pop	edi
674
.die:
682
.die:
675
	xor	eax, eax
683
	xor	eax, eax
676
	jmp	.ret
684
	jmp	.ret
677
.found:
685
.found:
678
	mov	eax, edi
686
	mov	eax, edi
679
	sub	eax, edx
687
	sub	eax, edx
680
	pop	edi
688
	pop	edi
681
.ret:
689
.ret:
682
	add	esp, 256
690
	add	esp, 256
683
	ret	4
691
	ret	4
684
endp
692
endp