Subversion Repositories Kolibri OS

Rev

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

Rev 131 Rev 205
1
; BGIFONT.INC v1.0 beta
1
; BGIFONT.INC v1.0 beta
2
;
2
;
3
; Written in pure assembler by Ivushkin Andrey aka Willow
3
; Written in pure assembler by Ivushkin Andrey aka Willow
4
;
4
;
5
; Created: December 16, 2004
5
; Created: December 16, 2004
6
;
6
;
7
; Last changed: February 2, 2005
7
; Last changed: August 27, 2006
8
;
8
;
9
; Compile with FASM
9
; Compile with FASM
10
 
10
 
11
; BGI constants
11
; BGI constants
12
BGI_NODRAW   equ 0x10000
12
BGI_NODRAW   equ 0x10000
13
BGI_ITALIC   equ 0x20000
13
BGI_ITALIC   equ 0x20000
14
BGI_BOLD     equ 0x40000
14
BGI_BOLD     equ 0x40000
15
BGI_HALEFT   equ 0x0
15
BGI_HALEFT   equ 0x0
16
BGI_HARIGHT  equ 0x1000
16
BGI_HARIGHT  equ 0x1000
17
BGI_HACENTER equ 0x2000
17
BGI_HACENTER equ 0x2000
18
BGI_VABOTTOM equ 0x0
18
BGI_VABOTTOM equ 0x0
19
BGI_VATOP    equ 0x4000
19
BGI_VATOP    equ 0x4000
20
BGI_VACENTER equ 0x8000
20
BGI_VACENTER equ 0x8000
21
 
21
 
22
BGI_FREE     equ 0x80000000
22
BGI_FREE     equ 0x80000000
23
BGI_HAMASK   equ 0x3000
23
BGI_HAMASK   equ 0x3000
24
BGI_VAMASK   equ 0xc000
24
BGI_VAMASK   equ 0xc000
25
 
25
 
26
; Freetext structure
26
; Freetext structure
27
struc BGIfree FontName,XY,Angle,ScaleX,ScaleY,StrPtr,StrLen,Color,Align
27
struc BGIfree FontName,XY,Angle,ScaleX,ScaleY,StrPtr,StrLen,Color,Align
28
{
28
{
29
    dd FontName ;0
29
    dd FontName ;0
30
    dd XY	    ;4
30
    dd XY	    ;4
31
    dd Angle	;8
31
    dd Angle	;8
32
    dd ScaleX	;12
32
    dd ScaleX	;12
33
    dd ScaleY	;16
33
    dd ScaleY	;16
34
    dd StrPtr	;20
34
    dd StrPtr	;20
35
    dd StrLen	;24
35
    dd StrLen	;24
36
    dd Color	;28
36
    dd Color	;28
37
    dd Align	;32
37
    dd Align	;32
38
}
38
}
39
 
39
 
40
; font options structure
40
; font options structure
41
struc BGIrec FontName,CharsCount,FirstChar,UpperMargin,LowerMargin,\
41
struc BGIrec FontName,CharsCount,FirstChar,UpperMargin,LowerMargin,\
42
    Widths,FirstData,EOF,font_data
42
    Widths,FirstData,EOF,font_data
43
{
43
{
44
 .FontName     dd ?  ; 0
44
 .FontName     dd ?  ; 0
45
 .CharsCount   db ?  ; 4
45
 .CharsCount   db ?  ; 4
46
 .FirstChar    db ?  ; 5
46
 .FirstChar    db ?  ; 5
47
 .UpperMargin  db ?  ; 6
47
 .UpperMargin  db ?  ; 6
48
 .LowerMargin  db ?  ; 7
48
 .LowerMargin  db ?  ; 7
49
 .Widths       dd ?  ; 8
49
 .Widths       dd ?  ; 8
50
 .FirstData    dd ?  ; 12
50
 .FirstData    dd ?  ; 12
51
 .EOF	       dd ?    ; 16
51
 .EOF	       dd ?    ; 16
52
 .font_data    dd ?  ; 20 follows (Offsets)
52
 .font_data    dd ?  ; 20 follows (Offsets)
53
}
53
}
54
 
54
 
55
macro BGIfont_GetID
55
macro BGIfont_GetID
56
{
56
{
57
    call _BGIfont_GetID
57
    call _BGIfont_GetID
58
}
58
}
59
 
59
 
60
macro BGIfont_Prepare
60
macro BGIfont_Prepare
61
{
61
{
62
    call _BGIfont_Prepare
62
    call _BGIfont_Prepare
63
}
63
}
64
 
64
 
65
macro BGIfont_Freetext
65
macro BGIfont_Freetext
66
{
66
{
67
    call _BGIfont_Freetext
67
    call _BGIfont_Freetext
68
}
68
}
69
 
69
 
70
macro BGIfont_Outtext
70
macro BGIfont_Outtext
71
{
71
{
72
    call _BGIfont_Outtext
72
    call _BGIfont_Outtext
73
}
73
}
74
 
74
 
75
macro _FI name,_size
75
macro _FI name,_size
76
{
76
{
77
    db name
77
    db name
78
if BGI_LEVEL eq KERNEL
78
if BGI_LEVEL eq KERNEL
79
    dw _size
79
    dw _size
80
end if
80
end if
81
}
81
}
82
 
82
 
83
BGIfont_names:
83
BGIfont_names:
84
_FI 'LCOM',11485   ;7
84
_FI 'LCOM',11485   ;7
85
_FI 'EURO',8117    ;5
85
_FI 'EURO',8117    ;5
86
_FI 'GOTH',13816   ;6
86
_FI 'GOTH',13816   ;6
87
_FI 'LITT',3596    ;8
87
_FI 'LITT',3596    ;8
88
_FI 'TRIP',11932   ;14
88
_FI 'TRIP',11932   ;14
89
_FI 'SCRI',8490    ;11
89
_FI 'SCRI',8490    ;11
90
_FI 'SMAL',4162    ;13
90
_FI 'SMAL',4162    ;13
91
_FI 'TSCR',12134   ;15
91
_FI 'TSCR',12134   ;15
92
_FI 'SANS',8453    ;10
92
_FI 'SANS',8453    ;10
93
_FI 'SIMP',9522    ;12
93
_FI 'SIMP',9522    ;12
94
BGIfont_names_end:
94
BGIfont_names_end:
95
 
95
 
96
macro BGIfont_Init
96
macro BGIfont_Init
97
{
97
{
98
; in:  ecx - number of fonts to load;
98
; in:  ecx - number of fonts to load;
99
;      esi-> _FI structure
99
;      esi-> _FI structure
100
;      edi-> where to load
100
;      edi-> where to load
101
    push edi
101
    push edi
102
if  BGI_LEVEL eq KERNEL
102
if  BGI_LEVEL eq KERNEL
103
    mov  edi,0x40000
103
    mov  edi,0x40000
104
end if
104
end if
105
  .nfont:
105
  .nfont:
106
    mov  edx,[esi]
106
    mov  edx,[esi]
107
if  BGI_LEVEL eq KERNEL
107
if  BGI_LEVEL eq KERNEL
108
    movzx ebx,word[esi+4]
108
    movzx ebx,word[esi+4]
109
    mov  [BGIfont_Prepare.okflag],'N'
109
    mov  [BGIfont_Prepare.okflag],'N'
110
end if
110
end if
111
    call _BGIfont_Prepare
111
    call _BGIfont_Prepare
112
if ~ BGI_LEVEL eq KERNEL
112
if ~ BGI_LEVEL eq KERNEL
113
    add  esi,4
113
    add  esi,4
114
else
114
else
115
    push esi
115
    push esi
116
    test eax,eax
116
    test eax,eax
117
    jz	 .fail
117
    jz	 .fail
118
    mov  [BGIfont_Prepare.okflag],'*'
118
    mov  [BGIfont_Prepare.okflag],'*'
119
  .fail:
119
  .fail:
120
    mov  esi,BGIfont_Prepare.font
120
    mov  esi,BGIfont_Prepare.font
121
    call boot_log
121
    call boot_log
122
    pop  esi
122
    pop  esi
123
    add  esi,6
123
    add  esi,6
124
end if
124
end if
125
    loop .nfont
125
    loop .nfont
126
    dph2 _BGI_BOLD,300,550
126
    dph2 _BGI_BOLD,300,550
127
;    movzx edi,byte[0x40000]
127
;    movzx edi,byte[0x40000]
128
    pop  edi
128
    pop  edi
129
}
129
}
130
 
130
 
131
BGIfont_get2head:
131
BGIfont_get2head:
132
    shr  ecx,28 ; font #
132
    shr  ecx,28 ; font #
133
    sub  ecx,4
133
    sub  ecx,4
134
    jb	 .exit2	; invalid #
134
    jb	 .exit2	; invalid #
135
    mov  edi,[BGIfont_Ptr]
135
    mov  edi,[BGIfont_Ptr]
136
    inc  edi
136
    inc  edi
137
    cmp  cl,[edi-1]
137
    cmp  cl,[edi-1]
138
    jae  .exit2 ; # too large
138
    jae  .exit2 ; # too large
139
    jecxz .ex
139
    jecxz .ex
140
  .fnext:
140
  .fnext:
141
    mov  edi,[edi+16]
141
    mov  edi,[edi+16]
142
    loop .fnext
142
    loop .fnext
143
    jmp  .ex
143
    jmp  .ex
144
  .exit2:
144
  .exit2:
145
    xor  edi,edi
145
    xor  edi,edi
146
  .ex:
146
  .ex:
147
    ret
147
    ret
148
 
148
 
149
BGIfont_GetName:
149
BGIfont_GetName:
150
; in: ecx-fontID;
150
; in: ecx-fontID;
151
; out: edx-font name.
151
; out: edx-font name.
152
    call BGIfont_get2head
152
    call BGIfont_get2head
153
    xor  edx,edx
153
    xor  edx,edx
154
    test edi,edi
154
    test edi,edi
155
    jz   .ex
155
    jz   .ex
156
    mov  edx,[edi]
156
    mov  edx,[edi]
157
  .ex:
157
  .ex:
158
    ret
158
    ret
159
 
159
 
160
macro dps2 _str
160
macro dps2 _str
161
{
161
{
162
if ~ BGI_LEVEL eq KERNEL
162
if ~ BGI_LEVEL eq KERNEL
163
  if LOAD_MSG eq 1
163
  if LOAD_MSG eq 1
164
    dps _str
164
    dps _str
165
  end if
165
  end if
166
else
166
else
167
    pusha
167
    pusha
168
    mov  esi,BGIfont_Prepare.okflag
168
    mov  esi,BGIfont_Prepare.okflag
169
    mov  byte[esi], _str
169
    mov  byte[esi], _str
170
    call boot_log
170
    call boot_log
171
    popa
171
    popa
172
end if
172
end if
173
}
173
}
174
 
174
 
175
macro dph2 num,x,y
175
macro dph2 num,x,y
176
{
176
{
177
if  BGI_LEVEL eq KERNEL
177
if  BGI_LEVEL eq KERNEL
178
    pusha
178
    pusha
179
    mov  eax,0x00080100
179
    mov  eax,0x00080100
180
    mov  ebx,num
180
    mov  ebx,num
181
    mov  ecx,x shl 16+y
181
    mov  ecx,x shl 16+y
182
    mov  edx,0xFF0000
182
    mov  edx,0xFF0000
183
    call display_number
183
    call display_number
184
    popa
184
    popa
185
end if
185
end if
186
}
186
}
187
 
