Subversion Repositories Kolibri OS

Rev

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