Subversion Repositories Kolibri OS

Rev

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

Rev 987 Rev 3014
1
diff16 'tp-common.asm',0,$
1
diff16 'tp-common.asm',0,$
2
 
2
 
3
;-----------------------------------------------------------------------------
3
;-----------------------------------------------------------------------------
4
proc clear_selection ;////////////////////////////////////////////////////////
4
proc clear_selection ;////////////////////////////////////////////////////////
5
;-----------------------------------------------------------------------------
5
;-----------------------------------------------------------------------------
6
	push	eax ebx
6
	push	eax ebx
7
	mov	eax,[cur_editor.SelStart.Y]
7
	mov	eax,[cur_editor.SelStart.Y]
8
	mov	ebx,[cur_editor.Caret.Y]
8
	mov	ebx,[cur_editor.Caret.Y]
9
	cmp	eax,ebx
9
	cmp	eax,ebx
10
	jle	@f
10
	jle	@f
11
	xchg	eax,ebx
11
	xchg	eax,ebx
12
    @@: push	[cur_editor.Caret.X] [cur_editor.Caret.Y]
12
    @@: push	[cur_editor.Caret.X] [cur_editor.Caret.Y]
13
	pop	[cur_editor.SelStart.Y] [cur_editor.SelStart.X]
13
	pop	[cur_editor.SelStart.Y] [cur_editor.SelStart.X]
14
	pop	ebx eax
14
	pop	ebx eax
15
	ret
15
	ret
16
endp
16
endp
17
 
17
 
18
;-----------------------------------------------------------------------------
18
;-----------------------------------------------------------------------------
19
proc pt_in_rect ;/////////////////////////////////////////////////////////////
19
proc pt_in_rect ;/////////////////////////////////////////////////////////////
20
;-----------------------------------------------------------------------------
20
;-----------------------------------------------------------------------------
21
	cmp	eax,[ecx+0x0]
21
	cmp	eax,[ecx+0x0]
22
	jl	@f
22
	jl	@f
23
	cmp	ebx,[ecx+0x4]
23
	cmp	ebx,[ecx+0x4]
24
	jl	@f
24
	jl	@f
25
	cmp	eax,[ecx+0x8]
25
	cmp	eax,[ecx+0x8]
26
	jg	@f
26
	jg	@f
27
	cmp	ebx,[ecx+0xC]
27
	cmp	ebx,[ecx+0xC]
28
	jg	@f
28
	jg	@f
29
	stc
29
	stc
30
	ret
30
	ret
31
    @@: clc
31
    @@: clc
32
	ret
32
	ret
33
endp
33
endp
34
 
34
 
35
;-----------------------------------------------------------------------------
35
;-----------------------------------------------------------------------------
36
proc check_bottom_right ;/////////////////////////////////////////////////////
36
proc check_bottom_right ;/////////////////////////////////////////////////////
37
;-----------------------------------------------------------------------------
37
;-----------------------------------------------------------------------------
38
	push	eax
38
	push	eax
39
	mov	eax,[cur_editor.TopLeft.Y]
39
	mov	eax,[cur_editor.TopLeft.Y]
40
	or	eax,eax
40
	or	eax,eax
41
	jns	@f
41
	jns	@f
42
	xor	eax,eax
42
	xor	eax,eax
43
	mov	[cur_editor.TopLeft.Y],eax
43
	mov	[cur_editor.TopLeft.Y],eax
44
    @@: add	eax,[lines.scr]
44
    @@: add	eax,[lines.scr]
45
	cmp	eax,[cur_editor.Lines.Count]
45
	cmp	eax,[cur_editor.Lines.Count]
46
	jbe	.lp1
46
	jbe	.lp1
47
	mov	eax,[cur_editor.Lines.Count]
47
	mov	eax,[cur_editor.Lines.Count]
48
	sub	eax,[lines.scr]
48
	sub	eax,[lines.scr]
49
	jns	@f
49
	jns	@f
50
	xor	eax,eax
50
	xor	eax,eax
51
    @@: mov	[cur_editor.TopLeft.Y],eax
51
    @@: mov	[cur_editor.TopLeft.Y],eax
52
  .lp1: mov	eax,[cur_editor.TopLeft.X]
52
  .lp1: mov	eax,[cur_editor.TopLeft.X]
53
	or	eax,eax
53
	or	eax,eax
54
	jns	@f
54
	jns	@f
55
	xor	eax,eax
55
	xor	eax,eax
56
	mov	[cur_editor.TopLeft.X],eax
56
	mov	[cur_editor.TopLeft.X],eax
57
    @@: add	eax,[columns.scr]
57
    @@: add	eax,[columns.scr]
58
	cmp	eax,[cur_editor.Columns.Count]
58
	cmp	eax,[cur_editor.Columns.Count]
59
	jbe	.exit
59
	jbe	.exit
60
	mov	eax,[cur_editor.Columns.Count]
60
	mov	eax,[cur_editor.Columns.Count]
61
	sub	eax,[columns.scr]
61
	sub	eax,[columns.scr]
62
	jns	@f
62
	jns	@f
63
	xor	eax,eax
63
	xor	eax,eax
64
    @@: mov	[cur_editor.TopLeft.X],eax
64
    @@: mov	[cur_editor.TopLeft.X],eax
65
  .exit:
65
  .exit:
66
	pop	eax
66
	pop	eax
67
	ret
67
	ret
68
endp
68
endp
69
 
69
 