187
 
188
_BGIfont_GetID:
188
_BGIfont_GetID:
189
; in:  edx-font name;
189
; in:  edx-font name;
190
; out: eax-fontID, edi->BGIrec
190
; out: eax-fontID, edi->BGIrec
191
    push ecx edi
191
    push ecx edi
192
    mov  edi,[BGIfont_Ptr]
192
    mov  edi,[BGIfont_Ptr]
193
    movzx ecx,byte[edi] ; ecx-font count
193
    movzx ecx,byte[edi] ; ecx-font count
194
    mov  eax,ecx
194
    mov  eax,ecx
195
    inc  edi ; edi->FontName
195
    inc  edi ; edi->FontName
196
    jecxz .ex
196
    jecxz .ex
197
  .fnext:
197
  .fnext:
198
    cmp  edx,[edi]
198
    cmp  edx,[edi]
199
    jne  .floop
199
    jne  .floop
200
    sub  eax,ecx
200
    sub  eax,ecx
201
    add  eax,4
201
    add  eax,4
202
    shl  eax,28
202
    shl  eax,28
203
    jmp  .ex
203
    jmp  .ex
204
  .floop:
204
  .floop:
205
    mov  edi,[edi+16]
205
    mov  edi,[edi+16]
206
    loop .fnext
206
    loop .fnext
207
  .num0:
207
  .num0:
208
    xor  eax,eax
208
    xor  eax,eax
209
  .ex:
209
  .ex:
210
    pop  edi ecx
210
    pop  edi ecx
211
    ret
211
    ret
212
 
212
 
213
_BGIfont_Prepare:
213
_BGIfont_Prepare:
214
; in:  edx-font name, edi->pointer to load fonts (fonts_count)
214
; in:  edx-font name, edi->pointer to load fonts (fonts_count)
215
; out: eax-ID of new font loaded; eax=0 error
215
; out: eax-ID of new font loaded; eax=0 error
216
    cmp  [BGIfont_Ptr],0
216
    cmp  [BGIfont_Ptr],0
217
    jne  .already
217
    jne  .already
218
    mov  [BGIfont_Ptr],edi
218
    mov  [BGIfont_Ptr],edi
219
  .already:
219
  .already:
220
    pusha
220
    pusha
221
    mov  edi,[BGIfont_Ptr]
221
    mov  edi,[BGIfont_Ptr]
222
    movzx ecx,byte[edi] ; ecx-font count
222
    movzx ecx,byte[edi] ; ecx-font count
223
    mov  eax,ecx
223
    mov  eax,ecx
224
    inc  edi ; edi->FontName
224
    inc  edi ; edi->FontName
225
    jecxz .fload
225
    jecxz .fload
226
  .fnext:
226
  .fnext:
227
    cmp  edx,[edi]
227
    cmp  edx,[edi]
228
    jne  .loop
228
    jne  .loop
229
    sub  eax,ecx
229
    sub  eax,ecx
230
    inc  eax
230
    inc  eax
231
    jmp  .cr_id
231
    jmp  .cr_id
232
  .loop:
232
  .loop:
233
    mov  edi,[edi+16]
233
    mov  edi,[edi+16]
234
    loop .fnext
234
    loop .fnext
235
  .fload:
235
  .fload:
236
    mov  dword[.font],edx ; filename
236
    mov  dword[.font],edx ; filename
237
    mov  esi,edi     ; esi->FontName
237
    mov  esi,edi     ; esi->FontName
238
    mov  [.dest],edi ; ptr to load font
238
    mov  [.dest],edi ; ptr to load font
239
if ~ BGI_LEVEL eq KERNEL
239
if ~ BGI_LEVEL eq KERNEL
240
    mov  [.fsize],1
-
 
241
    mov  eax,58
240
        mov     eax, 70
242
    mov  ebx,.fontinfo
241
        mov     ebx, .fontattr
243
    int  0x40
242
        int     0x40
244
    test eax,eax
243
        test    eax, eax
245
    jnz   .fail
244
        jnz     .fail
246
    dps2  '1'
245
        dps2    '1'
247
    shr  ebx,9
246
        mov     eax, [.fileattr+32]
248
    inc  ebx
-
 
249
    mov  [.fsize],ebx
247
        mov     [.fsize], eax
250
    mov  ebx,.fontinfo
248
    mov  ebx,.fontinfo
251
    mov  eax,58
249
    mov  eax,70
252
    int  0x40	     ; ebx - file size
250
    int  0x40	     ; ebx - file size
253
else
251
else
254
    push edi esi edx
252
    push edi esi edx
255
    mov  eax,.font
253
    mov  eax,.font
256
    xor  ebx,ebx
254
    xor  ebx,ebx
257
    mov  esi,12
255
    mov  esi,12
258
    mov  ecx,ebx
256
    mov  ecx,ebx
259
    mov  edx,edi
257
    mov  edx,edi
260
    call fileread
258
    call fileread
261
    pop  edx esi edi
259
    pop  edx esi edi
262
    mov  ebp,edi
260
    mov  ebp,edi
263
    add  ebp,ebx
261
    add  ebp,ebx
264
    cmp  ebp,0x50000
262
    cmp  ebp,0x50000
265
    ja	 .fail
263
    ja	 .fail
266
end if
264
end if
267
    cmp  dword[edi],0x08084b50 ; 'PK',8,8
265
    cmp  dword[edi],0x08084b50 ; 'PK',8,8
268
    jne  .fail
266
    jne  .fail
269
    dps2 '2'
267
    dps2 '2'
270
    inc  edi
268
    inc  edi
271
    mov  eax,26 ; #EOF
269
    mov  eax,26 ; #EOF
272
    mov  ecx,253
