Subversion Repositories Kolibri OS

Rev

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

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