Subversion Repositories Kolibri OS

Rev

Rev 3064 | Rev 4664 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3064 Rev 3527
Line 1... Line -...
1
;   à®á⮩ ¯à¨¬¥à ¯à®£à ¬¬ë ¤«ï KolibriOS
-
 
2
;   ®§¢ã稢 ¥â ª®¤ ­ ¦ â®© ª« ¢¨è¨
-
 
3
;
-
 
4
;   Š®¬¯¨«¨à®¢ âì FASM'®¬
-
 
5
;        Œ®¦­® ®âªàëâì example.asm ç¥à¥§ ¯à®£à ¬¬ã FASM (¥ñ ïà«ëª ¥áâì
-
 
6
;        ­  à ¡®ç¥¬ á⮫¥)
-
 
7
;        € ¬®¦­® ¯à®áâ® ­ ¦ âì F9 ¢ Tinypad'¥. ‹®£ ª®¬¯¨«ï樨 
-
 
8
;        ®â®¡à ¦ ¥âáï ­  ¤®áª¥ ®â« ¤ª¨ (¯à®£à ¬¬  BOARD)
-
 
9
;
-
 
10
;   —â® ¢ ¦­® §­ âì ¯à¨ ¯à®£à ¬¬¨à®¢ ­¨¨ ¯®¤ Š®«¨¡à¨:
-
 
11
;        ®¬¥à ä㭪樨 ¯®¬¥é ¥âáï ¢ ॣ¨áâà eax.
-
 
12
;        ‚맮¢ á¨á⥬­®© ä㭪樨 ®áãé¥á⢫ï¥âáï ª®¬ ­¤®© "int 0x40".
-
 
13
;        ‚ᥠॣ¨áâàë, ªà®¬¥ ® 㪠§ ­­ëå ¢ ¢®§¢à é ¥¬®¬ §­ ç¥­¨¨,
-
 
14
;        ¢ª«îç ï ॣ¨áâà ä« £®¢ eflags, á®åà ­ïîâáï.
-
 
15
;
-
 
16
;    à¨¬¥à:
-
 
17
;        mov eax, 1    ;”ã­ªæ¨ï 1 - ¯®áâ ¢¨âì â®çªã ¢ ®ª­¥
-
 
18
;                      ;ᯨ᮪ á¨áä㭪権 á¬. ¢ DOCPACK - sysfuncr.txt
-
 
19
;        mov ebx, 10   ; ª®®à¤¨­ â  x=10
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20
;        mov ecx, 20   ; ª®®à¤¨­ â  y=10
2
;                                                  ;
21
;        mov edx, 0xFFFfff ;梥â â®çª¨
3
;      EXAMPLE APPLICATION                         ;
22
;        int 0x40      ;¢ë§¢ âì äã­ªæ¨î
4
;                                                  ;
23
;
-
 
24
;    ’®¦¥ á ¬®¥ á ¨á¯®«ì§®¢ ­¨¥¬ ¬ ªà®á :
-
 
25
;        mcall 1, 10, 20, 0xFFFfff
5
;      Compile with FASM                           ;
26
;---------------------------------------------------------------------
-
 
27
 
-
 
28
  use32              ; ¢ª«îç¨âì 32-¡¨â­ë© ०¨¬  áᥬ¡«¥à 
-
 
29
  org    0x0         ;  ¤à¥á æ¨ï á ­ã«ï
6
;                                                  ;
30
 
-
 
31
  db     'MENUET01'  ; 8-¡ ©â­ë© ¨¤¥­â¨ä¨ª â®à MenuetOS
-
 
32
  dd     0x01        ; ¢¥àá¨ï § £®«®¢ª  (¢á¥£¤  1)
-
 
33
  dd     START       ;  ¤à¥á ¯¥à¢®© ª®¬ ­¤ë
-
 
34
  dd     I_END       ; à §¬¥à ¯à®£à ¬¬ë
-
 
35
  dd     0x1000      ; ª®«¨ç¥á⢮ ¯ ¬ïâ¨
-
 
36
  dd     0x1000      ;  ¤à¥á ¢¥à設ë áâíª 
-
 
37
  dd     0x0         ;  ¤à¥á ¡ãä¥à  ¤«ï ¯ à ¬¥â஢
-
 
38
  dd     0x0         ; § à¥§¥à¢¨à®¢ ­®
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39
 
-
 
40
include 'lang.inc'
-
 
41
include 'macros.inc' ; ¬ ªà®áë ®¡«¥£ç îâ ¦¨§­ì  áᥬ¡«¥à騪®¢!
-
 
42
 
-
 
43
;---------------------------------------------------------------------
-
 
44
;---  €—€‹Ž Žƒ€ŒŒ›  ----------------------------------------------
-
 