270
    mov  ecx,253
273
    cld
271
    cld
274
    repne scasb  ; skip Copyright
272
    repne scasb  ; skip Copyright
275
    test ecx,ecx
273
    test ecx,ecx
276
    jz	 .fail
274
    jz	 .fail
277
    dps2  '3'
275
    dps2  '3'
278
    cmp  edx,[edi+2] ; FontName
276
    cmp  edx,[edi+2] ; FontName
279
    jne  .fail
277
    jne  .fail
280
    dps2  '4'
278
    dps2  '4'
281
    movzx ecx,word[edi] ; HeaderSize
279
    movzx ecx,word[edi] ; HeaderSize
282
    sub  ebx,ecx  ; Filesize-Headersize
280
    sub  ebx,ecx  ; Filesize-Headersize
283
    movzx eax,word[edi+6] ; FontSize
281
    movzx eax,word[edi+6] ; FontSize
284
    cmp  eax,ebx
282
    cmp  eax,ebx
285
    jb	 .fail	  ; file truncated
283
    jb	 .fail	  ; file truncated
286
    add  ecx,[.dest]
284
    add  ecx,[.dest]
287
    dps2  '5'
285
    dps2  '5'
288
    cmp  byte[ecx],'+'	; ParPrefix
286
    cmp  byte[ecx],'+'	; ParPrefix
289
    jne  .fail
287
    jne  .fail
290
; font is valid, let's fill parameter table
288
; font is valid, let's fill parameter table
291
    dps2  '>'
289
    dps2  '>'
292
    mov  [esi],edx ; FontName
290
    mov  [esi],edx ; FontName
293
    mov  edx,eax
291
    mov  edx,eax
294
    add  eax,ecx
292
    add  eax,ecx
295
    mov  [esi+16],eax ; Font EOF
293
    mov  [esi+16],eax ; Font EOF
296
    movzx eax,word[ecx+5]
294
    movzx eax,word[ecx+5]
297
    add  eax,ecx
295
    add  eax,ecx
298
    mov  [esi+12],eax
296
    mov  [esi+12],eax
299
    lea  edi,[esi+4]  ; edi->CharsCount
297
    lea  edi,[esi+4]  ; edi->CharsCount
300
    lea  esi,[ecx+1] ; esi->ParPrefix+1
298
    lea  esi,[ecx+1] ; esi->ParPrefix+1
301
    xor  eax,eax
299
    xor  eax,eax
302
    lodsw
300
    lodsw
303
    stosb  ; CharsCount
301
    stosb  ; CharsCount
304
    inc  esi
302
    inc  esi
305
    movsb  ; FirstChar
303
    movsb  ; FirstChar
306
    add  esi,3
304
    add  esi,3
307
    lodsw
305
    lodsw
308
    stosb  ; UpperMargin
306
    stosb  ; UpperMargin
309
    movsb  ; LowerMargin
307
    movsb  ; LowerMargin
310
    add  esi,5 ; esi->offsets
308
    add  esi,5 ; esi->offsets
311
    mov  eax,[esi]
309
    mov  eax,[esi]
312
    push edi ; edi->Widths
310
    push edi ; edi->Widths
313
; prepare moving data
311
; prepare moving data
314
    add  edi,12 ; edi->offsets
312
    add  edi,12 ; edi->offsets
315
    lea  ecx,[edx-16]
313
    lea  ecx,[edx-16]
316
    rep  movsb
314
    rep  movsb
317
    pop  edi ; edi->Widths
315
    pop  edi ; edi->Widths
318
    mov  [edi+8],esi ; EOF
316
    mov  [edi+8],esi ; EOF
319
;    mov  eax,[edi]
317
;    mov  eax,[edi]
320
    movzx ecx,byte[edi-4] ; CharsCount
318
    movzx ecx,byte[edi-4] ; CharsCount
321
    lea  eax,[edi+12+ecx*2] ; eax->widths
319
    lea  eax,[edi+12+ecx*2] ; eax->widths
322
    stosd  ; edi->FirstData
320
    stosd  ; edi->FirstData
323
    add  eax,ecx
321
    add  eax,ecx
324
    stosd  ; edi->EOF
322
    stosd  ; edi->EOF
325
    mov  eax,[esp] ; eax->fonts_count
323
    mov  eax,[esp] ; eax->fonts_count
326
    inc  byte[eax] ; increase font counter
324
    inc  byte[eax] ; increase font counter
327
    movzx eax,byte[eax]
325
    movzx eax,byte[eax]
328
  .cr_id:
326
  .cr_id:
329
    add  eax,0x3   ; create unique ID
327
    add  eax,0x3   ; create unique ID
330
    shl  eax,28    ; to easy use in color(ecx)
328
    shl  eax,28    ; to easy use in color(ecx)
331
    jmp  .exit
329
    jmp  .exit
332
  .fail:
330
  .fail:
333
    xor  eax,eax
331
    xor  eax,eax
334
  .exit:
332
  .exit:
335
    mov  [esp+28],eax
333
    mov  [esp+28],eax
336
    popa
334
    popa
337
    ret
335
    ret
338
 
336
 
339
if ~ BGI_LEVEL eq KERNEL
337
if ~ BGI_LEVEL eq KERNEL
340
.fontinfo:
338
.fontinfo:
341
	dd 0
339
	dd 0
342
	dd 0
340
	dd 0
-
 
341
	dd 0
343
.fsize	dd 0
342
.fsize	dd 0
344
.dest	dd 0
343
.dest	dd 0
345
	dd 0x10000
344
.fontfullname:
346
	db BGIFONT_PATH
345
	db BGIFONT_PATH
347
.font	db 'FONT.CHR',0
346
.font	db 'FONT.CHR',0
-
 
347
 
-
 
348
.fontattr:
-
 
349
        dd      5