70
;-----------------------------------------------------------------------------
70
;-----------------------------------------------------------------------------
71
proc get_real_length ;////////////////////////////////////////////////////////
71
proc get_real_length ;////////////////////////////////////////////////////////
72
;-----------------------------------------------------------------------------
72
;-----------------------------------------------------------------------------
73
	mov	eax,[esi+EDITOR_LINE_DATA.Size]
73
	mov	eax,[esi+EDITOR_LINE_DATA.Size]
74
    @@: cmp	byte[esi+eax+sizeof.EDITOR_LINE_DATA-1],' '
74
    @@: cmp	byte[esi+eax+sizeof.EDITOR_LINE_DATA-1],' '
75
	jne	@f
75
	jne	@f
76
	dec	eax
76
	dec	eax
77
	jnz	@b
77
	jnz	@b
78
    @@: ret
78
    @@: ret
79
endp
79
endp
80
 
80
 
81
;-----------------------------------------------------------------------------
81
;-----------------------------------------------------------------------------
82
proc get_line_offset ;////////////////////////////////////////////////////////
82
proc get_line_offset ;////////////////////////////////////////////////////////
83
;-----------------------------------------------------------------------------
83
;-----------------------------------------------------------------------------
84
; Input:
84
; Input:
85
;  ECX = line number
85
;  ECX = line number
86
; Output:
86
; Output:
87
;  ESI = line data offset
87
;  ESI = line data offset
88
;-----------------------------------------------------------------------------
88
;-----------------------------------------------------------------------------
89
	push	eax ecx
89
	push	eax ecx
90
	mov	esi,[cur_editor.Lines]
90
	mov	esi,[cur_editor.Lines]
91
    @@: dec	ecx
91
    @@: dec	ecx
92
	js	.exit
92
	js	.exit
93
	mov	eax,[esi+EDITOR_LINE_DATA.Size]
93
	mov	eax,[esi+EDITOR_LINE_DATA.Size]
94
	lea	esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
94
	lea	esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
95
	jmp	@b
95
	jmp	@b
96
  .exit:
96
  .exit:
97
	pop	ecx eax
97
	pop	ecx eax
98
	ret
98
	ret
99
endp
99
endp
100
 
100
 
101
;-----------------------------------------------------------------------------
101
;-----------------------------------------------------------------------------
102
proc init_sel_vars ;//////////////////////////////////////////////////////////
102
proc init_sel_vars ;//////////////////////////////////////////////////////////
103
;-----------------------------------------------------------------------------
103
;-----------------------------------------------------------------------------
104
	pushad
104
	pushad
105
	mov	[sel.selected],1
105
	mov	[sel.selected],1
106
	mov	eax,[ebp+EDITOR.SelStart.X]
106
	mov	eax,[ebp+EDITOR.SelStart.X]
107
	mov	ebx,[ebp+EDITOR.SelStart.Y]
107
	mov	ebx,[ebp+EDITOR.SelStart.Y]
108
	mov	ecx,[ebp+EDITOR.Caret.X]
108
	mov	ecx,[ebp+EDITOR.Caret.X]
109
	mov	edx,[ebp+EDITOR.Caret.Y]
109
	mov	edx,[ebp+EDITOR.Caret.Y]
110
	cmp	ebx,edx
110
	cmp	ebx,edx
111
	jl	.lp2
111
	jl	.lp2
112
	jne	@f
112
	jne	@f
113
	cmp	eax,ecx
113
	cmp	eax,ecx
114
	jl	.lp2
114
	jl	.lp2
115
	jne	.lp1
115
	jne	.lp1
116
	dec	[sel.selected]
116
	dec	[sel.selected]
117
	jmp	.lp2
117
	jmp	.lp2
118
    @@: xchg	ebx,edx
118
    @@: xchg	ebx,edx
119
  .lp1: xchg	eax,ecx
119
  .lp1: xchg	eax,ecx
120
  .lp2: mov	[sel.begin.x],eax
120
  .lp2: mov	[sel.begin.x],eax
121
	mov	[sel.begin.y],ebx
121
	mov	[sel.begin.y],ebx
122
	mov	[sel.end.x],ecx
122
	mov	[sel.end.x],ecx
123
	mov	[sel.end.y],edx
123
	mov	[sel.end.y],edx
124
	popad
124
	popad
125
	ret
125
	ret
126
endp
126
endp
127
 
127
 
128
;-----------------------------------------------------------------------------
128
;-----------------------------------------------------------------------------
129
proc get_scroll_vars ;////////////////////////////////////////////////////////
129
proc get_scroll_vars ;////////////////////////////////////////////////////////
130
;-----------------------------------------------------------------------------
130
;-----------------------------------------------------------------------------
131
; Input:
131
; Input:
132
;  EAX = maximum data size      (units)
132
;  EAX = maximum data size      (units)
133
;  EBX = visible data size      (units)
133
;  EBX = visible data size      (units)
134
;  ECX = current data position  (units)
134
;  ECX = current data position  (units)
135
;  EDX = scrolling area size    (pixels)
135
;  EDX = scrolling area size    (pixels)
136
; Output:
136
; Output:
137
;  EAX = srcoller offset        (pixels)
137
;  EAX = srcoller offset        (pixels)
138
;  EBX = scroller size          (pixels)
138
;  EBX = scroller size          (pixels)
139
;-----------------------------------------------------------------------------
139
;-----------------------------------------------------------------------------
140
	push	eax ebx edx