45
;---------------------------------------------------------------------
-
 
46
 
-
 
47
START:
-
 
48
 
-
 
49
red:                    ; ¯¥à¥à¨á®¢ âì ®ª­®
-
 
Line 50... Line -...
50
 
-
 
-
 
8
 
Line 51... Line -...
51
    call draw_window    ; ¢ë§ë¢ ¥¬ ¯à®æ¥¤ãàã ®âà¨á®¢ª¨ ®ª­ 
-
 
52
 
9
; The header
53
;---------------------------------------------------------------------
-
 
Line 54... Line -...
54
;---  –ˆŠ‹ Ž€Ž’Šˆ ‘Ž›’ˆ‰  ----------------------------------------
-
 
55
;---------------------------------------------------------------------
10
 
Line 56... Line -...
56
 
-
 
57
still:
-
 
58
    mcall 10            ; äã­ªæ¨ï 10 - ¦¤ âì ᮡëâ¨ï
-
 
59
 
11
use32                                   ; Tell compiler to use 32 bit instructions
-
 
12
 
-
 
13
org 0x0                                 ; the base address of code, always 0x0
-
 
14
 
60
    cmp  eax,1          ; ¯¥à¥à¨á®¢ âì ®ª­® ?
15
db 'MENUET01'
61
    je   red            ; ¥á«¨ ¤  - ­  ¬¥âªã red
16
dd 0x01
-
 
17
dd START
Line 62... Line 18...
62
    cmp  eax,2          ; ­ ¦ â  ª« ¢¨è  ?
18
dd I_END
Line -... Line 19...
-
 
19
dd 0x100000
Line 63... Line 20...
63
    je   key            ; ¥á«¨ ¤  - ­  key
20
dd 0x7fff0
-
 
21
dd 0, 0
Line -... Line 22...
-
 
22
 
-
 
23
; The code area
Line -... Line 24...
-
 
24
 
64
    cmp  eax,3          ; ­ ¦ â  ª­®¯ª  ?
25
include 'macros.inc'
65
    je   button         ; ¥á«¨ ¤  - ­  button
26
 
Line -... Line 27...
-
 
27
START:                                  ; start of execution
-
 
28
        call    draw_window             ; draw the window
66
 
29
 
Line -... Line 30...
-
 
30
; After the window is drawn, it's practical to have the main loop.
67
    jmp  still          ; ¥á«¨ ¤à㣮¥ ᮡë⨥ - ¢ ­ ç «® 横« 
31
; Events are distributed from here.
68
 
32
 
Line 69... Line 33...
69
 
33
event_wait:
70
;---------------------------------------------------------------------
34
        mov     eax, 10                 ; function 10 : wait until event
71
 
35
        mcall                           ; event type is returned in eax
72
 
-
 
Line 73... Line -...
73
  key:                  ; ­ ¦ â  ª« ¢¨è  ­  ª« ¢¨ âãà¥
-
 
74
    mcall 2             ; äã­ªæ¨ï 2 - áç¨â âì ª®¤ ᨬ¢®«  (¢ ah)
36
 
Line 75... Line 37...
75
 
37
        cmp     eax, 1                  ; Event redraw request ?
Line -... Line 38...
-
 
38
        je      red                     ; Expl.: there has been activity on screen and
-
 
39
                                        ; parts of the applications has to be redrawn.
76
    mov  [Music+1], ah  ; § ¯¨á âì ª®¤ ᨬ¢®«  ª ª ª®¤ ­®âë
40
 
Line 77... Line 41...
77
 
41
        cmp     eax, 2                  ; Event key in buffer ?
-
 
42
        je      key                     ; Expl.: User has pressed a key while the
78
    ; äã­ªæ¨ï 55-55: á¨á⥬­ë© ¤¨­ ¬¨ª ("PlayNote")
43
                                        ; app is at the top of the window stack.
-
 
44
 
Line -... Line 45...
-
 
45
        cmp     eax, 3                  ; Event button in buffer ?
79
    ;   esi -  ¤à¥á ¬¥«®¤¨¨
46
        je      button                  ; Expl.: User has pressed one of the
80
 
47
                                        ; applications buttons.
Line -... Line 48...
-
 
48
 
81
    ;   mov  eax,55
49
        jmp     event_wait
82
    ;   mov  ebx,eax
50
 
-
 
51
;  The next section reads the event and processes data.
Line -... Line 52...
-
 
52
 
-
 
53
red:                                    ; Redraw event handler
Line -... Line 54...
-
 
54
        call    draw_window             ; We call the window_draw function and
-
 
55
        jmp     event_wait              ; jump back to event_wait
-
 
56
 
83
    ;   mov  esi,Music