-
 
350
        dd      0
-
 
351
        dd      0
-
 
352
        dd      0
-
 
353
        dd      .fileattr
-
 
354
        db      0
-
 
355
        dd      .fontfullname
-
 
356
.fileattr rd 40/4
348
else
357
else
349
  .dest   dd 0
358
  .dest   dd 0
350
  .font   db 'FONT    CHR'
359
  .font   db 'FONT    CHR'
351
  .okflag db ' ',0
360
  .okflag db ' ',0
352
end if
361
end if
353
 
362
 
354
BGIfont_Coo:
363
BGIfont_Coo:
355
; y->word[txt.y1], x->word[txt.x1]
364
; y->word[txt.y1], x->word[txt.x1]
356
    fild [txt.y1] ;y
365
    fild [txt.y1] ;y
357
    fmul st0,st0; y*y
366
    fmul st0,st0; y*y
358
    fild [txt.x1] ;x
367
    fild [txt.x1] ;x
359
    fmul st0,st0; x*x
368
    fmul st0,st0; x*x
360
    faddp  ; x*x+y*y
369
    faddp  ; x*x+y*y
361
    fsqrt  ; sqrt, angle
370
    fsqrt  ; sqrt, angle
362
    fild [txt.y1];y
371
    fild [txt.y1];y
363
    fabs
372
    fabs
364
    fild [txt.x1] ; x
373
    fild [txt.x1] ; x
365
    fabs
374
    fabs
366
    fpatan ; arctg(y/x)
375
    fpatan ; arctg(y/x)
367
  .skip:
376
  .skip:
368
    cmp  [txt.x1],0
377
    cmp  [txt.x1],0
369
    jge  .xplus
378
    jge  .xplus
370
    fchs
379
    fchs
371
    fadd st0,st3
380
    fadd st0,st3
372
  .xplus:
381
  .xplus:
373
    cmp  [txt.y1],0
382
    cmp  [txt.y1],0
374
    jge  .yplus
383
    jge  .yplus
375
    fchs
384
    fchs
376
  .yplus:
385
  .yplus:
377
    fadd st0,st2
386
    fadd st0,st2
378
    fsincos
387
    fsincos
379
    fmul st0,st2
388
    fmul st0,st2
380
    fiadd [txt.x0]
389
    fiadd [txt.x0]
381
    fistp [txt.x1] ; x=r*cos a
390
    fistp [txt.x1] ; x=r*cos a
382
    fmulp ; y=r*sin a,angle
391
    fmulp ; y=r*sin a,angle
383
    fiadd [txt.y0]
392
    fiadd [txt.y0]
384
    fistp [txt.y1]
393
    fistp [txt.y1]
385
    ret
394
    ret
386
 
395
 
387
_BGIfont_Freetext:
396
_BGIfont_Freetext:
388
; in: ebx-BGIfree structure
397
; in: ebx-BGIfree structure
389
; out: eax-new drawing coords
398
; out: eax-new drawing coords
390
    mov  edx,[ebx]
399
    mov  edx,[ebx]
391
    call _BGIfont_GetID
400
    call _BGIfont_GetID
392
    test eax,eax
401
    test eax,eax
393
    jnz  .fexists
402
    jnz  .fexists
394
    ret
403
    ret
395
  .fexists:
404
  .fexists:
396
    pusha
405
    pusha
397
    fninit
406
    fninit
398
    fldpi
407
    fldpi
399
    fld  [pi180]
408
    fld  [pi180]
400
    fimul dword[ebx+8]
409
    fimul dword[ebx+8]
401
    fst  [BGIangle]
410
    fst  [BGIangle]
402
    mov  esi,[ebx+28]
411
    mov  esi,[ebx+28]
403
    and  esi,0xffffff
412
    and  esi,0xffffff
404
    add  esi,eax
413
    add  esi,eax
405
    mov  eax,[ebx+32]
414
    mov  eax,[ebx+32]
406
    and  [deform],0
415
    and  [deform],0
407
    test eax,BGI_ITALIC
416
    test eax,BGI_ITALIC
408
    jz	 .norm
417
    jz	 .norm
409
    mov  [deform],0.4
418
    mov  [deform],0.4
410
  .norm:
419
  .norm:
411
    mov  ebp,eax
420
    mov  ebp,eax
412
    or	  ebp,BGI_FREE
421
    or	  ebp,BGI_FREE
413
    mov  eax,[ebx+12]
422
    mov  eax,[ebx+12]
414
    mov  [Xscale],eax
423
    mov  [Xscale],eax
415
    mov  eax,[ebx+16]
424
    mov  eax,[ebx+16]
416
    mov  [Yscale],eax
425
    mov  [Yscale],eax
417
    mov  ecx,[ebx+20]
426
    mov  ecx,[ebx+20]
418
    mov  edx,ebp
427
    mov  edx,ebp
419
    and  edx,BGI_FREE+BGI_VAMASK+BGI_HAMASK
428
    and  edx,BGI_FREE+BGI_VAMASK+BGI_HAMASK
420
    add  edx,[ebx+24]
429
    add  edx,[ebx+24]
421
    mov  eax,[ebx+4]
430
    mov  eax,[ebx+4]
422
    mov  ebx,esi
431
    mov  ebx,esi
423
    add  ebx,0x6000000
432
    add  ebx,0x6000000
424
    mov  [esp+4],edx
433
    mov  [esp+4],edx
425
    mov  [esp+20],ecx
434
    mov  [esp+20],ecx
426
    jmp  txt
435
    jmp  txt
427
 
436
 
428
    pi180 dd 0.017453
437
    pi180 dd 0.017453
429
 
438
 
430
_BGIfont_Outtext:
439
_BGIfont_Outtext:
431
; in: ebx-[x][y], ecx-color, edx-string, esi-length
440
; in: ebx-[x][y], ecx-color, edx-string, esi-length
432
    pusha
