Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;   THREAD EXAMPLE
  3. ;
  4. ;   Compile with FASM for Menuet
  5. ;
  6.  
  7.   use32
  8.   org    0x0
  9.  
  10.   db     'MENUET01'             ; 8 byte id
  11.   dd     0x01                   ; header version
  12.   dd     START                  ; start of code
  13.   dd     I_END                  ; size of image
  14.   dd     0x2000                ; memory for app
  15.   dd     0x2000                ; esp
  16.   dd     0x0 , 0x0              ; I_Param , I_Icon
  17.  
  18. include 'lang.inc'
  19. include '..\..\..\..\macros.inc'
  20.  
  21.  
  22. START:                          ; start of execution
  23.  
  24. red:                            ; redraw
  25.     call draw_window            ; at first, draw the window
  26.  
  27. still:
  28.  
  29.     mov  eax,10                 ; wait here for event
  30.     mcall
  31.  
  32.     dec  eax                    ; redraw request ?
  33.     je   red
  34.     dec  eax                    ; key in buffer ?
  35.     jne  button
  36.  
  37.   key:                          ; key
  38.     mov  eax,2                  ; just read it and ignore
  39.     mcall
  40.     jmp  still
  41.  
  42.   button:                       ; button
  43.     mov  eax,17                 ; get id
  44.     mcall
  45.  
  46.     cmp  ah,1                   ; button id=1 ?
  47.     jne  noclose
  48.     or   eax,-1                 ; close this program (thread)
  49.     mcall
  50.   noclose:
  51.  
  52.     cmp  ah,2
  53.     jne  no_thread
  54.  
  55.     cmp  [thread_stack],0x1f00
  56.     jge  no_thread
  57.  
  58.     add  [thread_stack],0x100
  59.     mov  eax,51
  60.     mov  ebx,1
  61.     mov  ecx,START
  62.     mov  edx,[thread_stack]
  63.     mcall
  64.  
  65.     jmp  still
  66.  
  67.   no_thread:
  68.  
  69.     jmp  still
  70.  
  71.  
  72. thread_stack dd 0x1000
  73.  
  74.  
  75. ;   *********************************************
  76. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  77. ;   *********************************************
  78.  
  79.  
  80. draw_window:
  81.  
  82.     mov  eax,12                    ; function 12:tell os about windowdraw
  83.     mov  ebx,1                     ; 1, start of draw
  84.     mcall
  85.  
  86.                                    ; DRAW WINDOW
  87.     xor  eax,eax                   ; function 0 : define and draw window
  88.     mov  ebx,10*65536+290         ; [x start] *65536 + [x size]
  89.     mov  ecx,10*65536+130         ; [y start] *65536 + [y size]
  90.     mov  esi,[thread_stack]
  91.     sub  esi,0x1000
  92.     shr  esi,4
  93.     shl  esi,16
  94.     add  ebx,esi
  95.     add  ecx,esi
  96.     mov  edx,0x34ffffff            ; color of work area RRGGBB,8->color gl
  97.     mov  edi,title               ; WINDOW LABEL
  98.     mcall
  99.  
  100.                                    
  101.     mov  eax,8                     ; NEW THREAD BUTTON
  102.     mov  ebx,20*65536+128
  103.     mov  ecx,63*65536+20
  104.     mov  edx,2
  105.     mov  esi,0x90b0d0 ;0x5577cc
  106.     mcall
  107.  
  108.     mov  eax,4
  109.     mov  ebx,20*65536+10           ; draw info text with function 4
  110.     mov  ecx,0x224466
  111.     mov  edx,text
  112.     mov  esi,40
  113.   newline:
  114.     mcall
  115.     add  ebx,10
  116.     add  edx,40
  117.     cmp  [edx],byte 'x'
  118.     jne  newline
  119.  
  120.  
  121.     mov  eax,12                    ; function 12:tell os about windowdraw
  122.     mov  ebx,2                     ; 2, end of draw
  123.     mcall
  124.  
  125.     ret
  126.  
  127.  
  128. ; DATA AREA
  129.  
  130. if lang eq ru
  131.   text:
  132.       db 'â  ¯à®£à ¬¬  ᮧ¤ ¥â ¯®â®ª¨, § ¯ãáª ï  '
  133.       db '®¤¨­ ¨ â®â ¦¥ ª®¤ ¬­®£® à §.  ¬ ­ã¦­®  '
  134.       db '⮫쪮 ¯®§ ¡®â¨âìáï ®¡ ®â¤¥«ì­®¬ áâíª¥  '
  135.       db '¤«ï ª ¦¤®£® ¯®â®ª .                     '
  136.       db ' ¬ïâì ¤«ï ¢á¥å ¯®â®ª®¢ ®¡é ï.          '
  137.       db '                                        '
  138.       db ' ‘Ž‡„€’œ Ž‚›‰ Ž’ŽŠ                    '
  139.       db 'x' ; <- END MARKER, DONT DELETE
  140.  
  141.   title   db   'à¨¬¥à ¨á¯®«ì§®¢ ­¨ï ¯®â®ª®¢',0
  142.  
  143. else
  144.   text:
  145.       db 'THIS EXAMPLE CREATES THREADS BY RUNNING '
  146.       db 'THE SAME CODE MULTIPLE TIMES. ALL WE    '
  147.       db 'NEED IS A NEW STACK FOR EACH THREAD.    '
  148.       db 'ALL THREADS SHARE THE SAME MEMORY.      '
  149.       db '                                        '
  150.       db '                                        '
  151.       db '  CREATE NEW THREAD                     '
  152.       db 'x' ; <- END MARKER, DONT DELETE
  153.  
  154.   title   db   'THREAD EXAMPLE',0
  155.  
  156. end if
  157. I_END:
  158.