57
key:                                    ; Keypress event handler
84
    ;   int  0x40
58
        mov     eax, 2                  ; The key is returned in ah. The key must be
85
 
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
 
86
    ; ¨«¨ ª®à®âª®:
62
button:                                 ; Buttonpress event handler
Line 87... Line 63...
87
    mcall 55, eax, , , Music
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
Line 88... Line -...
88
 
-
 
89
    jmp  still          ; ¢¥à­ãâìáï ª ­ ç «ã 横« 
-
 
90
 
-
 
91
;---------------------------------------------------------------------
-
 
92
 
-
 
93
  button:
-
 
94
    mcall 17            ; 17 - ¯®«ãç¨âì ¨¤¥­â¨ä¨ª â®à ­ ¦ â®© ª­®¯ª¨
-
 
95
 
103
        mov     eax, 4
96
    cmp   ah, 1         ; ¥á«¨ … ­ ¦ â  ª­®¯ª  á ­®¬¥à®¬ 1,
-
 
97
    jne   still         ;  ¢¥à­ãâìáï
-
 
98
 
-
 
99
  .exit:
-
 
100
    mcall -1            ; ¨­ ç¥ ª®­¥æ ¯à®£à ¬¬ë
104
 
101
 
-
 
102
 
-
 
103
 
-
 
104
;---------------------------------------------------------------------
-
 
105
;---  Ž…„…‹…ˆ… ˆ Ž’ˆ‘Ž‚Š€ ŽŠ€  ----------------------------------
-
 
106
;---------------------------------------------------------------------
-
 
107
 
-
 
108
draw_window:
-
 
109
 
-
 
110
    mcall 12, 1                    ; äã­ªæ¨ï 12: á®®¡é¨âì Ž‘ ®¡ ®âà¨á®¢ª¥ ®ª­ 
-
 
111
                                   ; 1 - ­ ç¨­ ¥¬ à¨á®¢ âì
-
 
112
 
-
 
113
    ; ¤ «¥¥: á­ ç «  ¤«¨­­ë© ¢ à¨ ­â (§ ª®¬¬¥­â¨à®¢ ­­ë©)
-
 
114
    ;        § â¥¬ ª®à®âª¨©  ­ «®£ á ¨á¯®«ì§®¢ ­¨¥¬ ¬ ªà®á®¢
-
 
115
 
-
 
116
 
-
 
117
                                   ; ‘Ž‡„€ðŒ ŽŠŽ
105
  .newline:                             ; text from the DATA AREA
118
;   mov  eax,0                     ; äã­ªæ¨ï 0 : ®¯à¥¤¥«¨âì ¨ ®âà¨á®¢ âì ®ª­®
-
 
119
;   mov  ebx,200*65536+200         ; [x áâ àâ] *65536 + [x à §¬¥à]
106
        mcall
120
;   mov  ecx,200*65536+50          ; [y áâ àâ] *65536 + [y à §¬¥à]
-
 
121
;   mov  edx,0x33aabbcc            ; 梥â à ¡®ç¥© ®¡« á⨠ RRGGBB,8->color gl
-
 
122
;   mov  edi,header                ; ‡€ƒŽ‹Ž‚ŽŠ ŽŠ€
-
 
123
;   int  0x40
-
 
124
 
-
 
125
    mcall 0, <200,200>, <200,50>, 0x33AABBCC,,title
-
 
126
 
-
 
127
                                   
-
 
128
 
-
 
129
;   mov  eax,4
-
 
130
;   mov  ebx,3 shl 16 + 8
-
 
131
;   mov  ecx,0
-
 
132
;   mov  edx,message
-
 
133
;   mov  esi,message.size
-
 
134
;   int  0x40
-
 
135
 
-
 
136
    mcall 4, <3, 8>, 0, message, message.size
-
 
137
 
-
 
138
    mcall 12, 2                    ; äã­ªæ¨ï 12: á®®¡é¨âì Ž‘ ®¡ ®âà¨á®¢ª¥ ®ª­ 
-
 
139
                                   ; 2, § ª®­ç¨«¨ à¨á®¢ âì
-
 
140
 
-
 
141
    ret                            ; ¢ë室¨¬ ¨§ ¯à®æ¥¤ãàë
-
 
Line 142... Line -...
142
 
-
 
143
 
-
 
144
;---------------------------------------------------------------------
-
 
145
;---  „€›… Žƒ€ŒŒ›  ----------------------------------------------
107
        add     ebx, 10
Line 146... Line -...
146
;---------------------------------------------------------------------
-
 
-
 
108
        add     edx, 40
Line -... Line 109...
-
 
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   *****************
147
 
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
148
; ‚®â â ª ï ¢®â ª®à®âª ï "¬¥«®¤¨ï".
129