441
    pusha
433
    mov  ebp,esi
442
    mov  ebp,esi
434
if ~ BGI_LEVEL eq KERNEL
443
if ~ BGI_LEVEL eq KERNEL
435
    mov  eax,ebx
444
    mov  eax,ebx
436
    mov  ebx,ecx
445
    mov  ebx,ecx
437
    mov  ecx,edx
446
    mov  ecx,edx
438
    mov  edx,esi
447
    mov  edx,esi
439
end if
448
end if
440
; in: eax-[x][y], ebx-color, ecx-string, edx-length
449
; in: eax-[x][y], ebx-color, ecx-string, edx-length
441
txt:
450
txt:
442
if  ~ BGI_LEVEL eq KERNEL
451
if  ~ BGI_LEVEL eq KERNEL
443
  if  BGI_WINDOW_CLIP eq 1
452
  if  BGI_WINDOW_CLIP eq 1
444
    pusha
453
    pusha
445
    mov  eax,9
454
    mov  eax,9
446
    mov  ebx,BGI_PRC_INFO
455
    mov  ebx,BGI_PRC_INFO
447
    mov  ecx,-1
456
    mov  ecx,-1
448
    int  0x40
457
    int  0x40
449
    popa
458
    popa
450
  end if
459
  end if
451
end if
460
end if
452
    mov  [.y0],ax
461
    mov  [.y0],ax
453
    shr  eax,16
462
    shr  eax,16
454
    mov  [.x0],ax
463
    mov  [.x0],ax
455
    mov  ecx,ebx ; color
464
    mov  ecx,ebx ; color
456
    and  ebx,0xfffffff
465
    and  ebx,0xfffffff
457
    mov  [.color],ebx
466
    mov  [.color],ebx
458
    call BGIfont_get2head
467
    call BGIfont_get2head
459
    test edi,edi
468
    test edi,edi
460
    jz   .exit
469
    jz   .exit
461
    mov  ecx,[esp+4]; str length
470
    mov  ecx,[esp+4]; str length
462
    mov  esi,[esp+20]; str ptr
471
    mov  esi,[esp+20]; str ptr
463
    movzx eax,byte[edi+5]
472
    movzx eax,byte[edi+5]
464
    push ecx
473
    push ecx
465
    and  ecx,0xff
474
    and  ecx,0xff
466
    jnz  .lenok
475
    jnz  .lenok
467
    add  esp,4
476
    add  esp,4
468
    jmp  .ex2
477
    jmp  .ex2
469
  .lenok:
478
  .lenok:
470
    pusha
479
    pusha
471
    push dword[txt.y0]
480
    push dword[txt.y0]
472
    and  dword[txt.y0],0
481
    and  dword[txt.y0],0
473
    xor  edx,edx
482
    xor  edx,edx
474
    mov  ebx,[edi+8]
483
    mov  ebx,[edi+8]
475
   .next:
484
   .next:
476
    call txt.BGIfont_GetChar
485
    call txt.BGIfont_GetChar
477
    movzx eax,byte[ebx+eax]
486
    movzx eax,byte[ebx+eax]
478
    add  edx,eax
487
    add  edx,eax
479
    loop .next
488
    loop .next
480
    mov  ecx,edx ; ecx - x size
489
    mov  ecx,edx ; ecx - x size
481
    movzx dx,byte[edi+6]
490
    movzx dx,byte[edi+6]
-
 
491
    mov  [BGIheight],dx
482
    mov  ebx,[esp+36]
492
    mov  ebx,[esp+36]
483
    and  ebx,BGI_HAMASK
493
    and  ebx,BGI_HAMASK
484
    cmp  ebx,BGI_HARIGHT
494
    cmp  ebx,BGI_HARIGHT
485
    je   .nova
495
    je   .nova
486
    ja   .subv
496
    ja   .subv
487
    xor  ecx,ecx
497
    xor  ecx,ecx
488
    jmp  .nova
498
    jmp  .nova
489
  .subv:
499
  .subv:
490
    shr  cx,1
500
    shr  cx,1
491
  .nova:
501
  .nova:
492
    mov  ebx,[esp+36]
502
    mov  ebx,[esp+36]
493
    and  ebx,BGI_VAMASK
503
    and  ebx,BGI_VAMASK
494
    cmp  ebx,BGI_VATOP
504
    cmp  ebx,BGI_VATOP
495
    je   .def
505
    je   .def
496
    ja   .subh
506
    ja   .subh
497
    xor  edx,edx
507
    xor  edx,edx
498
    jmp  .def
508
    jmp  .def
499
  .subh:
509
  .subh:
500
    shr  dx,1
510
    shr  dx,1
501
  .def:
511
  .def:
502
    call txt.BGIfont_Deform
512
    call txt.BGIfont_Deform
503
    pop  dword[txt.y0]
513
    pop  dword[txt.y0]
504
    popa
514
    popa
505
    pop  ebx
515
    pop  ebx
506
    mov  ax,[txt.y1]
516
    mov  ax,[txt.y1]
507
    sub  [txt.y0],ax
517
    sub  [txt.y0],ax
508
    mov  ax,[txt.x1]
518
    mov  ax,[txt.x1]
509
    sub  [txt.x0],ax
519
    sub  [txt.x0],ax
510
    xor  eax,eax
520
    xor  eax,eax
511
    cld
521
    cld
512
.mloop:
522
.mloop:
513
    push [.y0]
523
    push [.y0]
514
    pop  [.y]
524
    pop  [.y]
515
    push [.x0]
525
    push [.x0]
516
    pop  [.x]
526
    pop  [.x]
517
    call .BGIfont_GetChar
527
    call .BGIfont_GetChar
518
    push esi
