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