140
	push	eax ebx edx
141
;       sub     eax,ebx
141
;       sub     eax,ebx
142
	mov	esi,eax
142
	mov	esi,eax
143
	mov	eax,edx
143
	mov	eax,edx
144
	imul	ebx
144
	imul	ebx
145
	idiv	esi
145
	idiv	esi
146
	cmp	eax,[esp]
146
	cmp	eax,[esp]
147
	jge	.null
147
	jge	.null
148
	cmp	eax,AMINS
148
	cmp	eax,AMINS
149
	jge	@f
149
	jge	@f
150
	neg	eax
150
	neg	eax
151
	add	eax,AMINS
151
	add	eax,AMINS
152
	sub	[esp],eax
152
	sub	[esp],eax
153
	mov	eax,AMINS
153
	mov	eax,AMINS
154
    @@: mov	[esp+4],eax	; scroller size
154
    @@: mov	[esp+4],eax	; scroller size
155
	mov	eax,[esp]
155
	mov	eax,[esp]
156
	imul	ecx
156
	imul	ecx
157
	idiv	esi
157
	idiv	esi
158
	or	eax,eax
158
	or	eax,eax
159
	jns	@f
159
	jns	@f
160
	xor	eax,eax
160
	xor	eax,eax
161
   @@:	mov	[esp+8],eax	; scroller offset
161
   @@:	mov	[esp+8],eax	; scroller offset
162
	add	eax,[esp+4]
162
	add	eax,[esp+4]
163
	cmp	eax,[esp]
163
	cmp	eax,[esp]
164
	jle	@f
164
	jle	@f
165
    @@:
165
    @@:
166
	pop	edx ebx eax
166
	pop	edx ebx eax
167
	ret
167
	ret
168
  .null:
168
  .null:
169
	mov	dword[esp+4],0
169
	mov	dword[esp+4],0
170
	mov	dword[esp+8],0
170
	mov	dword[esp+8],0
171
	jmp	@b
171
	jmp	@b
172
endp
172
endp
173
 
173
 
174
;-----------------------------------------------------------------------------
174
;-----------------------------------------------------------------------------
175
proc uint2strz ;//////////////////////////////////////////////////////////////
175
proc uint2strz ;//////////////////////////////////////////////////////////////
176
;-----------------------------------------------------------------------------
176
;-----------------------------------------------------------------------------
177
	dec	ebx
177
	dec	ebx
178
	jz	@f
178
	jz	@f
179
	xor	edx,edx
179
	xor	edx,edx
180
	div	ecx
180
	div	ecx
181
	push	edx
181
	push	edx
182
	call	uint2strz
182
	call	uint2strz
183
	pop	eax
183
	pop	eax
184
    @@: cmp	al,10
184
    @@: cmp	al,10
185
	sbb	al,$69
185
	sbb	al,$69
186
	das
186
	das
187
	stosb
187
	stosb
188
	ret
188
	ret
189
endp
189
endp
190
 
190
 
191
;-----------------------------------------------------------------------------
191
;-----------------------------------------------------------------------------
192
proc uint2str ;///////////////////////////////////////////////////////////////
192
proc uint2str ;///////////////////////////////////////////////////////////////
193
;-----------------------------------------------------------------------------
193
;-----------------------------------------------------------------------------
194
	cmp	eax,ecx
194
	cmp	eax,ecx
195
	jb	@f
195
	jb	@f
196
	xor	edx,edx
196
	xor	edx,edx
197
	div	ecx
197
	div	ecx
198
	push	edx
198
	push	edx
199
	call	uint2str
199
	call	uint2str
200
	pop	eax
200
	pop	eax
201
    @@: cmp	al,10
201
    @@: cmp	al,10
202
	sbb	al,$69
202
	sbb	al,$69
203
	das
203
	das
204
	stosb
204
	stosb
205
	ret
205
	ret
206
endp
206
endp
207
 
207
 
208
;-----------------------------------------------------------------------------
208
;-----------------------------------------------------------------------------
209
proc strlen ;/////////////////////////////////////////////////////////////////
209
proc strlen ;/////////////////////////////////////////////////////////////////
210
;-----------------------------------------------------------------------------
210
;-----------------------------------------------------------------------------
211
	push	ebx
211
	push	ebx
212
	mov	ebx,eax
212
	mov	ebx,eax
213
	xor	eax,eax
213
	xor	eax,eax
214
    @@: cmp	byte[ebx+eax],0
214
    @@: cmp	byte[ebx+eax],0
215
	je	@f
215
	je	@f
216
	inc	eax
216
	inc	eax
217
	jmp	@b
217
	jmp	@b
218
    @@: pop	ebx
218
    @@: pop	ebx
219
	ret
219
	ret
220
endp
220
endp
221
 
221
 
222
;-----------------------------------------------------------------------------
222
;-----------------------------------------------------------------------------
223
proc rgb_to_gray ;////////////////////////////////////////////////////////////
223
proc rgb_to_gray ;////////////////////////////////////////////////////////////
224
;-----------------------------------------------------------------------------
224
;-----------------------------------------------------------------------------
225
	push	0 eax
225
	push	0 eax
226
	and	dword[esp],0x000000FF
226
	and	dword[esp],0x000000FF
227
	fild	dword[esp]
227
	fild	dword[esp]
228
	fmul	[float_gray_b]
228
	fmul	[float_gray_b]
229
	shr	eax,8
229
	shr	eax,8