528
    push esi
519
    lea  esi,[edi+20] ; offset
529
    lea  esi,[edi+20] ; offset
520
    movzx edx,word[esi+eax*2] ; ofs1
530
    movzx edx,word[esi+eax*2] ; ofs1
521
    add  edx,[edi+12]
531
    add  edx,[edi+12]
522
    inc  eax
532
    inc  eax
523
    cmp  al,[edi+4]
533
    cmp  al,[edi+4]
524
    je	 .eof
534
    je	 .eof
525
    movzx eax,word[esi+eax*2]; ofs2
535
    movzx eax,word[esi+eax*2]; ofs2
526
    add   eax,[edi+12]
536
    add   eax,[edi+12]
527
    jmp   .prc_vec
537
    jmp   .prc_vec
528
  .eof:
538
  .eof:
529
    mov  eax,[edi+16] ; ofs2=eof
539
    mov  eax,[edi+16] ; ofs2=eof
530
  .prc_vec:  ; edx-vec cmd ifs, eax-cmd limit
540
  .prc_vec:  ; edx-vec cmd ifs, eax-cmd limit
531
    mov  [.vec_end],eax
541
    mov  [.vec_end],eax
532
    push ecx
542
    push ecx
533
  .vec_loop:
543
  .vec_loop:
534
    mov  ax,word[edx]
544
    mov  ax,word[edx]
535
    push edx
545
    push edx
536
    mov  ecx,eax
546
    mov  ecx,eax
537
    and  eax,0x8080 ; op
547
    and  eax,0x8080 ; op
538
    and  ecx,0x7f ; xx
548
    and  ecx,0x7f ; xx
539
    mov  edx,[edx+1]
549
    mov  edx,[edx+1]
540
    and  edx,0x7f ; yy
550
    and  edx,0x7f ; yy
541
    cmp  edx,63
551
    cmp  edx,63
542
    jbe  .positive
552
    jbe  .positive
543
    sub  edx,128  ; yy-=128
553
    sub  edx,128  ; yy-=128
544
  .positive:
554
  .positive:
545
    cmp  ecx,63
555
    cmp  ecx,63
546
    jbe  .positive2
556
    jbe  .positive2
547
    sub  ecx,128  ; xx-=128
557
    sub  ecx,128  ; xx-=128
548
  .positive2:
558
  .positive2:
549
    call .BGIfont_Deform
559
    call .BGIfont_Deform
550
    cmp  eax,0x8080
560
    cmp  eax,0x8080
551
    jne  .noline
561
    jne  .noline
552
    test ebp,BGI_NODRAW
562
    test ebp,BGI_NODRAW
553
    jnz  .noline
563
    jnz  .noline
554
; draw vector
564
; draw vector
555
if ~ BGI_LEVEL eq KERNEL
565
if ~ BGI_LEVEL eq KERNEL
556
    push eax
566
    push eax
557
    mov  ebx,dword[.x1]
567
    mov  ebx,dword[.x1]
558
    mov  ecx,dword[.y1]
568
    mov  ecx,dword[.y1]
559
  if BGI_WINDOW_CLIP eq 1
569
  if BGI_WINDOW_CLIP eq 1
560
    movzx eax,[.x]
570
    movzx eax,[.x]
561
    cmp  eax,dword[BGI_PRC_INFO+42]
571
    cmp  eax,dword[BGI_PRC_INFO+42]
562
    ja   .nobold
572
    ja   .nobold
563
    movzx eax,[.y]
573
    movzx eax,[.y]
564
    cmp  eax,dword[BGI_PRC_INFO+46]
574
    cmp  eax,dword[BGI_PRC_INFO+46]
565
    ja  .nobold
575
    ja  .nobold
566
    xor  eax,eax
576
    xor  eax,eax
567
    cmp  ax,bx
577
    cmp  ax,bx
568
    jg   .nobold
578
    jg   .nobold
569
    cmp  ax,cx
579
    cmp  ax,cx
570
    jg   .nobold
580
    jg   .nobold
571
  end if
581
  end if
572
    mov  edx,[.color]
582
    mov  edx,[.color]
573
; \begin{diamond}[18.08.2006]
583
; \begin{diamond}[18.08.2006]
574
; starting from K0530 kernel interprets flag 0x1000000 as
584
; starting from K0530 kernel interprets flag 0x1000000 as
575
; negate existing pixels colors, disregarding passed color
585
; negate existing pixels colors, disregarding passed color
576
; we do not want this
586
; we do not want this
577
    and  edx, 0xFFFFFF
587
    and  edx, 0xFFFFFF
578
; \end{diamond}[18.08.2006]
588
; \end{diamond}[18.08.2006]
579
    mov  eax,38
589
    mov  eax,38
580
    int  0x40
590
    int  0x40
581
    test ebp,BGI_BOLD
591
    test ebp,BGI_BOLD
582
    jz	 .nobold
592
    jz	 .nobold
583
    test ebp,BGI_FREE
593
    test ebp,BGI_FREE
584
    jnz  .free5
594
    jnz  .free5
585
  .free5:
595
  .free5:
586
    add  ebx,1 shl 16+1
596
    add  ebx,1 shl 16+1
587
    int  0x40
597
    int  0x40
588
  .nobold:
598
  .nobold:
589
    pop  eax
599
    pop  eax
590
else
600
else
591
    pusha
601
    pusha
592
    mov  eax,dword[.x1]
602
    mov  eax,dword[.x1]
593
    mov  ebx,dword[.y1]
603
    mov  ebx,dword[.y1]
594
    mov  ecx,[.color]
604
    mov  ecx,[.color]
595
;    call syscall_drawline
605
;    call syscall_drawline
596
    test dword[esp+8],BGI_BOLD
606
    test dword[esp+8],BGI_BOLD
597
    jz	 .nobold
