Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;                                                  ;
  3. ;      EXAMPLE APPLICATION                         ;
  4. ;                                                  ;
  5. ;      Compile with FASM                           ;
  6. ;                                                  ;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9. ; The header
  10.  
  11. use32                                   ; Tell compiler to use 32 bit instructions
  12.  
  13. org 0x0                                 ; the base address of code, always 0x0
  14.  
  15. db 'MENUET01'
  16. dd 0x01
  17. dd START
  18. dd I_END
  19. dd 0x100000
  20. dd 0x7fff0
  21. dd 0, 0
  22.  
  23. ; The code area
  24.  
  25. include 'macros.inc'
  26.  
  27. START:                                  ; start of execution
  28.         call    draw_window             ; draw the window
  29.  
  30. ; After the window is drawn, it's practical to have the main loop.
  31. ; Events are distributed from here.
  32.  
  33. event_wait:
  34.         mov     eax, 10                 ; function 10 : wait until event
  35.         mcall                           ; event type is returned in eax
  36.  
  37.         cmp     eax, 1                  ; Event redraw request ?
  38.         je      red                     ; Expl.: there has been activity on screen and
  39.                                         ; parts of the applications has to be redrawn.
  40.  
  41.         cmp     eax, 2                  ; Event key in buffer ?
  42.         je      key                     ; Expl.: User has pressed a key while the
  43.                                         ; app is at the top of the window stack.
  44.  
  45.         cmp     eax, 3                  ; Event button in buffer ?
  46.         je      button                  ; Expl.: User has pressed one of the
  47.                                         ; applications buttons.
  48.  
  49.         jmp     event_wait
  50.  
  51. ;  The next section reads the event and processes data.
  52.  
  53. red:                                    ; Redraw event handler
  54.         call    draw_window             ; We call the window_draw function and
  55.         jmp     event_wait              ; jump back to event_wait
  56.  
  57. key:                                    ; Keypress event handler
  58.         mov     eax, 2                  ; The key is returned in ah. The key must be
  59.         mcall                           ; read and cleared from the system queue.
  60.         jmp     event_wait              ; Just read the key, ignore it and jump to event_wait.
  61.  
  62. button:                                 ; Buttonpress event handler
  63.         mov     eax,17                  ; The button number defined in window_draw
  64.         mcall                           ; is returned to ah.
  65.  
  66.         cmp     ah,1                    ; button id=1 ?
  67.         jne     noclose
  68.         mov     eax,-1                  ; Function -1 : close this program
  69.         mcall
  70.  
  71. noclose:
  72.         jmp     event_wait              ; This is for ignored events, useful at development
  73.  
  74. ;  *********************************************
  75. ;  ******  WINDOW DEFINITIONS AND DRAW  ********
  76. ;  *********************************************
  77. ;
  78. ;  The static window parts are drawn in this function. The window canvas can
  79. ;  be accessed later from any parts of this code (thread) for displaying
  80. ;  processes or recorded data, for example.
  81. ;
  82. ;  The static parts *must* be placed within the fn 12 , ebx = 1 and ebx = 2.
  83.  
  84. draw_window:
  85.         mov     eax, 12                 ; function 12: tell os about windowdraw
  86.         mov     ebx, 1                  ; 1, start of draw
  87.         mcall
  88.  
  89.         mov     eax, 0                  ; function 0 : define and draw window
  90.         mov     ebx, 100 * 65536 + 300  ; [x start] *65536 + [x size]
  91.         mov     ecx, 100 * 65536 + 120  ; [y start] *65536 + [y size]
  92.         mov     edx, 0x14ffffff         ; color of work area RRGGBB
  93.                                         ; 0x02000000 = window type 4 (fixed size, skinned window)
  94.         mov     esi, 0x808899ff         ; color of grab bar  RRGGBB
  95.                                         ; 0x80000000 = color glide
  96.         mov     edi, title
  97.         mcall
  98.  
  99.         mov     ebx, 25 * 65536 + 35    ; draw info text with function 4
  100.         mov     ecx, 0x224466
  101.         mov     edx, text
  102.         mov     esi, 40
  103.         mov     eax, 4
  104.  
  105.   .newline:                             ; text from the DATA AREA
  106.         mcall
  107.         add     ebx, 10
  108.         add     edx, 40
  109.         cmp     byte[edx], 0
  110.         jne     .newline
  111.  
  112.         mov     eax, 12                 ; function 12:tell os about windowdraw
  113.         mov     ebx, 2                  ; 2, end of draw
  114.         mcall
  115.  
  116.         ret
  117.  
  118. ;  *********************************************
  119. ;  *************   DATA AREA   *****************
  120. ;  *********************************************
  121. ;
  122. ; Data can be freely mixed with code to any parts of the image.
  123. ; Only the header information is required at the beginning of the image.
  124.  
  125. text    db  "It look's like you have just compiled   "
  126.         db  "your first program for KolibriOS.       "
  127.         db  "                                        "
  128.         db  "Congratulations!                        ", 0
  129.  
  130. title   db  "Example application", 0
  131.  
  132. I_END:
  133.  
  134. ; The area after I_END is free for use as the application memory,
  135. ; just avoid the stack.
  136. ;
  137. ; Application memory structure, according to the used header, 1 Mb.
  138. ;
  139. ; 0x00000   - Start of compiled image
  140. ; I_END     - End of compiled image          
  141. ;
  142. ;           + Free for use in the application
  143. ;
  144. ; 0x7ff00   - Start of stack area
  145. ; 0x7fff0   - End of stack area                 - defined in the header
  146. ;
  147. ;           + Free for use in the application
  148. ;
  149. ; 0xFFFFF   - End of freely useable memory      - defined in the header
  150. ;
  151. ; All of the the areas can be modified within the application with a
  152. ; direct reference.
  153. ; For example, mov [0x80000],byte 1 moves a byte above the stack area.