Subversion Repositories Kolibri OS

Rev

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,0xff0000
  213.     mov  edx,add_text
  214.     mov  esi,add_text_len-add_text
  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,0xff0000
  281.     mov  edx,rem_text
  282.     mov  esi,rem_text_len-rem_text
  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.     ;popa
  473.  
  474.     ret
  475.  
  476.  
  477. check_parameters:
  478.  
  479.     cmp   [I_Param],dword 'BOOT'
  480.     je    chpl1
  481.     ret
  482.  
  483.    chpl1:
  484.     mov   eax,21
  485.     jmp   apply_changes
  486.  
  487.  
  488. positions dd 65,34,3
  489.  
  490. read_string:
  491.  
  492.     ;pusha
  493.  
  494.     sub  eax,11
  495.     shl  eax,2
  496.     add  eax,positions
  497.     mov  eax,[eax]
  498.  
  499.     mov  esi,[current_icon]
  500.     add  esi,eax
  501.     mov  [addr],esi
  502.  
  503.     mov  edi,[addr]
  504.     mov  eax,'_'
  505.     mov  ecx,30
  506.     cld
  507.     rep  stosb
  508.  
  509.     call print_strings
  510.  
  511.     mov  edi,[addr]
  512.   f11:
  513.     mov  eax,10
  514.     mcall
  515.     cmp  eax,2
  516.     jz   fbu
  517.     jmp  rs_done
  518.   fbu:
  519.     mov  eax,2
  520.     mcall
  521.     shr  eax,8
  522.     cmp  eax,13
  523.     je   rs_done
  524.     cmp  eax,8
  525.     jnz  nobsl
  526.     cmp  edi,[addr]
  527.     jz   f11
  528.     dec  edi
  529.     mov  [edi],byte ' '
  530.     call print_strings
  531.     jmp  f11
  532.   nobsl:
  533.     cmp  eax,31
  534.     jbe  f11
  535.  
  536.   keyok:
  537.     mov  [edi],al
  538.     call print_strings
  539.  
  540.     add  edi,1
  541.     mov  esi,[addr]
  542.     add  esi,30
  543.     cmp  esi,edi
  544.     jnz  f11
  545.  
  546.    rs_done:
  547.  
  548.     mov  ecx,[addr]
  549.     add  ecx,30
  550.     sub  ecx,edi
  551.     mov  eax,32
  552.     cld
  553.     rep  stosb
  554.  
  555.     call print_strings
  556.  
  557.     ;popa
  558.  
  559.     ret
  560.  
  561.  
  562.  
  563. ;   *********************************************
  564. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  565. ;   *********************************************
  566.  
  567.  
  568. draw_window:
  569.  
  570.     mov  eax,12                    ; function 12:tell os about windowdraw
  571.     mov  ebx,1                     ; 1, start of draw
  572.     mcall
  573.  
  574.                                    ; DRAW WINDOW
  575.     xor  eax,eax
  576.     mov  ebx,210*65536+300
  577.     mov  ecx,30*65536+390
  578.     mov  edx,0x33ffffff
  579.     mov  edi,title
  580.     mcall
  581.  
  582.     mov  eax,13                    ; WINDOW AREA
  583.     mov  ebx,15*65536+260
  584.     mov  ecx,10*65536+200
  585.     mov  edx,0x3366cc
  586.     mcall
  587.  
  588.     mov  eax,38                    ; VERTICAL LINE ON WINDOW AREA
  589.     mov  ebx,145*65536+145
  590.     mov  ecx,10*65536+235
  591.     mov  edx,0xffffff
  592.     mcall
  593.  
  594.     ;mov  eax,38                    ; HOROZONTAL LINE ON WINDOW AREA
  595.     mov  ebx,15*65536+280
  596.     mov  ecx,110*65536+110
  597.     mov  edx,0xffffff
  598.     mcall
  599.  
  600.     mov  eax,8                     ; TEXT ENTER BUTTONS
  601.     mov  ebx,15*65536+72
  602.     mov  ecx,250*65536+13
  603.     mov  edx,11
  604.     mov  esi,[bcolor]
  605.     mcall
  606.     inc  edx
  607.     add  ecx,14*65536
  608.     mcall
  609.     inc  edx
  610.     add  ecx,14*65536
  611.     mcall
  612.  
  613.     ;mov  eax,8                     ; APPLY AND SAVE CHANGES BUTTON
  614.     mov  ebx,15*65536+259
  615.     mov  ecx,304*65536+15
  616.     mov  edx,21
  617.     mov  esi,[bcolor]
  618.     mcall
  619.  
  620.     ;mov  eax,8                     ; ADD ICON BUTTON
  621.     mov  ebx,15*65536+129
  622.     add  ecx,14*2*65536
  623.     inc  edx
  624.     mcall
  625.  
  626.     ;mov  eax,8                     ; REMOVE ICON BUTTON
  627.     add  ebx,130*65536
  628.     inc  edx
  629.     mcall
  630.  
  631.     xor  eax,eax                    ; DRAW BUTTONS ON WINDOW AREA
  632.     mov  ebx,15*65536+25
  633.     mov  ecx,10*65536+19
  634.     mov  edi,icon_table
  635.     mov  edx,40
  636.    newbline:
  637.  
  638.     cmp  [edi],byte 'x'
  639.     jne  no_button
  640.  
  641.     mov  esi,0x5577cc
  642.     cmp  [edi+100],byte 'x'
  643.     jne  nores
  644.     mov  esi,0xcc5555
  645.   nores:
  646.  
  647.     push eax
  648.     mov  eax,8
  649.     mcall
  650.     pop  eax
  651.  
  652.   no_button:
  653.  
  654.     add  ebx,26*65536
  655.  
  656.     inc  edi
  657.     inc  edx
  658.  
  659.     inc  al
  660.     cmp  al,9
  661.     jbe  newbline
  662.     mov  al,0
  663.  
  664.     add  edx,6
  665.  
  666.     ror  ebx,16
  667.     mov  bx,15
  668.     ror  ebx,16
  669.     add  ecx,20*65536
  670.  
  671.     inc  ah
  672.     cmp  ah,9
  673.     jbe  newbline
  674.  
  675.     mov  ebx,19*65536+225
  676.     mov  ecx,0xffffff
  677.     mov  edx,text
  678.     mov  esi,37
  679.     mov  eax,4
  680.   newline:
  681.     mov  ecx,[edx]
  682.     add  edx,4
  683.     mcall
  684.     add  ebx,14
  685.     add  edx,37
  686.     cmp  [edx],byte 'x'
  687.     jne  newline
  688.  
  689.     call print_strings
  690.  
  691.     mov  eax,12                    ; function 12:tell os about windowdraw
  692.     mov  ebx,2                     ; 2, end of draw
  693.     mcall
  694.  
  695.     ret
  696.  
  697.  
  698. ; DATA AREA
  699.  
  700. bcolor dd 0x335599
  701.  
  702. icon_table:
  703.  
  704.     times 4  db  'xxxx  xxxx'
  705.     times 2  db  '          '
  706.     times 3  db  'xxxx  xxxx'
  707.     times 1  db  '          '
  708.  
  709. icons_reserved:
  710.  
  711.     times 10  db  '          '
  712.  
  713.  
  714. text:
  715.     db 0,0,0,0,         'CLICK ON ICON POSITION TO EDIT       '
  716.     db 0,0,0,0,         '                                     '
  717.     db 255,255,255,0  , ' ICON TEXT                           '
  718.     db 255,255,255,0  , ' ICON APP                            '
  719.     db 255,255,255,0  , ' ICON FILE                           '
  720.     db 0,0,0,0,         '                                     '
  721.     db 255,255,255,0,   '        SAVE AND APPLY ALL CHANGES   '
  722.     db 0,0,0,0,         '                                     '
  723.     db 255,255,255,0,   '      ADD ICON            REMOVE ICON'
  724.     db                  'x' ; <- END MARKER, DONT DELETE
  725.  
  726.  
  727. title    db 'Icon manager',0
  728.  
  729. icons dd 0
  730.  
  731. addr  dd 0
  732. ya    dd 0
  733.  
  734. add_text db 'PRESS BUTTON OF UNUSED ICON POSITION'
  735. add_text_len:
  736.  
  737. rem_text db 'PRESS BUTTON OF USED ICON'
  738. rem_text_len:
  739.  
  740. finfo_start:
  741.           dd 7
  742.           dd 0
  743.           dd icon_start_parameters
  744.           dd 0
  745.           dd 0
  746.           db 0
  747.           dd icon_path
  748.  
  749. icon_path db '/rd/1/@ICON',0
  750.  
  751. finfo:
  752.           dd 0
  753.           dd 0
  754.           dd 0
  755.           dd 0
  756.           dd icon_data
  757.           db 0
  758.           dd icon_list
  759.  
  760. icon_list db '/rd/1/icons.dat',0
  761.  
  762. icon_start_parameters:
  763.       db   25,1,1,1
  764.       db   35,1,1,1
  765.       db   '/rd/1/icons/fs.ico',0
  766.       rb   12
  767.       db   '/rd/1/kfar',0
  768.       rb   20
  769.       db   'KFAR      '
  770.  
  771. icon_default:
  772.       db   'AA-/rd/1/icons/fs.ico            -/rd/1/kfar                    -KFAR      *',13,10
  773.  
  774. icon_data:   ; data length 76+2
  775.  
  776. rb 4096
  777.  
  778. I_Param:
  779.  
  780. I_END:
  781.