230
	mov	[esp],eax
230
	mov	[esp],eax
231
	and	dword[esp],0x000000FF
231
	and	dword[esp],0x000000FF
232
	fild	dword[esp]
232
	fild	dword[esp]
233
	fmul	[float_gray_g]
233
	fmul	[float_gray_g]
234
	faddp
234
	faddp
235
	shr	eax,8
235
	shr	eax,8
236
	and	eax,0x000000FF
236
	and	eax,0x000000FF
237
	mov	[esp],eax
237
	mov	[esp],eax
238
	fild	dword[esp]
238
	fild	dword[esp]
239
	fmul	[float_gray_r]
239
	fmul	[float_gray_r]
240
	faddp
240
	faddp
241
	frndint
241
	frndint
242
	fist	dword[esp]
242
	fist	dword[esp]
243
	fist	dword[esp+1]
243
	fist	dword[esp+1]
244
	fistp	dword[esp+2]
244
	fistp	dword[esp+2]
245
	pop	eax
245
	pop	eax
246
	add	esp,4
246
	add	esp,4
247
	ret
247
	ret
248
endp
248
endp
249
 
249
 
250
;float_gray_r dd 0.30f
250
;float_gray_r dd 0.30f
251
;float_gray_g dd 0.59f
251
;float_gray_g dd 0.59f
252
;float_gray_b dd 0.11f
252
;float_gray_b dd 0.11f
253
 
253
 
254
;-----------------------------------------------------------------------------
254
;-----------------------------------------------------------------------------
255
proc get_active_menu_item ;///////////////////////////////////////////////////
255
proc get_active_menu_item ;///////////////////////////////////////////////////
256
;-----------------------------------------------------------------------------
256
;-----------------------------------------------------------------------------
257
	pushad
257
	pushad
258
	mov	[mi_cur],0
258
	mov	[mi_cur],0
259
	mcall	37,1
259
	mcall	37,1
260
	movsx	ebx,ax
260
	movsx	ebx,ax
261
	sar	eax,16
261
	sar	eax,16
262
	mov	ecx,__rc
262
	mov	ecx,__rc
263
	pushd	2 0 (main_menu.width+7) (ATOPH-2)
263
	pushd	2 0 (main_menu.width+7) (ATOPH-2)
264
	popd	[__rc+0xC] [__rc+0x8] [__rc+0x4] [__rc+0x0]
264
	popd	[__rc+0xC] [__rc+0x8] [__rc+0x4] [__rc+0x0]
265
;       add     [__rc+0xC],ATOPH-2
265
;       add     [__rc+0xC],ATOPH-2
266
	call	pt_in_rect
266
	call	pt_in_rect
267
	jnc	.outside_menu
267
	jnc	.outside_menu
268
	m2m	dword[ecx+0x8],dword[ecx+0x0]
268
	m2m	dword[ecx+0x8],dword[ecx+0x0]
269
	mov	edx,main_menu
269
	mov	edx,main_menu
270
    @@: inc	[mi_cur]
270
    @@: inc	[mi_cur]
271
	movzx	esi,word[edx+0]
271
	movzx	esi,word[edx+0]
272
	add	[ecx+0x8],esi
272
	add	[ecx+0x8],esi
273
	call	pt_in_rect
273
	call	pt_in_rect
274
	jc	.exit
274
	jc	.exit
275
	m2m	dword[ecx+0x0],dword[ecx+0x8]
275
	m2m	dword[ecx+0x0],dword[ecx+0x8]
276
	add	edx,8+1
276
	add	edx,8+1
277
	movzx	esi,byte[edx-1]
277
	movzx	esi,byte[edx-1]
278
	add	edx,esi
278
	add	edx,esi
279
	cmp	byte[edx+8],0
279
	cmp	byte[edx+8],0
280
	jne	@b
280
	jne	@b
281
	mov	[mi_cur],0
281
	mov	[mi_cur],0
282
  .exit:
282
  .exit:
283
	popad
283
	popad
284
	ret
284
	ret
285
  .outside_menu:
285
  .outside_menu:
286
	or	[mi_cur],-1
286
	or	[mi_cur],-1
287
    @@: popad
287
    @@: popad
288
	ret
288
	ret
289
endp
289
endp
290
 
290
 
291
;-----------------------------------------------------------------------------
291
;-----------------------------------------------------------------------------
292
proc get_active_popup_item ;//////////////////////////////////////////////////
292
proc get_active_popup_item ;//////////////////////////////////////////////////
293
;-----------------------------------------------------------------------------
293
;-----------------------------------------------------------------------------
294
	pushad
294
	pushad
295
	mov	[pi_cur],0
295
	mov	[pi_cur],0
296
	mcall	37,1
296
	mcall	37,1
297
	movsx	ebx,ax
297
	movsx	ebx,ax
298
	sar	eax,16
298
	sar	eax,16
299
	mov	ecx,__rc
299
	mov	ecx,__rc
300
	mov	dword[ecx+0x0],0
300
	mov	dword[ecx+0x0],0
301
	mov	dword[ecx+0x4],0
301
	mov	dword[ecx+0x4],0
302
	movzx	edx,[ebp+POPUP.width]
302
	movzx	edx,[ebp+POPUP.width]
303
	mov	dword[ecx+0x8],edx
303
	mov	dword[ecx+0x8],edx
304
	movzx	edx,[ebp+POPUP.height]
304
	movzx	edx,[ebp+POPUP.height]
