Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;    ICON APPLICATION
  3. ;
  4. ;    Compile with FASM for Menuet
  5. ;
  6. ;    August 12, 2004 - 32-bit ICO format support (mike.dld)
  7. ;    March  14, 2007 - rewriten for KolibriOS (heavyiron)
  8.  
  9. use32
  10.  
  11.  org    0x0
  12.  db     'MENUET01'              ; 8 byte id
  13.  dd     0x01                    ; header version
  14.  dd     START                   ; start of code
  15.  dd     I_END                   ; size of image
  16.  dd     0x8000                  ; memory for app
  17.  dd     0x8000                  ; esp
  18.  dd     I_PARAM , 0x0           ; I_Param , I_Icon
  19.  
  20. ; params 4 xpos 4 ypos 30 iconfile 30 startfile 10 label
  21. ;          +0     +4      +8          +38          +68
  22.  
  23. include  '..\..\..\macros.inc'
  24.  
  25. ;__DEBUG__ fix 1
  26. ;__DEBUG_LEVEL__ fix 1
  27. ;include  'debug-fdo.inc'
  28.  
  29. flipdelay = 5
  30.  
  31. START:           ; start of execution
  32.  
  33.     cmp   [I_PARAM],byte 0
  34.     jne   nohalt
  35.     mcall -1
  36.  
  37.  nohalt:
  38.     mov   eax,[I_PARAM+0]
  39.     sub   eax,0x01010101
  40.     mov   [xpos],eax
  41.     mov   eax,[I_PARAM+4]
  42.     sub   eax,0x01010101
  43.     mov   [ypos],eax
  44.  
  45.     mov   esi,I_PARAM+8
  46.     mov   edi,fname
  47.     mov   ecx,30
  48.     cld
  49.     rep   movsb
  50.     call  fill_paths
  51.    
  52. ;DEBUGF 1,"fname: '%s'\n",fname
  53.  
  54.     mov   esi,I_PARAM+8+30
  55.     mov   edi,start_file
  56.     mov   ecx,30
  57.     cld
  58.     rep   movsb
  59.     call  fill_paths
  60.  
  61.     mov   esi,I_PARAM+8+30+30
  62.     mov   edi,labelt
  63.     mov   ecx,10
  64.     cld
  65.     rep   movsb
  66.  
  67.     mcall 40,110001b
  68.  
  69.     mcall 37,4,hand,1
  70.     mov   ecx,eax
  71.     mcall 37,5
  72.  
  73. red:
  74.     call  get_bg
  75.     call  draw_window
  76.  
  77. still:
  78.  
  79.     mcall  10          ; wait here for event
  80.  
  81.     cmp   eax,1          ; redraw request ?
  82.     jz    red
  83.     cmp   eax,6
  84.     jz    mouse
  85.  
  86.     call  get_bg
  87.     call  draw_icon
  88.     mcall 5,80
  89.     jmp   still
  90.  
  91.  
  92.   mouse:
  93.  
  94.     mcall 9,process,-1
  95.     xor   ebx,ebx
  96.     mov   bx,[process.window_stack_position]
  97.     cmp   eax,ebx              ;check is this process is active
  98.     jne   still
  99.  
  100.     cmp   [mouse_pressed],1
  101.     je    @f
  102.  
  103.     mcall 37,2
  104.     test  eax,1
  105.     jz    still
  106.  
  107.     mov   [icon_moved],0
  108.  
  109.     mcall 37,0
  110.     mov   ebx,eax
  111.     shr   eax,16             ;   eax= abs x
  112.     and   ebx,0xffff         ;   ebx= abs y
  113.  
  114.     mov   [xmouse_old],eax   ; saving mouse coordinates
  115.     mov   [ymouse_old],ebx
  116.  
  117.     cmp   eax,[process.box.left]    ; check is mouse in icon area
  118.     jl    still
  119.     sub   eax,[process.box.left]
  120.     cmp   eax,[process.box.width]
  121.     ja    still
  122.  
  123.     cmp   ebx,[process.box.top]
  124.     jl    still
  125.     sub   ebx,[process.box.top]
  126.     cmp   ebx,[process.box.height]
  127.     ja    still
  128.  
  129.     mov   [xmouse_rel],eax   ; saving relative coordinates
  130.     mov   [ymouse_rel],ebx
  131.  
  132.     mov   [mouse_pressed],1
  133.  
  134.     jmp   still
  135.  
  136.   @@:
  137.     mcall 37,2
  138.     test  eax,1
  139.     jnz   @F
  140.  
  141.     mov   [mouse_pressed],0
  142.  
  143.   @@:
  144.     mcall 37,0
  145.     mov   ecx,eax
  146.     shr   eax,16             ;   eax= abs x
  147.     and   ecx,0xffff         ;   ecx= abs y
  148.     push  eax ecx
  149.  
  150.     cmp   [icon_moved],1
  151.     je    move
  152.  
  153.     add   eax,2
  154.     cmp   eax,[xmouse_old]
  155.     jle   move
  156.     sub   eax,4
  157.     cmp   eax,[xmouse_old]
  158.     jae   move
  159.  
  160.     add   ecx,2
  161.     cmp   ecx,[ymouse_old]
  162.     jle   move
  163.     sub   ecx,4
  164.     cmp   ecx,[ymouse_old]
  165.     jae   move
  166.  
  167.     cmp   [mouse_pressed],1
  168.     je    still
  169.  
  170.     mcall 70,finfo_start
  171.     call  flip_icon
  172.     jmp   still
  173.  
  174.  move:
  175.     mov   [icon_moved],1
  176.     pop   ecx ebx
  177.     sub   ebx,[xmouse_rel]   ;   ebx=new_x
  178.     sub   ecx,[ymouse_rel]   ;   ecx=new_y
  179.     mov   [xpos],ebx
  180.     mov   [ypos],ecx
  181.  
  182.     mcall 67,,,-1,-1    ;   move
  183.  
  184.     jmp   still
  185.  
  186. fill_paths:
  187.      dec   edi
  188.      mov   ecx,30
  189.      std
  190.      mov   al,' '
  191.      repe  scasb
  192.      cld
  193.      mov   byte[edi+2],0
  194.      ret
  195.  
  196. flip_icon:
  197.  
  198.      mov   eax,1
  199.      call  flip
  200.      inc   eax
  201.      call  flip
  202.      inc   eax
  203.      call  flip
  204.      inc   eax
  205.      call  flip
  206.      inc   eax
  207.      call  flip
  208.      dec   eax
  209.      call  flip
  210.      dec   eax
  211.      call  flip
  212.      dec   eax
  213.      call  flip
  214.      dec   eax
  215.      call  flip
  216.      xor   eax,eax
  217.      call  flip
  218.  
  219.      ret
  220.  
  221. flip:
  222.      push  eax
  223.      mov   [iconstate],eax
  224.      call  get_bg
  225.      call  draw_icon
  226.      mcall 5,flipdelay
  227.      pop   eax
  228.      ret
  229.  
  230.  
  231. draw_window:
  232.  
  233.      mcall 12,1             ; function 12,1 - tell os about start of draw window
  234.  
  235.      xor   eax,eax          ; function 0 : define and draw window
  236.      mov   ebx,[xpos-2]
  237.      add   ebx,51           ; [x start] *65536 + [x size]
  238.      mov   ecx,[ypos-2]
  239.      add   ecx,67           ; [y start] *65536 + [y size]
  240.      mov   edx,0x01000000
  241.      mov   esi,0x01000000
  242.      mcall
  243.  
  244.      call  draw_icon
  245.  
  246.      mcall 12,2             ; function 12,2 - tell os about end of draw window
  247.  
  248.      ret
  249.  
  250. get_bg:
  251.  
  252.     mcall 61,1
  253.     mov  [scrxy],eax
  254.  
  255.     mcall 39,4             ; get background type
  256.     mov  [bgrdrawtype],eax
  257.  
  258.     mcall 39,1             ; get background size
  259.     mov  [bgrxy],eax
  260.  
  261.     mcall 70,finfo
  262.  
  263.     mov  [itype],0
  264.     cmp  word[I_END+256],'BM'
  265.     je  @f
  266.     inc  [itype]
  267.   @@:
  268.  
  269.     mov  ebx,51    
  270.     xor  ecx,ecx            ; 10608 = 52*68*3 - bg image
  271.     mov  esi,I_END+256+9662 ; 9662 - icon file image
  272.     mov  edi,51*3
  273.  
  274.   newb:
  275.  
  276.     push ebx ecx
  277.  
  278.   yesbpix:
  279.  
  280.     cmp   [bgrdrawtype],2
  281.     jne   nostretch
  282.  
  283.     mov   eax,[ypos]
  284.     add   eax,ecx
  285.     xor   edx,edx
  286.     movzx ebx,word [bgrxy]
  287.     mul   ebx
  288.     xor   edx,edx
  289.     movzx ebx,word [scrxy]
  290.     div   ebx
  291.     xor   edx,edx
  292.     movzx ebx,word [bgrxy+2]
  293.     mul   ebx
  294.     push  eax
  295.  
  296.     mov   eax,[xpos]
  297.     add   eax,[esp+8]
  298.     xor   edx,edx
  299.     movzx ebx,word [bgrxy+2]
  300.     mul   ebx
  301.     xor   edx,edx
  302.     movzx ebx,word [scrxy+2]
  303.     div   ebx
  304.     add   eax,[esp]
  305.     add   esp,4
  306.  
  307.   nostretch:
  308.  
  309.     cmp   [bgrdrawtype],1
  310.     jne   notiled
  311.  
  312.     mov  eax,[ypos]
  313.     add  eax,ecx
  314.     xor  edx,edx
  315.     movzx ebx,word [bgrxy]
  316.     div  ebx
  317.     mov  eax,edx
  318.     movzx  ebx,word [bgrxy+2]
  319.     xor  edx,edx
  320.     mul  ebx
  321.     push eax
  322.  
  323.     mov  eax,[xpos]
  324.     add  eax,[esp+8]
  325.     movzx ebx,word [bgrxy+2]
  326.     xor  edx,edx
  327.     div  ebx
  328.     mov  eax,edx
  329.     add  eax,[esp]
  330.     add  esp,4
  331.  
  332.   notiled:
  333.  
  334.     lea  ecx,[eax+eax*2]
  335.     mcall 39,2
  336.  
  337.   nobpix:
  338.  
  339.     pop  ecx ebx
  340.  
  341.     mov  [esi+edi+0],al
  342.     mov  [esi+edi+1],ah
  343.     shr  eax,16
  344.     mov  [esi+edi+2],al
  345.     sub  edi,3
  346.  
  347.     dec  ebx
  348.     jge  newb
  349.     mov  ebx,51
  350.  
  351.     add  esi,52*3
  352.     mov  edi,51*3
  353.     inc  ecx
  354.     cmp  ecx,68
  355.     jne  newb
  356.  
  357. ;*****************************************************************************
  358.  
  359.     mov  esi,I_END+256+9662+10608-17*52*3+3 ;! 54+32*3*33-3
  360.     mov  eax,[iconstate]
  361.     mov  eax,[add_table0+eax*4]
  362.     add  esi,eax
  363.     mov  edi,I_END+256+62
  364.     cmp  [itype],0
  365.     jne  @f
  366.     mov  edi,I_END+256+54
  367.   @@:
  368.     xor  ebp,ebp
  369.     mov  [pixl],0
  370.   newp:
  371.  
  372.     virtual at edi
  373.       r db ?
  374.       g db ?
  375.       b db ?
  376.       a db ?
  377.     end virtual
  378.     virtual at esi+ebp
  379.       ar db ?
  380.       ag db ?
  381.       ab db ?
  382.     end virtual
  383.  
  384.     movzx ecx,[a]
  385.  
  386.     push  ebp
  387.     cmp   [iconstate],3
  388.     jb   @f
  389.     neg   ebp
  390.   @@:
  391.  
  392.     cmp  [itype],0
  393.     jne  @f
  394.     mov  eax,[edi]
  395.     and  eax,$00FFFFFF
  396.     jnz  @f
  397.     jmp  no_transp
  398.   @@:
  399.  
  400.     movzx eax,[r]
  401.     cmp   [itype],0
  402.     je   @f
  403.     movzx ebx,byte[ar]
  404.     sub   eax,ebx
  405.     imul  eax,ecx
  406.     xor   edx,edx
  407.     or   ebx,$0FF
  408.     div   ebx
  409.     movzx ebx,[ar]
  410.     add   eax,ebx
  411.   @@:
  412.     mov  [esi+ebp+0],al
  413.  
  414.     movzx eax,[g]
  415.     cmp   [itype],0
  416.     je   @f
  417.     movzx ebx,[ag]
  418.     sub   eax,ebx
  419.     imul  eax,ecx
  420.     xor   edx,edx
  421.     or   ebx,$0FF
  422.     div   ebx
  423.     movzx ebx,[ag]
  424.     add   eax,ebx
  425.   @@:
  426.     mov  [esi+ebp+1],al
  427.  
  428.     movzx eax,[b]
  429.     cmp   [itype],0
  430.     je   @f
  431.     movzx ebx,[ab]
  432.     sub   eax,ebx
  433.     imul  eax,ecx
  434.     xor   edx,edx
  435.     or   ebx,$0FF
  436.     div   ebx
  437.     movzx ebx,[ab]
  438.     add   eax,ebx
  439.   @@:
  440.     mov  [esi+ebp+2],al
  441.  
  442.   no_transp:
  443.  
  444.     pop   ebp
  445.  
  446.     movzx eax,[itype]
  447.     imul  eax,6
  448.     add   eax,[iconstate]
  449.     push  eax
  450.     mov   eax,[add_table1+eax*4]
  451.     add   edi,eax
  452.  
  453.     add  ebp,3
  454.     pop  eax
  455.     mov  eax,[add_table2+eax*4]
  456.     add  [pixl],eax
  457.     cmp  [pixl],48
  458.     jl  newp
  459.     xor  ebp,ebp
  460.     mov  [pixl],0
  461.  
  462.     sub  esi,52*3
  463.     cmp  esi,I_END+256+9662+52*4*3
  464.     jge  newp
  465.  
  466. ;*****************************************************************************
  467.  
  468.     ret
  469.  
  470. draw_picture:
  471.     mcall 7,I_END+256+9662,52 shl 16+68,0
  472.     ret
  473.  
  474. draw_icon:
  475.     call draw_picture
  476.     call draw_text
  477.     ret
  478.  
  479. draw_text:
  480.  
  481.     mov   eax,labelt       ;text_length
  482.   news:
  483.     cmp   [eax],byte 40
  484.     jb   founde
  485.     inc   eax
  486.     cmp   eax,labelt+11
  487.     jb   news
  488.    founde:
  489.     sub   eax,labelt
  490.  
  491.     lea   eax,[eax+eax*2]  ; eax *= char_width/2
  492.     shl   eax,16
  493.     mov   ebx,26*65536+58
  494.     sub   ebx,eax
  495.     movzx ecx,byte [I_PARAM+8+30+30+10]
  496.     shl   ecx,16
  497.     add   ebx,ecx
  498.  
  499. ; black shade of text
  500. ; uncomment lines below if you like that style
  501.    
  502.     xor   ecx,ecx
  503.     mov   edx,labelt
  504.     mov   esi,labellen-labelt
  505.     add   ebx,1 shl 16
  506.     mcall 4
  507.     inc   ebx
  508.     mcall
  509.     add   ebx,1 shl 16
  510.     mcall
  511.     inc   ebx
  512.     mcall
  513.     sub   ebx,1 shl 16
  514.     mcall
  515.     sub   ebx,1*65536+1
  516.     mcall
  517.     sub   ebx,1*65536+1
  518.     mcall
  519.     add   ebx,1*65536-1
  520.     mcall
  521.     inc   ebx
  522.     or    ecx,0xffffff
  523.     mcall
  524.  
  525.     ;xor   ecx,ecx        
  526.     ;mov   edx,labelt
  527.     ;mov   esi,labellen-labelt
  528.     ;mcall 4
  529.     ;sub   ebx,1*65536+1
  530.     ;or    ecx,0xffffff
  531.     ;mcall
  532.  
  533.     ret
  534.  
  535.  
  536. ; DATA AREA
  537.  
  538. itype       db 0
  539.  
  540. tl          dd  2
  541.  
  542.  
  543. bgrxy       dd  0x0
  544. scrxy       dd  0x0
  545. bgrdrawtype dd  0x0
  546.  
  547. hand file 'hand.cur'
  548.  
  549. icon_moved  dd 0
  550.  
  551. iconstate   dd 0
  552.  
  553. add_table0  dd (24-6*4)*3,(24-6*2)*3,(24-6*1)*3,\
  554.                (24+6*1)*3,(24+6*2)*3,(24+6*4)*3
  555.  
  556. add_table1  dd 3,6,12,12,6,3
  557.             dd 4,8,16,16,8,4
  558.  
  559. add_table2  dd 1,2,4,4,2,1
  560.             dd 1,2,4,4,2,1
  561.  
  562. finfo_start:
  563.             dd 7
  564.             dd 0
  565.             dd 0
  566.             dd 0
  567.             dd 0
  568.             db 0
  569.             dd start_file
  570.  
  571. finfo:
  572.             dd 0
  573.             dd 0
  574.             dd 0
  575.             dd 9662
  576.             dd I_END+256
  577.             db 0
  578.             dd fname
  579.  
  580. start_file  rb  30
  581. fname       rb  30
  582.  
  583. labelt:
  584.             rb  10
  585. labellen:
  586.  
  587. pixl dd ?
  588.  
  589. xpos        dd  ?
  590. ypos        dd  ?
  591.  
  592. mouse_pressed  dd ?
  593.  
  594. xmouse_rel  dd ?
  595. ymouse_rel  dd ?
  596.  
  597. xmouse_old  dd ?
  598. ymouse_old  dd ?
  599. processes   dd ?
  600. pid         dd ?
  601.  
  602. process     process_information
  603.  
  604. ;include_debug_strings
  605.  
  606. I_PARAM:
  607.  
  608. I_END: