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