305
	mov	dword[ecx+0xC],edx
305
	mov	dword[ecx+0xC],edx
306
	call	pt_in_rect
306
	call	pt_in_rect
307
	jnc	.outside_window
307
	jnc	.outside_window
308
	inc	dword[ecx+0x0]
308
	inc	dword[ecx+0x0]
309
	mov	dword[ecx+0x4],2
309
	mov	dword[ecx+0x4],2
310
	dec	dword[ecx+0x8]
310
	dec	dword[ecx+0x8]
311
	mov	dword[ecx+0xC],2+POP_IHEIGHT-1
311
	mov	dword[ecx+0xC],2+POP_IHEIGHT-1
312
	mov	edx,[ebp+POPUP.data]
312
	mov	edx,[ebp+POPUP.data]
313
    @@: inc	[pi_cur]
313
    @@: inc	[pi_cur]
314
	inc	edx
314
	inc	edx
315
	movzx	esi,byte[edx-1]
315
	movzx	esi,byte[edx-1]
316
	cmp	byte[edx],'-'
316
	cmp	byte[edx],'-'
317
	jne	.lp1
317
	jne	.lp1
318
	pushd	[ecx+0xC]
318
	pushd	[ecx+0xC]
319
	sub	dword[ecx+0xC],POP_IHEIGHT-POP_SHEIGHT
319
	sub	dword[ecx+0xC],POP_IHEIGHT-POP_SHEIGHT
320
	call	pt_in_rect
320
	call	pt_in_rect
321
	popd	[ecx+0xC]
321
	popd	[ecx+0xC]
322
	jc	.separator
322
	jc	.separator
323
	add	dword[ecx+0x4],POP_SHEIGHT
323
	add	dword[ecx+0x4],POP_SHEIGHT
324
	add	dword[ecx+0xC],POP_SHEIGHT
324
	add	dword[ecx+0xC],POP_SHEIGHT
325
	jmp	.lp3
325
	jmp	.lp3
326
  .lp1: call	pt_in_rect
326
  .lp1: call	pt_in_rect
327
	jnc	.lp2
327
	jnc	.lp2
328
	mov	eax,[pi_cur]
328
	mov	eax,[pi_cur]
329
	test	byte[ebp+eax-1],1
329
	test	byte[ebp+eax-1],1
330
	jnz	.exit
330
	jnz	.exit
331
	jmp	.separator
331
	jmp	.separator
332
  .lp2: add	dword[ecx+0x4],POP_IHEIGHT
332
  .lp2: add	dword[ecx+0x4],POP_IHEIGHT
333
	add	dword[ecx+0xC],POP_IHEIGHT
333
	add	dword[ecx+0xC],POP_IHEIGHT
334
	add	edx,esi
334
	add	edx,esi
335
	inc	edx
335
	inc	edx
336
	movzx	esi,byte[edx-1]
336
	movzx	esi,byte[edx-1]
337
  .lp3: add	edx,esi
337
  .lp3: add	edx,esi
338
	cmp	byte[edx],0
338
	cmp	byte[edx],0
339
	jne	@b
339
	jne	@b
340
  .separator:
340
  .separator:
341
	mov	[pi_cur],0
341
	mov	[pi_cur],0
342
  .exit:
342
  .exit:
343
	popad
343
	popad
344
	ret
344
	ret
345
  .outside_window:
345
  .outside_window:
346
	or	[pi_cur],-1
346
	or	[pi_cur],-1
347
	jmp	.exit
347
	jmp	.exit
348
endp
348
endp
349
 
349
 
350
;-----------------------------------------------------------------------------
350
;-----------------------------------------------------------------------------
351
proc line_add_spaces ;////////////////////////////////////////////////////////
351
proc line_add_spaces ;////////////////////////////////////////////////////////
352
;-----------------------------------------------------------------------------
352
;-----------------------------------------------------------------------------
353
; Input:
353
; Input:
354
;  ESI = line offset
354
;  ESI = line offset
355
;  ECX = needed line length
355
;  ECX = needed line length
356
; Output:
356
; Output:
357
;  EAX = delta
357
;  EAX = delta
358
;-----------------------------------------------------------------------------
358
;-----------------------------------------------------------------------------
359
	xor	eax,eax
359
	xor	eax,eax
360
	pushad
360
	pushad
361
	mov	edx,[esi+EDITOR_LINE_DATA.Size]
361
	mov	edx,[esi+EDITOR_LINE_DATA.Size]
362
	cmp	ecx,edx
362
	cmp	ecx,edx
363
	jbe	.exit
363
	jbe	.exit
364
	sub	ecx,edx
364
	sub	ecx,edx
365
	lea	eax,[ecx+sizeof.EDITOR_LINE_DATA]
365
	lea	eax,[ecx+sizeof.EDITOR_LINE_DATA]
366
	call	editor_realloc_lines
366
	call	editor_realloc_lines
367
	mov	[esp+4*7],eax
367
	mov	[esp+4*7],eax
368
	add	esi,eax
368
	add	esi,eax
369
	push	ecx
369
	push	ecx
370
	mov	edi,[cur_editor.Lines]
370
	mov	edi,[cur_editor.Lines]
371
	add	edi,[cur_editor.Lines.Size] ; !!! CHECK THIS!!! add edi,[edi-4]
371
	add	edi,[cur_editor.Lines.Size] ; !!! CHECK THIS!!! add edi,[edi-4]
