Subversion Repositories Kolibri OS

Rev

Rev 31 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
; BGI Font Test
2
;
3
; Written in pure assembler by Ivushkin Andrey aka Willow
4
;
5
; Created: December 20, 2004
6
;
7
; Last changed: February 2, 2005
8
;
9
 
10
BGIFONT_PATH equ '/RD/1/'
11
_X equ 340
12
_Y equ 240
13
 
14
BGI_WINDOW_CLIP equ 1
15
BGI_PRC_INFO equ pinfo
16
 
17
macro ListFonts
18
{
19
   mov  eax,lf_head
20
   call PixelPrint
21
   mov  ebx,20 shl 16+60
22
   mov  ecx,(BGIfont_names_end-BGIfont_names)/4
23
   mov  esi,BGIfont_names
24
 .l1:
25
   pusha
26
   pusha
27
   mcall 4,,0x10777fac,esi,4
28
   popa
29
   mov  edx,[esi]
30
   BGIfont_GetID
31
   mov  dword[_BGIfont_Prepare.font],edx
32
   mov  ecx,eax
33
   add  ebx,140 shl 16
34
   mov  edx,ebx
35
   mcall 47,0x80100,,,0x10ffffff
36
   jecxz .nofont
37
   lea  ebx,[edx+80 shl 16+12]
38
   mov  edx,_BGIfont_Prepare.dest+8
39
   mov  esi,BGIfont_Coo-1
40
   sub  esi,edx
41
   add  ecx,0x3b800b8
42
   BGIfont_Outtext
43
   sub  ebx,155 shl 16+12
44
   mcall 4,,0x1000f000,load_ok,load_fail-load_ok
45
   jmp  .pop
46
 .nofont:
47
   lea  ebx,[edx-80 shl 16]
48
   mcall 4,,0x10f00010,load_fail,font_msg-load_fail
49
 .pop:
50
   popa
51
   add  esi,4
52
   add  ebx,39
53
   loop .l2
54
   jmp  .ex
55
 .l2:
56
   jmp  .l1
57
.ex:
58
}
59
use32
60
  org	 0x0
61
 
62
  db	 'MENUET01'
63
  dd	 0x01
64
  dd	 START
65
  dd	 I_END
66
  dd	 0x100000
67
  dd	 0x0cfff0
68
  dd	 0x0
69
not1strun  dd	 0x0
70
 
71
include  'lang.inc'
72
include  'macros.inc'
73
;include   'debug.inc'
74
include  'bgifont.inc'
75
lang equ en;ru;en
76
 
77
START:
78
    mov  [help],0
79
    mov  ecx,(BGIfont_names_end-BGIfont_names)/4
80
    mov  esi,BGIfont_names
81
    mov  edi,I_END
82
    BGIfont_Init
83
reset:
84
    mov  esi,[BGIfont_Ptr]
85
    inc  esi
86
    mov  edi,freeconst
87
    movsd
88
    mov  esi,freeconst
89
    mov  edi,freetest
90
    mov  ecx,36
91
    rep  movsb
92
red:
93
    mov  eax,[freetest]
94
    mov  dword[title+19],eax
95
    call draw_window
96
    cmp  [not1strun],0
97
    jnz  still
98
    mcall 5,300
99
    not  [not1strun]
100
    inc  [help]
101
    jmp  red
102
still:
103
 
104
    mov  eax,10
105
    int  0x40
106
 
107
    cmp  eax,1
108
    je	 red
109
    cmp  eax,2
110
    je	 key
111
    cmp  eax,3
112
    je	 button
113
 
114
    jmp  still
115
 
116
button:
117
    mov  eax,17
118
    int  0x40
119
    cmp  ah,1
120
    jnz  noclose
121
close:
122
    xor  eax,eax
123
    dec  eax
124
    int  0x40
125
  noclose:
126
    jmp  still
127
 
128
key:
129
    mov  eax,2
130
    int  0x40
131
    shr  eax,8
132
    cmp  al,27 ; esc - close
133
    je   close
134
    cmp  al,32 ; Space - help
135
    jne  .noh
136
    inc  [help]
137
    cmp  [help],3
138
    jne  red
139
    and  [help],0
140
    jmp  red
141
  .noh:
142
    cmp  [help],2
143
    jne   still
144
    cmp  al,50
145
    jb   .noff
146
    cmp  al,57
147
    ja   .noff
148
    sub  al,46
149
  .gn:
150
    movzx ecx,al
151
    shl  ecx,28
152
    call BGIfont_GetName
153
    mov  [freetest],edx
154
    jmp  red
155
  .noff:
156
    mov  ecx,4
157
    mov  edi,Fkeys
158
  .fkey:
159
    cmp  al,[edi]
160
    je   .fndkey
161
    inc  edi
162
    loop .fkey
163
    jmp  .notfnd
164
  .fndkey:
