Subversion Repositories Kolibri OS

Rev

Rev 539 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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 '/sys/FONTS/'
  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.fontfullname
  39.    mov  esi,_BGIfont_Prepare.fontattr-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     0x100000
  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.  
  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.     mcall
  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.     mcall
  118.     cmp  ah,1
  119.     jnz  noclose
  120. close:
  121.     xor  eax,eax
  122.     dec  eax
  123.     mcall
  124.   noclose:
  125.     jmp  still
  126.  
  127. key:
  128.     mov  eax,2
  129.     mcall
  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.  
  227.     mov  eax,48
  228.     mov  ebx,3
  229.     mov  ecx,sc
  230.     mov  edx,sizeof.system_colors
  231.     mcall
  232.  
  233.     mov  eax,12
  234.     mov  ebx,1
  235.     mcall
  236.  
  237.     xor  eax,eax
  238.     mov  ebx,10*65536+_X*2+30
  239.     mov  ecx,100*65536+_Y*2
  240.     mov  edx,0x04261212
  241.     mov  esi,0x805080d0
  242.     mov  edi,0x005080d0
  243.     mcall
  244.  
  245.     mov  eax,4
  246.     mov  ebx,8*65536+8
  247.     mov  ecx,[sc.grab_text]
  248.     or   ecx,0x10000000
  249.     mov  edx,title
  250.     mov  esi,title_end-title
  251.     cmp  [help],2
  252.     je   .int
  253.     sub  esi,12
  254.   .int:
  255.     mcall
  256.  
  257.     cmp  [help],0
  258.     jnz  .help
  259.     cmp  byte[I_END],0
  260.     jnz  .fontsok
  261.     mov  eax,font_msg
  262.     call PixelPrint
  263.   .fontsok:
  264.     ListFonts
  265.     jmp  .eod
  266.   .help:
  267.     cmp  [help],1
  268.     jne  .nohelp
  269.     mov  eax,helptxt
  270.     cmp  byte[I_END],0
  271.     jnz  .fontsok2
  272.     mov  word[eax+2],_X-80
  273.     call PixelPrint
  274.     jmp  .eod
  275.   .fontsok2:
  276.     mov  word[eax+2],_X
  277.     call Print
  278.     jmp  .eod
  279.   .nohelp:
  280.     mov  edi,cross
  281.     mov  eax,38
  282.     mov  edx,0x4b331a
  283.     mov  ebx,[edi]
  284.     mov  ecx,[edi+4]
  285.     mcall
  286.     mov  ebx,[edi+8]
  287.     mov  ecx,[edi+12]
  288.     mcall
  289.     mov  ebx,freetest
  290.     BGIfont_Freetext
  291.   .eod:
  292.     mov  eax,12
  293.     mov  ebx,2
  294.     mcall
  295.     ret
  296.  
  297. Print:  ; eax-pointer to _txt struc
  298.    pusha
  299.    mov  ebx,[eax]
  300.    movzx ecx,byte[eax+12]
  301.    lea  edx,[eax+13]
  302.    mov  edi,eax
  303.  .nextstr:
  304.    mov esi,[edx]
  305.    add  edx,4
  306.    push ecx
  307.    mov  ecx,[edi+8]
  308.    BGIfont_Outtext
  309.    add   ebx,[edi+4]
  310.    pop   ecx
  311.    and  esi,0xfff
  312.    add   edx,esi
  313.    loop .nextstr
  314.    popa
  315.    ret
  316.  
  317. PixelPrint: ; eax-pointer to _txt struc, but used differently
  318.    pusha
  319.    mov  ebp,eax
  320.    mov  ebx,[ebp]
  321.    movzx ecx,byte[ebp+12]
  322.    mov  eax,4
  323.    lea  edx,[ebp+17]
  324.  .l:
  325.    mov  esi,[edx-4]
  326.    and  esi,0xfff
  327.    push ecx
  328.    mov  ecx,[ebp+8]
  329.    mcall
  330.    pop  ecx
  331.    lea  edx,[esi+edx+4]
  332.    add  ebx,[ebp+4]
  333.    loop .l
  334.    popa
  335.    ret
  336.  
  337. macro _txt _xy,_vert,_color,_opt,[_str]
  338. {
  339. common
  340.    _counter=0
  341. forward
  342.    _counter=_counter+1
  343. common
  344.    dd  _xy            ; 0
  345.    dd  _vert        ; 4
  346.    dd  _color       ; 8
  347.    db  _counter   ;_str_count   ; 12
  348. forward
  349.    local .str_beg,.str_end
  350.    dd  (.str_end-.str_beg) or _opt  ; 13
  351.  .str_beg:
  352.    db  _str                 ;17
  353.  .str_end:
  354. }
  355.  
  356. title db 'BGIFONT.INC demo - FONT font'
  357. title_end:
  358. _M equ 30
  359. cross dd _M shl 16+_X*2-_M,_Y shl 16+_Y,_X shl 16+_X,_M shl 16+_Y*2-_M
  360. helptxt:
  361. if  lang eq ru
  362. _txt _X shl 16+60,40,0x434ba010,BGI_HACENTER,\
  363.      "ƒŽŸ—ˆ… Š‹€‚ˆ˜ˆ:",\
  364.      "à®¡¥« - èà¨äâë/íâ®â ⥪áâ/¤¥¬ª ;",\
  365.      "<-> áâ५ª¨ - ¢à é¥­¨¥ áâப¨;",\
  366.      "V - ¢ëà ¢­¨¢ ­¨¥ ¯® ¢¥à⨪ «¨;",\
  367.      "H - ¢ëà ¢­¨¢ ­¨¥ ¯® £®à¨§®­â «¨;",\
  368.      "[,] - ¬ áèâ ¡ ¯® ®á¨ X;",\
  369.      "A,Z - ¬ áèâ ¡ ¯® ®á¨ Y;",\
  370.      "B,I - ¯®«ã¦¨à­ë© èà¨äâ ¨ ªãàᨢ;",\
  371.      "R - á¡à®á ¯ à ¬¥â஢ èà¨äâ ;",\
  372.      "F1..F12 - ¢ë¡®à èà¨äâ ;",\
  373.      "Esc - § ªàëâì ¯à®£ã :-("
  374. alpha:
  375.    db "‚®â ¯à¨¬¥à ⥪áâ !"
  376. lf_head:
  377. _txt 10 shl 16+30,85 shl 16,0x6e00f7,0,"ˆ¬ï èà¨äâ ","‘â âãá","ID",\
  378.      "ãâì ª ä ©«ã"
  379. load_ok:
  380.    db "§ £à㦥­"
  381. load_fail:
  382.    db "­¥ ­ ©¤¥­"
  383. font_msg:
  384.    _txt (_X+20) shl 16+180,25,0x10ff0000,0,\
  385.    "Š ᮦ «¥­¨î, ­¥ ­ ©¤¥­® ­¨ ®¤­®£®",\
  386.    "¢¥ªâ®à­®£® èà¨äâ  *.CHR. ‚®§¬®¦­®,",\
  387.    "¢ ¬ á«¥¤ã¥â ¨á¯à ¢¨âì ª®­áâ ­âã",\
  388.    "BGIFONT_PATH ¢ ­ ç «¥ ä ©«  BGITEST.ASM",\
  389.    "¨ ¯¥à¥ª®¬¯¨«¨à®¢ âì ¥£® :-("
  390. else
  391. _txt _X shl 16+60,40,0x434ba010, BGI_HACENTER,\
  392.      "HOT KEYS:",\
  393.      "Space - font list/this message/demo;",\
  394.      "<-> arrows - rotate text string;",\
  395.      "V - toggle vertical alignment;",\
  396.      "H - toggle horizontal alignment;",\
  397.      "[,] - scale on X axis;",\
  398.      "A,Z - scale on Y axis;",\
  399.      "B,I - toggle bold & italic mode;",\
  400.      "R - reset font options;",\
  401.      "F1..F12 - select font;",\
  402.      "Esc - close demo :-("
  403. alpha:
  404.    db 'This is a Sample text!'
  405. ;    db 'ABCDEFGHIGKLMNOPQRSTUVWXWZ'
  406. lf_head:
  407. _txt 10 shl 16+30,85 shl 16,0x6e00f7,0,"Font name","Status","ID",\
  408.      "Filename"
  409. load_ok:
  410.    db "loaded"
  411. load_fail:
  412.    db "not found"
  413. font_msg:
  414.    _txt (_X+20) shl 16+180,25,0x10ff0000,0,\
  415.    "Sorry, no vector font *.CHR found.",\
  416.    "Maybe you should correct BGIFONT_PATH",\
  417.    "constant at the beginning of file",\
  418.    "BGITEST.ASM and recompile it :-("
  419. end if
  420.  
  421. macro Deltas _key,_scale,_ofs
  422. {
  423.    db _key
  424.    dd _scale
  425.    db _ofs
  426. }
  427.  
  428. delt:
  429. Deltas  91, -0.15,12
  430. Deltas  93, 0.15,12
  431. Deltas  97, 0.15,16
  432. Deltas  122,-0.15,16
  433. Fkeys db 48,49,68,255
  434.  
  435. macro Aligns _key,_mask,_add
  436. {
  437.    db _key
  438.    dw _mask,_add
  439. }
  440. ali:
  441. Aligns 118,BGI_VAMASK,BGI_VATOP
  442. Aligns 104,BGI_HAMASK,BGI_HARIGHT
  443. freeconst BGIfree 'FONT',_X shl 16+_Y,0, 1.0, 1.0, alpha,\
  444.     lf_head-alpha,0xb800e7,\
  445.     BGI_VACENTER or BGI_HACENTER
  446. freetest BGIfree ?,?,?,?,?,?,?,?,?
  447. help db ?
  448. pinfo:
  449.     times 1024 db ?
  450. sc     system_colors
  451. I_END:
  452.