Subversion Repositories Kolibri OS

Rev

Rev 109 | Rev 139 | 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  [BGIheight],dx
483
    mov  ebx,[esp+36]
484
    and  ebx,BGI_HAMASK
485
    cmp  ebx,BGI_HARIGHT
486
    je   .nova
487
    ja   .subv
488
    xor  ecx,ecx
489
    jmp  .nova
490
  .subv:
491
    shr  cx,1
492
  .nova:
493
    mov  ebx,[esp+36]
494
    and  ebx,BGI_VAMASK
495
    cmp  ebx,BGI_VATOP
496
    je   .def
497
    ja   .subh
498
    xor  edx,edx
499
    jmp  .def
500
  .subh:
501
    shr  dx,1
502
  .def:
503
    call txt.BGIfont_Deform
504
    pop  dword[txt.y0]
505
    popa
506
    pop  ebx
507
    mov  ax,[txt.y1]
508
    sub  [txt.y0],ax
509
    mov  ax,[txt.x1]
510
    sub  [txt.x0],ax
511
    xor  eax,eax
512
    cld
513
.mloop:
514
    push [.y0]
515
    pop  [.y]
516
    push [.x0]
517
    pop  [.x]
518
    call .BGIfont_GetChar
519
    push esi
520
    lea  esi,[edi+20] ; offset
521
    movzx edx,word[esi+eax*2] ; ofs1
522
    add  edx,[edi+12]
523
    inc  eax
524
    cmp  al,[edi+4]
525
    je	 .eof
526
    movzx eax,word[esi+eax*2]; ofs2
527
    add   eax,[edi+12]
528
    jmp   .prc_vec
529
  .eof:
530
    mov  eax,[edi+16] ; ofs2=eof
531
  .prc_vec:  ; edx-vec cmd ifs, eax-cmd limit
532
    mov  [.vec_end],eax
533
    push ecx
534
  .vec_loop:
535
    mov  ax,word[edx]
536
    push edx
537
    mov  ecx,eax
538
    and  eax,0x8080 ; op
539
    and  ecx,0x7f ; xx
540
    mov  edx,[edx+1]
541
    and  edx,0x7f ; yy
542
    cmp  edx,63
543
    jbe  .positive
544
    sub  edx,128  ; yy-=128
545
  .positive:
546
    cmp  ecx,63
547
    jbe  .positive2
548
    sub  ecx,128  ; xx-=128
549
  .positive2:
550
    call .BGIfont_Deform
551
    cmp  eax,0x8080
552
    jne  .noline
553
    test ebp,BGI_NODRAW
554
    jnz  .noline
555
; draw vector
556
if ~ BGI_LEVEL eq KERNEL
557
    push eax
558
    mov  ebx,dword[.x1]
559
    mov  ecx,dword[.y1]
560
  if BGI_WINDOW_CLIP eq 1
561
    movzx eax,[.x]
562
    cmp  eax,dword[BGI_PRC_INFO+42]
563
    ja   .nobold
564
    movzx eax,[.y]
565
    cmp  eax,dword[BGI_PRC_INFO+46]
566
    ja  .nobold
567
    xor  eax,eax
568
    cmp  ax,bx
569
    jg   .nobold
570
    cmp  ax,cx
571
    jg   .nobold
572
  end if
573
    mov  edx,[.color]
134 diamond 574
; \begin{diamond}[18.08.2006]
575
; starting from K0530 kernel interprets flag 0x1000000 as
576
; negate existing pixels colors, disregarding passed color
577
; we do not want this
578
    and  edx, 0xFFFFFF
579
; \end{diamond}[18.08.2006]
31 halyavin 580
    mov  eax,38
581
    int  0x40
582
    test ebp,BGI_BOLD
583
    jz	 .nobold
584
    test ebp,BGI_FREE
585
    jnz  .free5
586
  .free5:
587
    add  ebx,1 shl 16+1
588
    int  0x40
589
  .nobold:
590
    pop  eax
591
else
592
    pusha
593
    mov  eax,dword[.x1]
594
    mov  ebx,dword[.y1]
595
    mov  ecx,[.color]
596
;    call syscall_drawline
597
    test dword[esp+8],BGI_BOLD
598
    jz	 .nobold
599
    add  eax,1 shl 16+1
600
;    call syscall_drawline
601
  .nobold:
602
    popa
603
end if
604
  .noline:
605
    pop  edx
606
    test eax,eax
607
    je	 .eovecs  ; op=0
608
    push [.y1]
609
    pop  [.y]
610
    push [.x1]
611
    pop  [.x]
612
    add  edx,2
613
    cmp  edx,[.vec_end]
614
    jb	 .vec_loop
615
  .eovecs:
616
    pop  ecx esi
617
    push [.y]
618
    pop  [.y0]
619
    push [.x]
620
    pop  [.x0]
621
    loop .mloop1
622
    jmp  .exit
623
  .mloop1:
624
    jmp  .mloop
625
  .exit:
626
    mov  eax,dword[.y0]
627
    mov  [esp+28],eax
628
  .ex2:
629
    popa
630
    ret
631
 
632
.BGIfont_Deform:
633
    test ebp,BGI_FREE
634
    jnz  .free0
635
    movzx ebx,byte[.color+3] ;ebx=scale
636
    imul ecx,ebx
637
    add  ecx,2
638
    shr  ecx,2
639
    imul edx,ebx
640
    add  edx,2
641
    shr  edx,2
642
    neg  edx
643
    mov  [.x1],cx
644
    mov  [.y1],dx
645
    jmp  .add
646
  .free0:
647
    mov  [.x1],cx
648
    mov  [.y1],dx
649
    fild [.y1]
650
    fld  st0
651
    fmul [Yscale]
652
    fchs
653
    fistp [.y1]
654
    fmul [deform]
655
    fiadd [.x1]
656
    fmul [Xscale]
657
    fistp [.x1]
658
    cmp  [BGIangle],0
659
    je	 .add
660
    call BGIfont_Coo
661
    jmp  .eax
662
  .add:
663
    mov  cx,[.x0]
664
    add  [.x1],cx
665
    mov  cx,[.y0]
666
    add  [.y1],cx
667
  .eax:
668
    ret
669
 
670
.BGIfont_GetChar:
671
; in:  esi -> string; edi -> BGIrec
672
; out: esi -> next char; al - char obtained
673
    lodsb  ; al - char from str
674
    sub  al,[edi+5]
675
    jb	 .out
676
    cmp  al,[edi+4]
677
    jb	 .in
678
  .out:
679
    xor  al,al ; al - 1st symbol available
680
  .in:
681
    ret
682
 
683
.y0	 dw ?
684
.x0	 dw ?
685
 
686
.x1	 dw ?
687
.x	 dw ?
688
.y1	 dw ?
689
.y	 dw ?
690
 
691
.color	 dd ?
692
.vec_end dd ?
693
BGIfont_Ptr  dd 0
694
BGIheight dw ?
695
deform dd ?
696
BGIangle dd ?
697
Xscale  dd ?
698
Yscale  dd ?