372
	dec	edi
372
	dec	edi
373
	mov	eax,esi
373
	mov	eax,esi
374
	mov	esi,edi
374
	mov	esi,edi
375
	sub	esi,ecx
375
	sub	esi,ecx
376
	lea	ecx,[eax+sizeof.EDITOR_LINE_DATA]
376
	lea	ecx,[eax+sizeof.EDITOR_LINE_DATA]
377
	add	ecx,edx
377
	add	ecx,edx
378
	push	ecx
378
	push	ecx
379
	neg	ecx
379
	neg	ecx
380
	lea	ecx,[esi+ecx+1]
380
	lea	ecx,[esi+ecx+1]
381
	std
381
	std
382
	rep	movsb
382
	rep	movsb
383
	pop	edi ecx
383
	pop	edi ecx
384
	add	[eax+EDITOR_LINE_DATA.Size],ecx
384
	add	[eax+EDITOR_LINE_DATA.Size],ecx
385
	mov	al,' '
385
	mov	al,' '
386
	cld
386
	cld
387
	rep	stosb
387
	rep	stosb
388
  .exit:
388
  .exit:
389
	popad
389
	popad
390
	ret
390
	ret
391
endp
391
endp
392
 
392
 
393
;-----------------------------------------------------------------------------
393
;-----------------------------------------------------------------------------
394
proc delete_selection ;///////////////////////////////////////////////////////
394
proc delete_selection ;///////////////////////////////////////////////////////
395
;-----------------------------------------------------------------------------
395
;-----------------------------------------------------------------------------
396
;       call    init_sel_vars
396
;       call    init_sel_vars
397
 
397
 
398
	cmp	[sel.selected],0
398
	cmp	[sel.selected],0
399
	je	.exit.2
399
	je	.exit.2
400
 
400
 
401
	pushad
401
	pushad
402
	mov	ecx,[sel.begin.y]
402
	mov	ecx,[sel.begin.y]
403
	cmp	ecx,[sel.end.y]
403
	cmp	ecx,[sel.end.y]
404
	je	.single_line
404
	je	.single_line
405
	call	get_line_offset
405
	call	get_line_offset
