Subversion Repositories Kolibri OS

Rev

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. ;    22.02.05 Mario79
  7. ;      1) multi-threading
  8. ;      2)dinamic load BMP files
  9. ;      3)type on desktop with function 7
  10. ;      4)Image in memory only 8000h (32Kb) for all 48 icons.
  11. ;        Old version ICON 5000h*48(decimal)=960Kb.
  12. ;
  13.  
  14. use32
  15.  
  16.   org    0x0
  17.  
  18.   db     'MENUET01'
  19.   dd     0x01
  20.   dd     START
  21.   dd     I_END
  22.   dd     0x8000
  23.   dd     0x8000
  24.   dd     I_Param , 0x0
  25.  
  26. include 'lang.inc'
  27. include 'macros.inc'
  28.  
  29. get_bg_info:
  30.     mov  eax,39
  31.     mov  ebx,4
  32.     int  0x40
  33.     mov  [bgrdrawtype],eax
  34.  
  35.     mov  eax,39     ; get background size
  36.     mov  ebx,1
  37.     int  0x40
  38.     mov  [bgrxy],eax
  39.  
  40.     mov  ebx,eax
  41.     shr  eax,16
  42.     and  ebx,0xffff
  43.     mov  [bgrx],eax
  44.     mov  [bgry],ebx
  45.     ret
  46.  
  47. START:
  48. load_icon_list:
  49.     mov   eax,6
  50.     mov   ebx,icon_lst
  51.     xor   ecx,ecx
  52.     mov   edx,-1
  53.     mov   esi,icon_data
  54.     int   0x40
  55.  
  56.     add   eax,10
  57.     xor   edx,edx
  58.     mov   ebx,52
  59.     div   ebx
  60.     mov   [icons],eax
  61.  
  62.     call  get_bg_info
  63.  
  64.     mov  eax,14
  65.     int  0x40
  66.     add  eax,0x00010001
  67.     mov  [scrxy],eax
  68.  
  69. apply_changes:
  70.  
  71.     mov  edi,[icons]
  72.     mov  esi,icon_data
  73.     mov  ebp,0x5000 ; threads stack starting point
  74.  
  75.   start_new:
  76.     movzx eax,byte [esi]    ; x position
  77.     sub  eax,'A'            ;eax - number of letter
  78.     cmp  eax,4
  79.     jg   no_left
  80.     shl  eax,6 ;imul eax,64
  81.     add  eax,24
  82.     jmp  x_done
  83.   no_left:
  84.     sub  eax,9
  85.     shl  eax,6 ;imul eax,64
  86.     sub  eax,24+32-1
  87.     movzx ebx,word [scrxy+2]
  88.     add  eax,ebx
  89.   x_done:
  90. ;    mov  [xpos],eax
  91.     mov  [ebp-12],eax
  92.  
  93.     movzx eax,byte [esi+1]  ; y position
  94.     sub  eax,'A'            ; eax - number of letter
  95.     cmp  eax,4
  96.     jg   no_up
  97.     lea  eax,[eax+4*eax]
  98.     shl  eax,4              ;imul eax,80
  99.     add  eax,34
  100.     jmp  y_done
  101.   no_up:
  102.     sub  eax,9
  103.     lea  eax,[eax+4*eax]
  104.     shl  eax,4              ;imul eax,80
  105.     movzx ebx,word [scrxy]
  106.     sub  eax,32-1
  107.     add  eax,ebx
  108.   y_done:
  109. ;    mov  [ypos],eax
  110.     mov  [ebp-8],eax
  111.  
  112.     mov  eax,51
  113.     mov  ebx,1
  114.     mov  ecx,thread
  115. ;    mov  edx,[thread_stack]
  116.     mov  edx,ebp
  117. ;    sub  edx,4
  118. ;    mov  [edx],esi
  119.     mov  [ebp-4],esi
  120.     int  0x40
  121. ;    add  [thread_stack],0x100
  122.     add  ebp,0x100
  123.  
  124.     mov  eax,5
  125.     mov  ebx,1
  126. wait_thread_start:               ;wait until thread draw itself first time
  127.     cmp  [create_thread_event],bl
  128.     jz   wait_thread_end
  129.     int  0x40
  130.     jmp  wait_thread_start
  131. wait_thread_end:
  132.     dec  [create_thread_event]   ;reset event
  133.  
  134.  
  135.     add  esi,50+2
  136.     dec  edi
  137.     jnz  start_new
  138.     or   eax,-1
  139.     int  0x40
  140.  
  141. thread:
  142. ;   pop  ebp ;ebp - address of our icon
  143.     sub  esp,12
  144.     mov  ebp,esp
  145.     call draw_window
  146.     mov  [create_thread_event],1
  147.     mov  eax,40
  148.     mov  ebx,010101b
  149.     int  0x40
  150.     jmp  still
  151. red:
  152.     call draw_window
  153.  
  154. still:
  155.  
  156.     mov  eax,10
  157.     int  0x40
  158.  
  159.     cmp  eax,1
  160.     je   red
  161.     cmp  eax,3
  162.     je   button
  163.     cmp  eax,5
  164.     jne  still
  165.  
  166.     call  get_bg_info
  167.     mov   eax,5
  168.     mov   ebx,1
  169.     call  draw_icon
  170.  
  171.     jmp  still
  172.  
  173.   key:
  174.     mov  eax,2
  175.     int  0x40
  176.  
  177.     jmp  still
  178.  
  179.   button:
  180.     mov  eax,17
  181.     int  0x40
  182.  
  183. ;    mcall 55,eax, , ,klick_music
  184.  
  185.     mov  ebx,[ebp+8]
  186.     add  ebx,19
  187. ;    lea  ebx,[ebp+19]
  188.     mov  eax,19
  189.     xor  ecx,ecx
  190.     int  0x40
  191.     mcall 55,eax, , ,klick_music
  192.     jmp  still
  193.  
  194. klick_music db 0x85,0x60,0x85,0x70,0x85,0x65,0
  195.  
  196. draw_picture:
  197.     mov  [image],0x3000
  198.     xor  ebx,ebx
  199.     xor  ecx,ecx
  200.     mov  esi,data_from_file+54+32*3*33-96
  201.     mov  [pixpos],0
  202.     mov  [pixpos2],32
  203.   newb:
  204.     push ebx
  205.     push ecx
  206.  
  207.     cmp  ebx,10
  208.     jb   yesbpix
  209.     cmp  ebx,42
  210.     jge  yesbpix
  211.     cmp  ecx,32
  212.     jg   yesbpix
  213.  
  214.     push esi
  215.     mov  esi,data_from_file+54+32*3*33-96
  216.     sub  esi,[pixpos]
  217.  
  218.     dec  [pixpos2]
  219.     cmp  [pixpos2],0
  220.     jne  no_correction_pixpos
  221.     add  [pixpos],192
  222.     mov  [pixpos2],32
  223. no_correction_pixpos:
  224.     sub  [pixpos],3
  225.     mov  eax,[esi]
  226.     and  eax,0xffffff
  227.  
  228.     pop  esi
  229.  
  230.     cmp eax,0
  231.     je  yesbpix
  232.     cmp eax,0xf5f5f5
  233.     je  yesbpix
  234.     jmp nobpix
  235.  
  236.   yesbpix:
  237.  
  238.   stretch:
  239.     cmp   [bgrdrawtype],dword 2
  240.     jne   nostretch
  241. ;    mov   eax,[ypos]
  242.     mov   eax,[ebp+4]
  243.     add   eax,ecx
  244.     imul  eax,[bgry]
  245.     cdq
  246.     movzx ebx,word [scrxy]
  247.     div   ebx
  248.     imul  eax,[bgrx]
  249.     push  eax
  250. ;    mov   eax,[xpos]
  251.     mov   eax,[ebp+0]
  252.     add   eax,[esp+8]
  253.     imul  eax,[bgrx]
  254.     cdq
  255.     movzx ebx,word [scrxy+2]
  256.     div   ebx
  257.     add   eax,[esp]
  258.     add   esp,4
  259.  
  260.     jmp   notiled
  261.  
  262.   nostretch:
  263.  
  264.     cmp   [bgrdrawtype],dword 1
  265.     jne   notiled
  266. ;    mov   eax,[ypos]
  267.     mov   eax,[ebp+4]
  268.     add   eax,ecx
  269.     cdq
  270.     movzx ebx,word [bgrxy]
  271.     div   ebx
  272.     mov   eax,edx
  273.     imul  eax,[bgrx]
  274.     push  eax
  275. ;    mov   eax,[xpos]
  276.     mov   eax,[ebp+0]
  277.     add   eax,[esp+8]
  278.     movzx ebx,word [bgrxy+2]
  279.     cdq
  280.     div   ebx
  281.     mov   eax,edx
  282.     add   eax,[esp]
  283.     add   esp,4
  284.  
  285.   notiled:
  286.  
  287.     lea  ecx,[eax+eax*2]
  288.     mov  eax,39
  289.     mov  ebx,2
  290.     int  0x40
  291.  
  292.   nobpix:
  293.  
  294.     pop  ecx
  295.     pop  ebx
  296.  
  297.     mov  edx,eax
  298.     mov  eax,[image]
  299.     mov  [eax],dl
  300.     inc  eax
  301.     ror  edx,8
  302.     mov  [eax],dl
  303.     inc  eax
  304.     ror  edx,8
  305.     mov  [eax],dl
  306.     inc  eax
  307.     mov  [image],eax
  308.  
  309.     inc  ebx
  310.     mov  eax,[yw]
  311.     inc  eax
  312.     cmp  ebx,eax
  313.     jnz  newb
  314.     xor  ebx,ebx
  315.  
  316.     inc  ecx
  317.  
  318.     mov  eax,[ya]
  319.     add  [pixpos],eax
  320.  
  321.     cmp  [top],1
  322.     jne  notop
  323.     cmp  ecx,38
  324.     je   toponly
  325.  
  326.   notop:
  327.  
  328.     cmp  ecx,52
  329.     jnz  newb
  330.  
  331.   toponly:
  332.  
  333.     mov  eax,7
  334.     mov  ebx,0x3000
  335.     mov  ecx,52 shl 16 + 52
  336.     xor  edx,edx
  337.     int  0x40
  338.     mov  [load_pic],0
  339.     ret
  340.  
  341. draw_text:
  342.  
  343.     mov  esi,[ebp+8]
  344.     add  esi,33
  345. ;    lea  esi,[ebp+33]
  346.     push edi
  347.     mov  edi,labelt
  348.     mov  ecx,8
  349.     cld
  350.     rep  movsb
  351.     pop  edi
  352.     mov   eax,labelt
  353.   news:
  354.     cmp   [eax],byte 33
  355.     jb    founde
  356.     inc   eax
  357.     cmp   eax,labelt+11
  358.     jb    news
  359.    founde:
  360.     sub   eax,labelt
  361.     mov   [tl],eax
  362.  
  363.     mov   eax,[tl]
  364.     lea   eax,[eax+eax*2]  ; eax *= char_width/2
  365.     shl   eax,16
  366.  
  367.     mov   ebx,27*65536+42
  368.     sub   ebx,eax
  369.  
  370.     mov   eax,4
  371.     xor   ecx,ecx                ; black shade of text
  372.     mov   edx,labelt
  373.     mov   esi,[tl]
  374.     add   ebx,1 shl 16    ;*65536+1
  375.     int   0x40
  376.     inc   ebx
  377.     int   0x40
  378.     add   ebx,1 shl 16
  379.     int   0x40
  380.     inc   ebx
  381.     int   0x40
  382.     sub   ebx,1 shl 16
  383.     int   0x40
  384.     dec   ebx
  385.     sub   ebx,1 shl 16
  386.     int   0x40
  387.     sub   ebx,1 shl 16
  388.     dec   ebx
  389.     int   0x40
  390.     dec   ebx
  391.     add   ebx,1 shl 16
  392.     int   0x40
  393.     inc   ebx
  394.     mov   ecx,0xffffff
  395.  
  396.     int   0x40
  397.     mov   [draw_pic],0
  398.     ret
  399.  
  400. load_icon_file:
  401.     mov  ebx,[ebp+8]
  402.     add  ebx,5
  403. ;    lea  ebx,[ebp+5]
  404.  
  405.     mov  eax,6
  406.     xor  ecx,ecx
  407.     mov  edx,-1
  408.     mov  esi,data_from_file
  409.     int  0x40
  410.  
  411.     ret
  412.  
  413.     ; for y = 32 to 0
  414.     ;   for x = 0 to 32
  415.     ;     if (pix[y][x]==0) then
  416.     ;        pix[y][x]=background(x,y);
  417.  
  418. ;   *********************************************
  419. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  420. ;   *********************************************
  421.  
  422.  
  423. draw_window:
  424.  
  425.     mov  eax,12                    ; function 12:tell os about windowdraw
  426.     mov  ebx,1                     ; 1, start of draw
  427.     int  0x40
  428.  
  429.                                    ; DRAW WINDOW
  430.     xor  eax,eax                     ; function 0 : define and draw window
  431. ;    mov  ebx,[xpos-2]
  432.     mov  ebx,[ebp+0-2]
  433. ;    mov  ecx,[ypos-2]
  434.     mov  ecx,[ebp+4-2]
  435.     add  ebx,[yw]                  ; [x start] *65536 + [x size]
  436.     add  ecx,51                    ; [y start] *65536 + [y size]
  437.     mov  edx,0x01000000            ; color of work area RRGGBB,8->color gl
  438.     int  0x40
  439.  
  440.     mov  eax,8    ; button
  441.     mov  ebx,51
  442.     mov  ecx,50
  443.     mov  edx,1+20000000 ; or 0x40000000
  444.     int  0x40
  445.  
  446.     mov  eax,5
  447.     mov  ebx,1
  448. draw_icon:
  449.     xchg [load_pic],bl
  450.     test bl,bl
  451.     je   draw_icon_end
  452.     int  0x40
  453.     jmp  draw_icon
  454. draw_icon_end:
  455.  
  456.     call load_icon_file
  457.  
  458.     mov  eax,5
  459.     mov  ebx,1
  460. draw_icon_2:
  461.     xchg [draw_pic],bl
  462.     test bl,bl
  463.     je   draw_icon_end_2
  464.     int  0x40
  465.     jmp  draw_icon_2
  466. draw_icon_end_2:
  467.  
  468.     mov  eax,9
  469.     mov  ebx,process_table
  470.     mov  ecx,-1
  471.     int  0x40
  472. ;    mov  eax,process_table
  473. ;    add  eax,34
  474. ;    mov  ebx,[eax]
  475. ;    mov  [xpos],ebx
  476. ;    add  eax,4
  477. ;    mov  ebx,[eax]
  478. ;    mov  [ypos],ebx
  479.  
  480.     call draw_picture
  481.     call draw_text
  482.  
  483.     mov  eax,12
  484.     mov  ebx,2
  485.     int  0x40
  486.  
  487.     ret
  488.  
  489.  
  490.  
  491. icon_lst db 'ICON    LST'
  492.  
  493. tl          dd    8
  494. yw          dd   51
  495. ya          dd    0
  496.  
  497. ;xpos       dd   15
  498. ;ypos       dd  185
  499. draw_pic    db    0
  500. load_pic    db    0
  501. create_thread_event db 0
  502.  
  503. labelt:
  504.             db  'SETUP      '
  505. labellen:
  506.  
  507. bgrxy       dd  0x0
  508. scrxy       dd  0x0
  509. bgrdrawtype dd  0x0
  510.  
  511. pixpos      dd  0
  512. pixpos2     db  0
  513.  
  514. top       dd 0
  515.  
  516. image         dd  0x3000
  517. ;thread_stack  dd  0x5000
  518.  
  519. icons dd 0
  520.  
  521.  
  522. I_Param:
  523.  
  524.  icon_data = I_END+0x1400
  525.  process_table = I_END+0x2400
  526.  
  527. I_END:
  528.  
  529. bgrx dd ?
  530. bgry dd ?
  531. data_from_file:
  532.   rb 54 ;header
  533.  raw_data:
  534.   rb 32*32
  535.