Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;   DESKTOP ICON MANAGER
  3. ;
  4. ;   Compile with FASM for Menuet
  5. ;
  6.  
  7. use32
  8.  
  9.                org    0x0
  10.  
  11.                db     'MENUET01'              ; 8 byte id
  12.                dd     0x01                    ; header version
  13.                dd     START                   ; start of code
  14.                dd     I_END                   ; size of image
  15.                dd     0x4000                  ; memory for app
  16.                dd     0x4000                  ; esp
  17.                dd     I_Param , 0x0           ; I_Param , I_Icon
  18.  
  19. include  '..\..\..\macros.inc'
  20. include  'lang.inc'
  21.  
  22. START:                          ; start of execution
  23.  
  24.     call load_icon_list
  25.  
  26.     call check_parameters
  27.  
  28.   red:                          ; redraw
  29.     call draw_window            ; at first, draw the window
  30.  
  31. still:
  32.  
  33.     mov  eax,10                 ; wait here for event
  34.     mcall
  35.  
  36.     dec  eax                    ; redraw request ?
  37.     jz   red
  38.     dec  eax                    ; key in buffer ?
  39.     jz   key
  40.  
  41.   button:                       ; button
  42.     mov  al,17                  ; get id
  43.     mcall
  44.  
  45.     shr  eax,8
  46.  
  47.     cmp  eax,1                  ; button id=1 ?
  48.     jne  noclose
  49.     or   eax,-1                 ; close this program
  50.     mcall
  51.   noclose:
  52.  
  53.     cmp  eax,11
  54.     jb   no_str
  55.     cmp  eax,13
  56.     jg   no_str
  57.     call read_string
  58.     jmp  still
  59.   no_str:
  60.  
  61.  
  62.     cmp  eax,21                 ; apply changes
  63.     jne  no_apply
  64.  
  65.     ; (1) save list
  66.  
  67.     mov  eax,70
  68.     mov  ebx,finfo
  69.     mov  dword[ebx],2
  70.     mov  edx,78
  71.     imul edx,dword [icons]
  72.     mov  dword[ebx+12],edx
  73.     mcall
  74.  
  75.  
  76.     ; (2) terminate all icons
  77.  
  78.     mov  esi,1
  79.   newread:
  80.     inc  esi
  81.     mov  eax,9
  82.     mov  ebx,I_END
  83.     mov  ecx,esi
  84.     mcall
  85.     cmp  esi,eax
  86.     jg   all_terminated
  87.  
  88.     cmp  [I_END+10],dword '@ICO'
  89.     jne  newread
  90.  
  91.     mov  eax,18
  92.     mov  ebx,2
  93.     mov  ecx,esi
  94.     mcall
  95.  
  96.     mov  esi,1
  97.  
  98.     jmp  newread
  99.  
  100.    all_terminated:
  101.  
  102.    apply_changes:
  103.  
  104.     ; (3)  start icons from icon_data
  105.  
  106.     mov  edi,[icons]
  107.     mov  esi,icon_data
  108.   start_new:
  109.  
  110.     push edi
  111.     push esi
  112.  
  113.     movzx eax,byte [esi]    ; x position
  114.     cmp  eax,'E'
  115.     jg   no_left
  116.     sub  eax,65
  117.     imul eax,70
  118.     add  eax,15
  119.     jmp  x_done
  120.   no_left:
  121.     sub  eax,65
  122.     mov  ebx,9
  123.     sub  ebx,eax
  124.     imul ebx,70
  125.     push ebx
  126.     mov  eax,14
  127.     mcall
  128.     pop  ebx
  129.     shr  eax,16
  130.     sub  eax,51+15
  131.     sub  eax,ebx
  132.   x_done:
  133.     add  eax,0x01010101
  134.     mov  [icon_start_parameters],eax
  135.  
  136.     movzx eax,byte [esi+1]  ; y position
  137.     cmp  eax,'E'
  138.     jg   no_up
  139.     sub  eax,65
  140.     imul eax,80
  141.     add  eax,12
  142.     jmp  y_done
  143.   no_up:
  144.     sub  eax,65
  145.     mov  ebx,9
  146.     sub  ebx,eax
  147.     imul ebx,80
  148.     push ebx
  149.     mov  eax,14
  150.     mcall
  151.     pop  ebx
  152.     and  eax,0xffff
  153.     sub  eax,-1+20
  154.     sub  eax,ebx
  155.   y_done:
  156.     add  eax,0x01010101
  157.     mov  [icon_start_parameters+4],eax
  158.  
  159.     mov  esi,[esp]          ; icon picture
  160.     add  esi,3
  161.     mov  edi,icon_start_parameters+8
  162.     mov  ecx,30
  163.     cld
  164.     rep  movsb
  165.  
  166.     mov  esi,[esp]          ; icon application
  167.     add  esi,34
  168.     mov  edi,icon_start_parameters+8+30
  169.     mov  ecx,30
  170.     cld
  171.     rep  movsb
  172.  
  173.     mov  esi,[esp]          ; icon text
  174.     add  esi,65
  175.     mov  edi,icon_start_parameters+8+30+30
  176.     mov  ecx,10
  177.     cld
  178.     rep  movsb
  179.  
  180.     mov byte[edi],0          ; ASCII -> ASCIIZ
  181.  
  182.     mov  eax,70
  183.     mov  ebx,finfo_start
  184.     mcall
  185.  
  186.     pop  esi edi
  187.  
  188.     add  esi,76+2
  189.  
  190.     dec  edi
  191.     jnz  start_new
  192.  
  193.     cmp  [I_Param],byte 0
  194.     je   still
  195.  
  196.     or   eax,-1
  197.     mcall
  198.  
  199.   no_apply:
  200.  
  201.  
  202.     cmp  eax,22                 ; user pressed the 'add icon' button
  203.     jne  no_add_icon
  204.  
  205.     mov  eax,13
  206.     mov  ebx,19*65536+260
  207.     mov  ecx,225*65536+10
  208.     mov  edx,0xffffff
  209.     mcall
  210.     mov  eax,4
  211.     mov  ebx,19*65536+225
  212.     mov  ecx,0xc0ff0000
  213.     mov  edx,add_text
  214.     mov  edi,0xffffff
  215.     mcall
  216.  
  217.     mov  eax,10
  218.     mcall
  219.     cmp  eax,3
  220.     jne  still
  221.     mov  al,17
  222.     mcall
  223.     shr  eax,8
  224.     cmp  eax,40
  225.     jb   no_f
  226.     sub  eax,40
  227.  
  228.     xor  edx,edx  ; bcd -> 10
  229.     mov  ebx,16
  230.     div  ebx
  231.     imul eax,10
  232.     add  eax,edx
  233.  
  234.     mov  ebx,eax
  235.     add  ebx,icons_reserved
  236.     cmp  [ebx],byte 'x'
  237.     je   no_f
  238.     mov  [ebx],byte 'x'
  239.  
  240.     xor  edx,edx
  241.     mov  ebx,10
  242.     div  ebx
  243.     add  eax,65
  244.     add  edx,65
  245.     mov  [icon_default+0],dl
  246.     mov  [icon_default+1],al
  247.  
  248.     inc  dword [icons]
  249.     mov  edi,[icons]
  250.     dec  edi
  251.     imul edi,76+2
  252.     add  edi,icon_data
  253.  
  254.     mov  [current_icon],edi
  255.  
  256.     mov  esi,icon_default
  257.     mov  ecx,76+2
  258.     cld
  259.     rep  movsb
  260.  
  261.   no_f:
  262.  
  263.     call draw_window
  264.  
  265.     jmp  still
  266.  
  267.   no_add_icon:
  268.  
  269.  
  270.     cmp  eax,23                     ; user pressed the remove icon button
  271.     jne  no_remove_icon
  272.  
  273.     mov  eax,13
  274.     mov  ebx,19*65536+260
  275.     mov  ecx,225*65536+10
  276.     mov  edx,0xffffff
  277.     mcall
  278.     mov  eax,4
  279.     mov  ebx,19*65536+225
  280.     mov  ecx,0xc0ff0000
  281.     mov  edx,rem_text
  282.     mov  edi,0xffffff
  283.     mcall
  284.  
  285.     mov  eax,10
  286.     mcall
  287.     cmp  eax,3
  288.     jne  no_found
  289.     mov  al,17
  290.     mcall
  291.     shr  eax,8
  292.     cmp  eax,40
  293.     jb   no_found
  294.     sub  eax,40
  295.  
  296.     xor  edx,edx
  297.     mov  ebx,16
  298.     div  ebx
  299.     imul eax,10
  300.     add  eax,edx
  301.  
  302.     mov  ebx,eax
  303.     add  ebx,icons_reserved
  304.     cmp  [ebx],byte 'x'
  305.     jne  no_found
  306.     mov  [ebx],byte ' '
  307.  
  308.     xor  edx,edx
  309.     mov  ebx,10
  310.     div  ebx
  311.     shl  eax,8
  312.     mov  al,dl
  313.  
  314.     add  eax,65*256+65
  315.  
  316.     mov  esi,icon_data
  317.     mov  edi,76+2
  318.     imul edi,[icons]
  319.     add  edi,icon_data
  320.   news:
  321.     cmp  word [esi],ax
  322.     je   foundi
  323.     add  esi,76+2
  324.     cmp  esi,edi
  325.     jb   news
  326.     jmp  no_found
  327.  
  328.   foundi:
  329.  
  330.     mov  ecx,edi
  331.     sub  ecx,esi
  332.  
  333.     mov  edi,esi
  334.     add  esi,76+2
  335.  
  336.     cld
  337.     rep  movsb
  338.  
  339.     dec  [icons]
  340.  
  341.     mov  eax,icon_data
  342.     mov  [current_icon],eax
  343.  
  344.   no_found:
  345.  
  346.     call draw_window
  347.  
  348.     jmp  still
  349.  
  350.  
  351.  
  352.   no_remove_icon:
  353.  
  354.  
  355.     cmp  eax,40                 ; user pressed button for icon position
  356.     jb   no_on_screen_button
  357.  
  358.     sub  eax,40
  359.     mov  edx,eax
  360.     shl  eax,4
  361.     and  edx,0xf
  362.     mov  dh,ah
  363.     add  edx,65*256+65
  364.  
  365.     mov  esi,icon_data
  366.     mov  ecx,[icons]
  367.     cld
  368.    findl1:
  369.     cmp  dx,[esi]
  370.     je   foundl1
  371.     add  esi,76+2
  372.     loop findl1
  373.     jmp  still
  374.  
  375.    foundl1:
  376.  
  377.     mov  [current_icon],esi
  378.  
  379.     call print_strings
  380.  
  381.     jmp  still
  382.  
  383.   no_on_screen_button:
  384.  
  385.  
  386.     jmp  still
  387.  
  388.  
  389.   key:                          ; key
  390.     mov  al,2                   ; just read it and ignore
  391.     mcall
  392.     jmp  still
  393.  
  394. current_icon dd icon_data
  395.  
  396.  
  397. print_strings:
  398.  
  399.     pusha
  400.  
  401.     mov  eax,13              ; clear text area
  402.     mov  ebx,95*65536+180
  403.     mov  ecx,253*65536+40
  404.     mov  edx,0xffffff
  405.     mcall
  406.  
  407.     mov  eax,4               ; icon text
  408.     mov  ebx,95*65536+253
  409.     mov  ecx,0x000000
  410.     mov  edx,[current_icon]
  411.     add  edx,65
  412.     mov  esi,10
  413.     mcall
  414.  
  415.     ;mov  eax,4               ; icon application
  416.     add  ebx,14
  417.     mov  edx,[current_icon]
  418.     add  edx,34
  419.     mov  esi,30
  420.     mcall
  421.  
  422.     ;mov  eax,4               ; icon file
  423.     add  ebx,14
  424.     mov  edx,[current_icon]
  425.     add  edx,3
  426.     mov  esi,30
  427.     mcall
  428.  
  429.     popa
  430.  
  431.     ret
  432.  
  433.  
  434. load_icon_list:
  435.  
  436.     ;pusha
  437.  
  438.     mov   eax,70
  439.     mov   ebx,finfo
  440.     mov   dword[ebx],0
  441.     mov   dword[ebx+12],4096   ; max size of icons.dat (in current format) is 4 kb
  442.     mcall
  443.  
  444.     mov   eax,ebx
  445.     add   eax,2
  446.     xor   edx,edx
  447.     mov   ebx,76+2
  448.     div   ebx
  449.     mov   [icons],eax
  450.  
  451.     mov   edi,icons_reserved   ; clear reserved area
  452.     mov   eax,32
  453.     mov   ecx,10*10
  454.     cld
  455.     rep   stosb
  456.  
  457.     mov   ecx,[icons]          ; set used icons to reserved area
  458.     mov   esi,icon_data
  459.     cld
  460.   ldl1:
  461.     movzx ebx,byte [esi+1]
  462.     sub   ebx,65
  463.     imul  ebx,10
  464.     movzx eax,byte [esi]
  465.     add   ebx,eax
  466.     sub   ebx,65
  467.     add   ebx,icons_reserved
  468.     mov   [ebx],byte 'x'
  469.     add   esi,76+2
  470.     loop  ldl1
  471.  
  472.     ret
  473.  
  474.  
  475. check_parameters:
  476.  
  477.     cmp   [I_Param],dword 'BOOT'
  478.     je    chpl1
  479.     ret
  480.  
  481.    chpl1:
  482.     mov   eax,21
  483.     jmp   apply_changes
  484.  
  485.  
  486. positions dd 65,34,3
  487.  
  488. read_string:
  489.  
  490.     sub  eax,11
  491.     shl  eax,2
  492.     add  eax,positions
  493.     mov  eax,[eax]
  494.  
  495.     mov  esi,[current_icon]
  496.     add  esi,eax
  497.     mov  [addr],esi
  498.  
  499.     mov  edi,[addr]
  500.     mov  eax,'_'
  501.     mov  ecx,30
  502.     cld
  503.     rep  stosb
  504.  
  505.     call print_strings
  506.  
  507.     mov  edi,[addr]
  508.   f11:
  509.     mov  eax,10
  510.     mcall
  511.     cmp  eax,2
  512.     jz   fbu
  513.     jmp  rs_done
  514.   fbu:
  515.     mov  eax,2
  516.     mcall
  517.     shr  eax,8
  518.     cmp  eax,13
  519.     je   rs_done
  520.     cmp  eax,8
  521.     jnz  nobsl
  522.     cmp  edi,[addr]
  523.     jz   f11
  524.     dec  edi
  525.     mov  [edi],byte ' '
  526.     call print_strings
  527.     jmp  f11
  528.   nobsl:
  529.     cmp  eax,31
  530.     jbe  f11
  531.     mov  [edi],al
  532.     call print_strings
  533.  
  534.     add  edi,1
  535.     mov  esi,[addr]
  536.     add  esi,30
  537.     cmp  esi,edi
  538.     jnz  f11
  539.  
  540.    rs_done:
  541.  
  542.     mov  ecx,[addr]
  543.     add  ecx,30
  544.     sub  ecx,edi
  545.     mov  eax,32
  546.     cld
  547.     rep  stosb
  548.  
  549.     call print_strings
  550.  
  551.     ret
  552.  
  553.  
  554.  
  555. ;   *********************************************
  556. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  557. ;   *********************************************
  558.  
  559.  
  560. draw_window:
  561.  
  562.     mov  eax,12                    ; function 12:tell os about windowdraw
  563.     mov  ebx,1                     ; 1, start of draw
  564.     mcall
  565.  
  566.                                    ; DRAW WINDOW
  567.     xor  eax,eax
  568.     mov  ebx,210*65536+300
  569.     mov  ecx,30*65536+390
  570.     mov  edx,0x33ffffff
  571.     mov  edi,title
  572.     mcall
  573.  
  574.     mov  eax,13                    ; WINDOW AREA
  575.     mov  ebx,15*65536+260
  576.     mov  ecx,10*65536+200
  577.     mov  edx,0x3366cc
  578.     mcall
  579.  
  580.     mov  eax,38                    ; VERTICAL LINE ON WINDOW AREA
  581.     mov  ebx,145*65536+145
  582.     mov  ecx,10*65536+235
  583.     mov  edx,0xffffff
  584.     mcall
  585.  
  586.     ;mov  eax,38                    ; HOROZONTAL LINE ON WINDOW AREA
  587.     mov  ebx,15*65536+280
  588.     mov  ecx,110*65536+110
  589.     mov  edx,0xffffff
  590.     mcall
  591.  
  592.     mov  eax,8                     ; TEXT ENTER BUTTONS
  593.     mov  ebx,15*65536+72
  594.     mov  ecx,250*65536+13
  595.     mov  edx,11
  596.     mov  esi,[bcolor]
  597.     mcall
  598.     inc  edx
  599.     add  ecx,14*65536
  600.     mcall
  601.     inc  edx
  602.     add  ecx,14*65536
  603.     mcall
  604.  
  605.     ;mov  eax,8                     ; APPLY AND SAVE CHANGES BUTTON
  606.     mov  ebx,15*65536+259
  607.     mov  ecx,304*65536+15
  608.     mov  edx,21
  609.     mov  esi,[bcolor]
  610.     mcall
  611.  
  612.     ;mov  eax,8                     ; ADD ICON BUTTON
  613.     mov  ebx,15*65536+129
  614.     add  ecx,14*2*65536
  615.     inc  edx
  616.     mcall
  617.  
  618.     ;mov  eax,8                     ; REMOVE ICON BUTTON
  619.     add  ebx,130*65536
  620.     inc  edx
  621.     mcall
  622.  
  623.     xor  eax,eax                    ; DRAW BUTTONS ON WINDOW AREA
  624.     mov  ebx,15*65536+25
  625.     mov  ecx,10*65536+19
  626.     mov  edi,icon_table
  627.     mov  edx,40
  628.    newbline:
  629.  
  630.     cmp  [edi],byte 'x'
  631.     jne  no_button
  632.  
  633.     mov  esi,0x5577cc
  634.     cmp  [edi+100],byte 'x'
  635.     jne  nores
  636.     mov  esi,0xcc5555
  637.   nores:
  638.  
  639.     push eax
  640.     mov  eax,8
  641.     mcall
  642.     pop  eax
  643.  
  644.   no_button:
  645.  
  646.     add  ebx,26*65536
  647.  
  648.     inc  edi
  649.     inc  edx
  650.  
  651.     inc  al
  652.     cmp  al,9
  653.     jbe  newbline
  654.     mov  al,0
  655.  
  656.     add  edx,6
  657.  
  658.     ror  ebx,16
  659.     mov  bx,15
  660.     ror  ebx,16
  661.     add  ecx,20*65536
  662.  
  663.     inc  ah
  664.     cmp  ah,9
  665.     jbe  newbline
  666.  
  667.     mov  ebx,24*65536+225
  668.     mov  ecx,0xffffff
  669.     mov  edx,text
  670.     mov  esi,36
  671.     mov  eax,4
  672.   newline:
  673.     mov  ecx,[edx]
  674.     add  edx,4
  675.     mcall
  676.     add  ebx,14
  677.     add  edx,36
  678.     cmp  [edx],byte 'x'
  679.     jne  newline
  680.  
  681.     call print_strings
  682.  
  683.     mov  eax,12                    ; function 12:tell os about windowdraw
  684.     mov  ebx,2                     ; 2, end of draw
  685.     mcall
  686.  
  687.     ret
  688.  
  689.  
  690. ; DATA AREA
  691.  
  692. bcolor dd 0x335599
  693.  
  694. icon_table:
  695.  
  696.     times 4  db  'xxxx  xxxx'
  697.     times 2  db  '          '
  698.     times 3  db  'xxxx  xxxx'
  699.     times 1  db  '          '
  700.  
  701. icons_reserved:
  702.  
  703.     times 10  db  '          '
  704.  
  705.  
  706. text:
  707.     db 0,0,0,0,         'Click on icon position to edit      '
  708.     db 0,0,0,0,         '                                    '
  709.     db 255,255,255,0  , 'Icon text                           '
  710.     db 255,255,255,0  , 'Icon app                            '
  711.     db 255,255,255,0  , 'Icon file                           '
  712.     db 0,0,0,0,         '                                    '
  713.     db 255,255,255,0,   '       Save and apply all changes   '
  714.     db 0,0,0,0,         '                                    '
  715.     db 255,255,255,0,   '     Add icon            Remove icon'
  716.     db                  'x' ; <- End marker, dont delete
  717.  
  718.  
  719. title    db 'Icon manager',0
  720.  
  721. icons dd 0
  722.  
  723. addr  dd 0
  724. ya    dd 0
  725.  
  726. add_text    db 'Press button of unused icon position',0
  727.  
  728. rem_text    db 'Press button of used icon           ',0
  729.  
  730. finfo_start:
  731.           dd 7
  732.           dd 0
  733.           dd icon_start_parameters
  734.           dd 0
  735.           dd 0
  736.           db 0
  737.           dd icon_path
  738.  
  739. icon_path db '/rd/1/@ICON',0
  740.  
  741. finfo:
  742.           dd 0
  743.           dd 0
  744.           dd 0
  745.           dd 0
  746.           dd icon_data
  747.           db 0
  748.           dd icon_list
  749.  
  750. icon_list db '/rd/1/icons.dat',0
  751.  
  752. icon_start_parameters:
  753.       db   25,1,1,1
  754.       db   35,1,1,1
  755.       db   '/rd/1/icons/fs.ico',0
  756.       rb   12
  757.       db   '/rd/1/kfar',0
  758.       rb   20
  759.       db   'KFAR      '
  760.  
  761. icon_default:
  762.       db   'AA-/rd/1/icons/fs.ico            -/rd/1/kfar                    -KFAR      *',13,10
  763.  
  764. icon_data:   ; data length 76+2
  765.  
  766. rb 4096
  767.  
  768. I_Param:
  769.  
  770. I_END:
  771.