406
	and	[esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
406
	and	[esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
407
	or	[esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
407
	or	[esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
408
	mov	ecx,[sel.begin.x]
408
	mov	ecx,[sel.begin.x]
409
	call	line_add_spaces
409
	call	line_add_spaces
410
	add	esi,eax
410
	add	esi,eax
411
	lea	edi,[esi+sizeof.EDITOR_LINE_DATA]
411
	lea	edi,[esi+sizeof.EDITOR_LINE_DATA]
412
	mov	ecx,[sel.end.y]
412
	mov	ecx,[sel.end.y]
413
	call	get_line_offset
413
	call	get_line_offset
414
	call	get_real_length
414
	call	get_real_length
415
	cmp	eax,[sel.end.x]
415
	cmp	eax,[sel.end.x]
416
	jbe	@f
416
	jbe	@f
417
	mov	eax,[sel.end.x]
417
	mov	eax,[sel.end.x]
418
    @@: mov	ecx,[esi+EDITOR_LINE_DATA.Size]
418
    @@: mov	ecx,[esi+EDITOR_LINE_DATA.Size]
419
	sub	ecx,eax
419
	sub	ecx,eax
420
	mov	ebx,[sel.begin.x]
420
	mov	ebx,[sel.begin.x]
421
	add	ebx,ecx
421
	add	ebx,ecx
422
	mov	[edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size],ebx
422
	mov	[edi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size],ebx
423
	add	edi,[sel.begin.x]
423
	add	edi,[sel.begin.x]
424
	lea	esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
424
	lea	esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
425
	mov	ecx,[cur_editor.Lines]
425
	mov	ecx,[cur_editor.Lines]
426
	add	ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
426
	add	ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
427
	sub	ecx,esi
427
	sub	ecx,esi
428
	cld
428
	cld
429
	rep	movsb
429
	rep	movsb
430
	mov	eax,[sel.end.y]
430
	mov	eax,[sel.end.y]
431
	sub	eax,[sel.begin.y]
431
	sub	eax,[sel.begin.y]
432
	sub	[cur_editor.Lines.Count],eax
432
	sub	[cur_editor.Lines.Count],eax
433
	jmp	.exit
433
	jmp	.exit
434
 
434
 
435
  .single_line:
435
  .single_line:
436
	call	get_line_offset
436
	call	get_line_offset
437
	and	[esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
437
	and	[esi+EDITOR_LINE_DATA.Flags],not EDITOR_LINE_FLAG_SAVED
438
	or	[esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
438
	or	[esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
439
	call	get_real_length
439
	call	get_real_length
440
	cmp	eax,[sel.begin.x]
440
	cmp	eax,[sel.begin.x]
441
	jbe	.exit
441
	jbe	.exit
442
	mov	ecx,[sel.end.x]
442
	mov	ecx,[sel.end.x]
443
	cmp	ecx,eax
443
	cmp	ecx,eax
444
	jbe	@f
444
	jbe	@f
445
	mov	ecx,eax
445
	mov	ecx,eax
446
    @@: sub	ecx,[sel.begin.x]
446
    @@: sub	ecx,[sel.begin.x]
447
	sub	[esi+EDITOR_LINE_DATA.Size],ecx
447
	sub	[esi+EDITOR_LINE_DATA.Size],ecx
448
	lea	edi,[esi+sizeof.EDITOR_LINE_DATA]
448
	lea	edi,[esi+sizeof.EDITOR_LINE_DATA]
449
	add	edi,[sel.begin.x]
449
	add	edi,[sel.begin.x]
450
	lea	esi,[edi+ecx]
450
	lea	esi,[edi+ecx]
451
	mov	ecx,[cur_editor.Lines]
451
	mov	ecx,[cur_editor.Lines]
452
	add	ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
452
	add	ecx,[cur_editor.Lines.Size] ;*** add ecx,[ecx-4]
453
	sub	ecx,esi
453
	sub	ecx,esi
454
	cld
454
	cld
455
	rep	movsb
455
	rep	movsb
456
 
456
 
457
  .exit:
457
  .exit:
458
	mov	eax,[sel.begin.x]
458
	mov	eax,[sel.begin.x]
459
	mov	[cur_editor.Caret.X],eax
459
	mov	[cur_editor.Caret.X],eax
460
	mov	[cur_editor.SelStart.X],eax
460
	mov	[cur_editor.SelStart.X],eax
461
	mov	eax,[sel.begin.y]
461
	mov	eax,[sel.begin.y]
462
	mov	[cur_editor.Caret.Y],eax
462
	mov	[cur_editor.Caret.Y],eax
463
	mov	[cur_editor.SelStart.Y],eax
463
	mov	[cur_editor.SelStart.Y],eax
464
 
464
 
465
	mov	ecx,[cur_editor.Lines.Count]
465
	mov	ecx,[cur_editor.Lines.Count]
466
	call	get_line_offset
466
	call	get_line_offset
467
	mov	eax,[esi+EDITOR_LINE_DATA.Size]
467
	mov	eax,[esi+EDITOR_LINE_DATA.Size]
468
	lea	esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
468
	lea	esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
469
	mov	eax,[cur_editor.Lines]
469
	mov	eax,[cur_editor.Lines]
470
	add	eax,[cur_editor.Lines.Size] ;*** add eax,[eax-4]
470
	add	eax,[cur_editor.Lines.Size] ;*** add eax,[eax-4]
471
	sub	esi,eax
471
	sub	esi,eax
472
	lea	eax,[esi+4096]
472
	lea	eax,[esi+4096]
473
	call	editor_realloc_lines
473
	call	editor_realloc_lines
474
 
474
 
475
	popad
475
	popad
476
	mov	[cur_editor.Modified],1
476
	mov	[cur_editor.Modified],1
477
	clc
477
	clc
478
	ret
478
	ret
479
 
479
 
480
  .exit.2:
480
  .exit.2:
481
	stc
481
	stc
482
	ret
482
	ret
483
endp
483
endp
484
 
484
 
485
;-----------------------------------------------------------------------------
485
;-----------------------------------------------------------------------------
486
proc get_selection_size ;/////////////////////////////////////////////////////
486
proc get_selection_size ;/////////////////////////////////////////////////////
487
;-----------------------------------------------------------------------------
487
;-----------------------------------------------------------------------------
488
	push	ecx esi
488
	push	ecx esi
489
	mov	ecx,[sel.end.y]
489
	mov	ecx,[sel.end.y]
490
	inc	ecx
490
	inc	ecx
491
	call	get_line_offset
491
	call	get_line_offset
492
	mov	eax,esi
492
	mov	eax,esi
493
	mov	ecx,[sel.begin.y]
493
	mov	ecx,[sel.begin.y]
494
	call	get_line_offset
494
	call	get_line_offset
495
	sub	eax,esi
495
	sub	eax,esi
496
	pop	esi ecx
496
	pop	esi ecx
497
	ret
497
	ret
498
endp
498
endp
499
 
499
 
500
;-----------------------------------------------------------------------------
500
;-----------------------------------------------------------------------------
501
proc get_lines_in_file ;//////////////////////////////////////////////////////
501
proc get_lines_in_file ;//////////////////////////////////////////////////////
502
;-----------------------------------------------------------------------------
502
;-----------------------------------------------------------------------------
503
; Input:
503
; Input:
504
;  ESI = data pointer
504
;  ESI = data pointer
505
;  ECX = data length
505
;  ECX = data length
506
; Output:
506
; Output:
507
;  EAX = lines number
507
;  EAX = lines number
508
;  EBX = extra length after tabs expansion
508
;  EBX = extra length after tabs expansion
509
;-----------------------------------------------------------------------------
509
;-----------------------------------------------------------------------------
510
	push	ecx edx esi 0
510
	push	ecx edx esi 0
511
	or	ebx,-1
511
	or	ebx,-1
512
	xor	edx,edx
512
	xor	edx,edx
513
  .lp0: inc	ebx
513
  .lp0: inc	ebx
514
  .lp1: dec	ecx
514
  .lp1: dec	ecx
515
	jle	.lp2
515
	jle	.lp2
516
	lodsb
516
	lodsb
517
	cmp	al,0
517
	cmp	al,0
518
	je	.lp2
518
	je	.lp2
519
	cmp	al,9
519
	cmp	al,9
520
	je	.TB
520
	je	.TB
521
	cmp	al,10
521
	cmp	al,10
522
	je	.LF
522
	je	.LF
523
	cmp	al,13
523
	cmp	al,13
524
	je	.CR
524
	je	.CR
525
	inc	edx
525
	inc	edx
526
	jmp	.lp1
526
	jmp	.lp1
527
  .lp2: lea	eax,[ebx+1]
527
  .lp2: lea	eax,[ebx+1]
528
	pop	ebx esi edx ecx
528
	pop	ebx esi edx ecx
529
	ret
529
	ret
530
 
530
 
531
   .CR: cmp	byte[esi],10
531
   .CR: cmp	byte[esi],10
532
	jne	.LF
532
	jne	.LF
533
	lodsb
533
	lodsb
534
   .LF: xor	edx,edx
534
   .LF: xor	edx,edx
535
	jmp	.lp0
535
	jmp	.lp0
536
   .TB: and	edx,00000111b
536
   .TB: and	edx,00000111b
537
	add	dword[esp],ATABW
537
	add	dword[esp],ATABW
538
	sub	[esp],edx
538
	sub	[esp],edx
539
	xor	edx,edx
539
	xor	edx,edx
540
	jmp	.lp1
540
	jmp	.lp1
541
endp
541
endp
542
 
542
 
543
;-----------------------------------------------------------------------------
543
;-----------------------------------------------------------------------------
544
proc update_caption ;/////////////////////////////////////////////////////////
544
proc update_caption ;/////////////////////////////////////////////////////////
545
;-----------------------------------------------------------------------------
545
;-----------------------------------------------------------------------------
546
	lea	esi,[cur_editor.FilePath]
546
	lea	esi,[cur_editor.FilePath]
547
	mov	edi,s_title
547
	mov	edi,s_title
548
 
548
 
549
	xor	ecx,ecx
549
	xor	ecx,ecx
550
    @@: lodsb
550
    @@: lodsb
551
	cmp	al,0
551
	cmp	al,0
552
	je	@f
552
	je	@f
553
	stosb
553
	stosb
554
	inc	ecx
554
	inc	ecx
555
	jmp	@b
555
	jmp	@b
556
    @@:
556
    @@:
557
	push	ecx
557
	push	ecx
558
	mov	dword[edi],' - '
558
	mov	dword[edi],' - '
559
	add	edi,3
559
	add	edi,3
560
	mov	esi,htext
560
	mov	esi,htext
561
	mov	ecx,htext.size
561
	mov	ecx,htext.size
562
	cld
562
	cld
563
	rep	movsb
563
	rep	movsb
564
 
564
 
565
	mov	al,0
565
	mov	al,0
566
	stosb
566
	stosb
567
 
567
 
568
	mcall	71,1,s_title
568
	mcall	71,1,s_title
569
 
569
 
570
	cmp	[do_not_draw],0
570
	cmp	[do_not_draw],0
571
	jne	@f
571
	jne	@f
572
	lea	esi,[cur_editor.FilePath]
572
	lea	esi,[cur_editor.FilePath]
573
	mov	edi,tb_opensave.text
573
	mov	edi,tb_opensave.text
574
	mov	ecx,[esp]
574
	mov	ecx,[esp]
575
	cld
575
	cld
576
	rep	movsb
576
	rep	movsb
577
	pop	ecx
577
	pop	ecx
578
	mov	[tb_opensave.length],cl
578
	mov	[tb_opensave.length],cl
579
	clc
579
	clc
580
	ret
580
	ret
581
    @@:
581
    @@:
582
	add	esp,4
582
	add	esp,4
583
	clc
583
	clc
584
	ret
584
	ret
585
endp
585
endp
586
 
-
 
587
;-----------------------------------------------------------------------------
-
 
588
proc mem.Alloc,size ;/////////////////////////////////////////////////////////
-
 
589
;-----------------------------------------------------------------------------
-
 
590
	push	ebx ecx
-
 
591
	mov	ecx,[size]
-
 
592
	;*** add ecx,4
-
 
593
	mcall	68,12
-
 
594
	;*** add ecx,-4
-
 
595
	;*** mov [eax],ecx
-
 
596
	;*** add eax,4
-
 
597
	pop	ecx ebx
-
 
598
	ret
-
 
599
endp
-
 
600
 
-
 
601
;-----------------------------------------------------------------------------
-
 
602
proc mem.ReAlloc,mptr,size ;//////////////////////////////////////////////////
-
 
603
;-----------------------------------------------------------------------------
-
 
604
	push	ebx ecx edx
-
 
605
	mov	ecx,[size]
-
 
606
	or	ecx,ecx
-
 
607
	jz	@f
-
 
608
	;*** add ecx,4
-
 
609
    @@: mov	edx,[mptr]
-
 
610
	or	edx,edx
-
 
611
	jz	@f
-
 
612
	;*** add edx,-4
-
 
613
    @@: mcall	68,20
-
 
614
	or	eax,eax
-
 
615
	jz	@f
-
 
616
	;*** add ecx,-4
-
 
617
	;*** mov [eax],ecx
-
 
618
	;*** add eax,4
-
 
619
    @@: pop	edx ecx ebx
-
 
620
	ret
-
 
621
endp
-
 
622
 
-
 
623
;-----------------------------------------------------------------------------
-
 
624
proc mem.Free,mptr ;//////////////////////////////////////////////////////////
-
 
625
;-----------------------------------------------------------------------------
-
 
626
	push	ebx ecx
-
 
627
	mov	ecx,[mptr]
-
 
628
	or	ecx,ecx
-
 
629
	jz	@f
-
 
630
	;*** add ecx,-4
-
 
631
    @@: mcall	68,13
-
 
632
	pop	ecx ebx
-
 
633
	ret
-
 
634
endp
-