607
    jz	 .nobold
598
    add  eax,1 shl 16+1
608
    add  eax,1 shl 16+1
599
;    call syscall_drawline
609
;    call syscall_drawline
600
  .nobold:
610
  .nobold:
601
    popa
611
    popa
602
end if
612
end if
603
  .noline:
613
  .noline:
604
    pop  edx
614
    pop  edx
605
    test eax,eax
615
    test eax,eax
606
    je	 .eovecs  ; op=0
616
    je	 .eovecs  ; op=0
607
    push [.y1]
617
    push [.y1]
608
    pop  [.y]
618
    pop  [.y]
609
    push [.x1]
619
    push [.x1]
610
    pop  [.x]
620
    pop  [.x]
611
    add  edx,2
621
    add  edx,2
612
    cmp  edx,[.vec_end]
622
    cmp  edx,[.vec_end]
613
    jb	 .vec_loop
623
    jb	 .vec_loop
614
  .eovecs:
624
  .eovecs:
615
    pop  ecx esi
625
    pop  ecx esi
616
    push [.y]
626
    push [.y]
617
    pop  [.y0]
627
    pop  [.y0]
618
    push [.x]
628
    push [.x]
619
    pop  [.x0]
629
    pop  [.x0]
620
    loop .mloop1
630
    loop .mloop1
621
    jmp  .exit
631
    jmp  .exit
622
  .mloop1:
632
  .mloop1:
623
    jmp  .mloop
633
    jmp  .mloop
624
  .exit:
634
  .exit:
625
    mov  eax,dword[.y0]
635
    mov  eax,dword[.y0]
626
    mov  [esp+28],eax
636
    mov  [esp+28],eax
627
  .ex2:
637
  .ex2:
628
    popa
638
    popa
629
    ret
639
    ret
630
 
640
 
631
.BGIfont_Deform:
641
.BGIfont_Deform:
632
    test ebp,BGI_FREE
642
    test ebp,BGI_FREE
633
    jnz  .free0
643
    jnz  .free0
634
    movzx ebx,byte[.color+3] ;ebx=scale
644
    movzx ebx,byte[.color+3] ;ebx=scale
635
    imul ecx,ebx
645
    imul ecx,ebx
636
    add  ecx,2
646
    add  ecx,2
637
    shr  ecx,2
647
    shr  ecx,2
638
    imul edx,ebx
648
    imul edx,ebx
639
    add  edx,2
649
    add  edx,2
640
    shr  edx,2
650
    shr  edx,2
641
    neg  edx
651
    neg  edx
642
    mov  [.x1],cx
652
    mov  [.x1],cx
643
    mov  [.y1],dx
653
    mov  [.y1],dx
644
    jmp  .add
654
    jmp  .add
645
  .free0:
655
  .free0:
646
    mov  [.x1],cx
656
    mov  [.x1],cx
647
    mov  [.y1],dx
657
    mov  [.y1],dx
648
    fild [.y1]
658
    fild [.y1]
649
    fld  st0
659
    fld  st0
650
    fmul [Yscale]
660
    fmul [Yscale]
651
    fchs
661
    fchs
652
    fistp [.y1]
662
    fistp [.y1]
653
    fmul [deform]
663
    fmul [deform]
654
    fiadd [.x1]
664
    fiadd [.x1]
655
    fmul [Xscale]
665
    fmul [Xscale]
656
    fistp [.x1]
666
    fistp [.x1]
657
    cmp  [BGIangle],0
667
    cmp  [BGIangle],0
658
    je	 .add
668
    je	 .add
659
    call BGIfont_Coo
669
    call BGIfont_Coo
660
    jmp  .eax
670
    jmp  .eax
661
  .add:
671
  .add:
662
    mov  cx,[.x0]
672
    mov  cx,[.x0]
663
    add  [.x1],cx
673
    add  [.x1],cx
664
    mov  cx,[.y0]
674
    mov  cx,[.y0]
665
    add  [.y1],cx
675
    add  [.y1],cx
666
  .eax:
676
  .eax:
667
    ret
677
    ret
668
 
678
 
669
.BGIfont_GetChar:
679
.BGIfont_GetChar:
670
; in:  esi -> string; edi -> BGIrec
680
; in:  esi -> string; edi -> BGIrec
671
; out: esi -> next char; al - char obtained
681
; out: esi -> next char; al - char obtained
672
    lodsb  ; al - char from str
682
    lodsb  ; al - char from str
673
    sub  al,[edi+5]
683
    sub  al,[edi+5]
674
    jb	 .out
684
    jb	 .out
675
    cmp  al,[edi+4]
685
    cmp  al,[edi+4]
676
    jb	 .in
686
    jb	 .in
677
  .out:
687
  .out:
678
    xor  al,al ; al - 1st symbol available
688
    xor  al,al ; al - 1st symbol available
679
  .in:
689
  .in:
680
    ret
690
    ret
681
 
691
 
682
.y0	 dw ?
692
.y0	 dw ?
683
.x0	 dw ?
693
.x0	 dw ?
684
 
694
 
685
.x1	 dw ?
695
.x1	 dw ?
686
.x	 dw ?
696
.x	 dw ?
687
.y1	 dw ?
697
.y1	 dw ?
688
.y	 dw ?
698
.y	 dw ?
689
 
699
 
690
.color	 dd ?
700
.color	 dd ?
691
.vec_end dd ?
701
.vec_end dd ?
692
BGIfont_Ptr  dd 0
702
BGIfont_Ptr  dd 0
693
width  dd ?
703
BGIheight dw ?
694
deform dd ?
704
deform dd ?
695
BGIangle dd ?
705
BGIangle dd ?
696
Xscale  dd ?
706
Xscale  dd ?
697
Yscale  dd ?
707
Yscale  dd ?