165
    lea  eax,[edi-Fkeys+0xc]
166
    jmp  .gn
167
  .notfnd:
168
    cmp  al,114 ; r - reset
169
    je   reset
170
    cmp  al,176
171
    jne  .nol  ; left
172
    sub  dword[freetest+8],5
173
    jmp  red
174
  .nol:
175
    cmp  al,179
176
    jne  .nor  ; right
177
    add  dword[freetest+8],5
178
    jmp  red
179
  .nor:
180
    cmp  al,105 ; i -italic
181
    jne  .noi
182
    xor  dword[freetest+32],BGI_ITALIC
183
    jmp  red
184
  .noi:
185
    cmp  al,98 ; b -bold
186
    jne  .nob
187
    xor  dword[freetest+32],BGI_BOLD
188
    jmp  red
189
  .nob:
190
    mov  ecx,2
191
    mov  esi,ali
192
  .ol2:
193
    cmp  al,[esi]
194
    jne  .othl2
195
    mov  ax,[freetest+32]
196
    add  ax,[esi+3]
197
    mov  bx,ax
198
    mov  dx,[esi+1]
199
    and  bx,dx
200
    cmp  bx,dx
201
    jne  .ok
202
    not  dx
203
    and  ax,dx
204
  .ok:
205
    mov  [freetest+32],ax
206
    jmp  red
207
  .othl2:
208
    add  esi,5
209
    loop .ol2
210
  .other:
211
    mov  esi,delt
212
    mov  ecx,4
213
  .ol:
214
    cmp  al,[esi]
215
    jne  .othl
216
    fld  dword[esi+1]
217
    movzx eax,byte[esi+5]
218
    fadd dword[freetest+eax]
219
    fstp dword[freetest+eax]
220
    jmp  red
221
  .othl:
222
    add  esi,6
223
    loop .ol
224
    jmp  still
225
 
226
draw_window:
227
    mov  eax,12
228
    mov  ebx,1
229
    int  0x40
230
 
231
    xor  eax,eax
232
    mov  ebx,10*65536+_X*2
233
    mov  ecx,100*65536+_Y*2
234
    mov  edx,0x03261212
235
    mov  esi,0x805080d0
236
    mov  edi,0x005080d0
237
    int  0x40
238
 
239
    mov  eax,4
240
    mov  ebx,8*65536+8
241
    mov  ecx,0x10ddeeff
242
    mov  edx,title
243
    mov  esi,title_end-title
244
    cmp  [help],2
245
    je   .int
246
    sub  esi,12
247
  .int:
248
    int  0x40
249
 
250
    cmp  [help],0
251
    jnz  .help
252
    cmp  byte[I_END],0
253
    jnz  .fontsok
254
    mov  eax,font_msg
255
    call PixelPrint
256
  .fontsok:
257
    ListFonts
258
    jmp  .eod
259
  .help:
260
    cmp  [help],1
261
    jne  .nohelp
262
    mov  eax,helptxt
263
    cmp  byte[I_END],0
264
    jnz  .fontsok2
265
    mov  word[eax+2],_X-80
266
    call PixelPrint
267
    jmp  .eod
268
  .fontsok2:
269
    mov  word[eax+2],_X
270
    call Print
271
    jmp  .eod
272
  .nohelp:
273
    mov  edi,cross
274
    mov  eax,38
275
    mov  edx,0x4b331a
276
    mov  ebx,[edi]
277
    mov  ecx,[edi+4]
278
    int  0x40
279
    mov  ebx,[edi+8]
280
    mov  ecx,[edi+12]
281
    int  0x40
282
    mov  ebx,freetest
283
    BGIfont_Freetext
284
  .eod:
285
    mov  eax,12
286
    mov  ebx,2
287
    int  0x40
288
    ret
289
 
290
Print:	; eax-pointer to _txt struc
291
   pusha
292
   mov	ebx,[eax]
293
   movzx ecx,byte[eax+12]
294
   lea	edx,[eax+13]
295
   mov	edi,eax
296
 .nextstr:
297
   mov esi,[edx]
298
   add	edx,4
299
   push ecx
300
   mov	ecx,[edi+8]
301
   BGIfont_Outtext
302
   add	 ebx,[edi+4]
303
   pop	 ecx
304
   and  esi,0xfff
305
   add	 edx,esi
306
   loop .nextstr
307
   popa
308
   ret
309
 
310
PixelPrint: ; eax-pointer to _txt struc, but used differently
311
   pusha
312
   mov  ebp,eax
313
   mov  ebx,[ebp]
314
   movzx ecx,byte[ebp+12]
315
   mov  eax,4
316
   lea  edx,[ebp+17]
317
 .l:
318
   mov  esi,[edx-4]
319
   and  esi,0xfff
320
   push ecx
321
   mov  ecx,[ebp+8]
322
   int  0x40
323
   pop  ecx
324
   lea  edx,[esi+edx+4]
325
   add  ebx,[ebp+4]
326
   loop .l
327
   popa
328
   ret
329
 
330
macro _txt _xy,_vert,_color,_opt,[_str]
331
{
332
common
333
   _counter=0
334
forward
335
   _counter=_counter+1
336
common
337
   dd  _xy	      ; 0
338
   dd  _vert	    ; 4
339
   dd  _color	    ; 8
340
   db  _counter   ;_str_count   ; 12
341
forward
342
   local .str_beg,.str_end
343
   dd  (.str_end-.str_beg) or _opt  ; 13
344
 .str_beg:
345
   db  _str		    ;17
346
 .str_end:
347
}
348
 
349
title db 'BGIFONT.INC demo - FONT font'
350
title_end:
351
_M equ 30
352
cross dd _M shl 16+_X*2-_M,_Y shl 16+_Y,_X shl 16+_X,_M shl 16+_Y*2-_M
353
helptxt:
354
if  lang eq ru
355
_txt _X shl 16+60,40,0x434ba010,BGI_HACENTER,\
356
     "ГОРЯЧИЕ КЛАВИШИ:",\
357
     "Пробел - шрифты/этот текст/демка;",\
358
     "<-> стрелки - вращение строки;",\
359
     "V - выравнивание по вертикали;",\
360
     "H - выравнивание по горизонтали;",\
361
     "[,] - масштаб по оси X;",\
362
     "A,Z - масштаб по оси Y;",\
363
     "B,I - полужирный шрифт и курсив;",\
364
     "R - сброс параметров шрифта;",\
365
     "F1..F12 - выбор шрифта;",\
366
     "Esc - закрыть прогу :-("
367
alpha:
368
   db "Вот пример текста!"
369
lf_head:
370
_txt 10 shl 16+30,85 shl 16,0x6e00f7,0,"Имя шрифта","Статус","ID",\
371
     "Путь к файлу"
372
load_ok:
373
   db "загружен"
374
load_fail:
375
   db "не найден"
376
font_msg:
377
   _txt (_X+20) shl 16+180,25,0x10ff0000,0,\
378
   "К сожалению, не найдено ни одного",\
379
   "векторного шрифта *.CHR. Возможно,",\
380
   "вам следует исправить константу",\
381
   "BGIFONT_PATH в начале файла BGITEST.ASM",\
382
   "и перекомпилировать его :-("
383
else
384
_txt _X shl 16+60,40,0x434ba010, BGI_HACENTER,\
385
     "HOT KEYS:",\
386
     "Space - font list/this message/demo;",\
387
     "<-> arrows - rotate text string;",\
388
     "V - toggle vertical alignment;",\
389
     "H - toggle horizontal alignment;",\
390
     "[,] - scale on X axis;",\
391
     "A,Z - scale on Y axis;",\
392
     "B,I - toggle bold & italic mode;",\
393
     "R - reset font options;",\
394
     "F1..F12 - select font;",\
395
     "Esc - close demo :-("
396
alpha:
397
   db 'This is a Sample text!'
398
;    db 'ABCDEFGHIGKLMNOPQRSTUVWXWZ'
399
lf_head:
400
_txt 10 shl 16+30,85 shl 16,0x6e00f7,0,"Font name","Status","ID",\
401
     "Filename"
402
load_ok:
403
   db "loaded"
404
load_fail:
405
   db "not found"
406
font_msg:
407
   _txt (_X+20) shl 16+180,25,0x10ff0000,0,\
408
   "Sorry, no vector font *.CHR found.",\
409
   "Maybe you should correct BGIFONT_PATH",\
410
   "constant at the beginning of file",\
411
   "BGITEST.ASM and recompile it :-("
412
end if
413
 
414
macro Deltas _key,_scale,_ofs
415
{
416
   db _key
417
   dd _scale
418
   db _ofs
419
}
420
 
421
delt:
422
Deltas  91, -0.15,12
423
Deltas  93, 0.15,12
424
Deltas  97, 0.15,16
425
Deltas  122,-0.15,16
426
Fkeys db 48,49,68,255
427
 
428
macro Aligns _key,_mask,_add
429
{
430
   db _key
431
   dw _mask,_add
432
}
433
ali:
434
Aligns 118,BGI_VAMASK,BGI_VATOP
435
Aligns 104,BGI_HAMASK,BGI_HARIGHT
436
freeconst BGIfree 'FONT',_X shl 16+_Y,0, 1.0, 1.0, alpha,\
437
    lf_head-alpha,0xb800e7,\
438
    BGI_VACENTER or BGI_HACENTER
439
freetest BGIfree ?,?,?,?,?,?,?,?,?
440
help db ?
441
pinfo:
442
    times 1024 db ?
443
rb 10000     ; reserve, unless process info will corrupt our fonts (why?)
444
I_END: