Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | 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     0x1000                ; 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.     call draw_window            ; at first, draw the window
  25.  
  26. still:
  27.  
  28.     mov  eax,10                 ; wait here for event
  29.     int  0x40
  30.  
  31.     cmp  eax,1                  ; redraw request ?
  32.     je   red
  33.     cmp  eax,2                  ; key in buffer ?
  34.     je   key
  35.     cmp  eax,3                  ; button in buffer ?
  36.     je   button
  37.  
  38.     jmp  still
  39.  
  40.   red:                          ; redraw
  41.     call draw_window
  42.     jmp  still
  43.  
  44.   key:                          ; key
  45.     mov  eax,2                  ; just read it and ignore
  46.     int  0x40
  47.     jmp  still
  48.  
  49.   button:                       ; button
  50.     mov  eax,17                 ; get id
  51.     int  0x40
  52.  
  53.     cmp  ah,1                   ; button id=1 ?
  54.     jne  noclose
  55.     mov  eax,-1                 ; close this program (thread)
  56.     int  0x40
  57.   noclose:
  58.  
  59.     cmp  ah,2
  60.     jne  no_thread
  61.  
  62.     cmp  [thread_stack],0x1f00
  63.     jge  no_thread
  64.  
  65.     add  [thread_stack],0x100
  66.     mov  eax,51
  67.     mov  ebx,1
  68.     mov  ecx,START
  69.     mov  edx,[thread_stack]
  70.     int  0x40
  71.  
  72.     jmp  still
  73.  
  74.   no_thread:
  75.  
  76.     jmp  still
  77.  
  78. thread_stack dd 0x1000
  79.  
  80.  
  81. ;   *********************************************
  82. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  83. ;   *********************************************
  84.  
  85.  
  86. draw_window:
  87.  
  88.     mov  eax,12                    ; function 12:tell os about windowdraw
  89.     mov  ebx,1                     ; 1, start of draw
  90.     int  0x40
  91.  
  92.                                    ; DRAW WINDOW
  93.     mov  eax,0                     ; function 0 : define and draw window
  94.     mov  ebx,10*65536+290         ; [x start] *65536 + [x size]
  95.     mov  ecx,10*65536+130         ; [y start] *65536 + [y size]
  96.     mov  esi,[thread_stack]
  97.     sub  esi,0x1000
  98.     shr  esi,4
  99.     shl  esi,16
  100.     add  ebx,esi
  101.     add  ecx,esi
  102.     mov  edx,0x03ffffff            ; color of work area RRGGBB,8->color gl
  103.     mov  esi,0x808899ff            ; color of grab bar  RRGGBB,8->color gl
  104.     mov  edi,0x008899ff            ; color of frames    RRGGBB
  105.     int  0x40
  106.  
  107.                                    ; WINDOW LABEL
  108.     mov  eax,4                     ; function 4 : write text to window
  109.     mov  ebx,8*65536+8             ; [x start] *65536 + [y start]
  110.     mov  ecx,0x10ddeeff            ; color of text RRGGBB
  111.     mov  edx,labelt                ; pointer to text beginning
  112.     mov  esi,labellen-labelt       ; text length
  113.     int  0x40
  114.  
  115.     mov  eax,8                     ; NEW THREAD BUTTON
  116.     mov  ebx,25*65536+128
  117.     mov  ecx,88*65536+20
  118.     mov  edx,2
  119.     mov  esi,0x90b0d0 ;0x5577cc
  120.     int  0x40
  121.  
  122.     mov  ebx,25*65536+35           ; draw info text with function 4
  123.     mov  ecx,0x224466
  124.     mov  edx,text
  125.     mov  esi,40
  126.   newline:
  127.     mov  eax,4
  128.     int  0x40
  129.     add  ebx,10
  130.     add  edx,40
  131.     cmp  [edx],byte 'x'
  132.     jne  newline
  133.  
  134.  
  135.     mov  eax,12                    ; function 12:tell os about windowdraw
  136.     mov  ebx,2                     ; 2, end of draw
  137.     int  0x40
  138.  
  139.     ret
  140.  
  141.  
  142. ; DATA AREA
  143.  
  144. if lang eq ru
  145.   text:
  146.       db '’€ Žƒ€ŒŒ€ ‘Ž‡„€…’ Ž’ŽŠˆ, ‡€“‘Š€Ÿ  '
  147.       db 'Ž„ˆ ˆ ’Ž’ †… ŠŽ„ ŒŽƒŽ €‡. €Œ “†Ž  '
  148.       db '’Ž‹œŠŽ Ž‡€Ž’ˆ’œ‘Ÿ Ž Ž’„…‹œŽŒ ‘’Š…  '
  149.       db '„‹Ÿ Š€†„ŽƒŽ Ž’ŽŠ€.                     '
  150.       db '€ŒŸ’œ „‹Ÿ ‚‘…• Ž’ŽŠŽ‚ Ž™€Ÿ.          '
  151.       db '                                        '
  152.       db ' ‘Ž‡„€’œ Ž‚›‰ Ž’ŽŠ                    '
  153.  
  154.       db 'x' ; <- END MARKER, DONT DELETE
  155.  
  156.   labelt:
  157.        db   'ˆŒ… ˆ‘Ž‹œ‡Ž‚€ˆŸ 51®© ”“Š–ˆˆ'
  158.   labellen:
  159. else
  160.   text:
  161.       db 'THIS EXAMPLE CREATES THREADS BY RUNNING '
  162.       db 'THE SAME CODE MULTIPLE TIMES. ALL WE    '
  163.       db 'NEED IS A NEW STACK FOR EACH THREAD.    '
  164.       db 'ALL THREADS SHARE THE SAME MEMORY.      '
  165.       db '                                        '
  166.       db '                                        '
  167.       db '  CREATE NEW THREAD                     '
  168.  
  169.       db 'x' ; <- END MARKER, DONT DELETE
  170.  
  171.   labelt:
  172.        db   'THREAD EXAMPLE'
  173.   labellen:
  174. end if
  175. I_END:
  176.