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