Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2269 | leency | 1 | ; |
2 | ; application : WAVED 3D FORM SIN(SQRT(x*x+y*y)) |
||
3 | ; author : macgub |
||
4 | ; email : macgub3@wp.pl |
||
5 | ; system : MenuetOS |
||
6 | ; compiler : fasm |
||
7 | ; |
||
8 | ; |
||
9 | TIMEOUT EQU 2 |
||
10 | use32 |
||
11 | |||
12 | org 0x0 |
||
13 | |||
14 | db 'MENUET01' ; 8 byte id |
||
15 | dd 0x01 ; header version |
||
16 | dd START ; start of code |
||
17 | dd I_END ; size of image |
||
18 | dd 0x100000 ; memory for app |
||
19 | dd 0x7fff0 ; esp |
||
20 | dd 0x0 , 0x0 ; I_Param , I_Icon |
||
21 | |||
22 | START: ; start of execution |
||
23 | |||
24 | call draw_window |
||
25 | |||
26 | still: |
||
27 | |||
28 | mov eax,23 ; wait here for event |
||
29 | mov ebx,TIMEOUT |
||
30 | int 0x40 |
||
31 | |||
32 | cmp eax,1 ; redraw request ? |
||
33 | je red |
||
34 | cmp eax,2 ; key in buffer ? |
||
35 | je key |
||
36 | cmp eax,3 ; button in buffer ? |
||
37 | je button |
||
38 | |||
39 | jmp noclose |
||
40 | |||
41 | red: ; redraw |
||
42 | call draw_window |
||
43 | jmp still |
||
44 | |||
45 | key: ; key |
||
46 | mov eax,2 ; just read it and ignore |
||
47 | int 0x40 |
||
48 | jmp still |
||
49 | |||
50 | button: ; button |
||
51 | mov eax,17 ; get id |
||
52 | int 0x40 |
||
53 | |||
54 | cmp ah,1 ; button id=1 ? |
||
55 | jne noclose |
||
56 | |||
57 | mov eax,-1 ; close this program |
||
58 | int 0x40 |
||
59 | noclose: |
||
60 | |||
61 | call calc_deg |
||
62 | |||
63 | ; mov eax,13 ;clear screen |
||
64 | ; mov ebx,5*65536 + 517 |
||
65 | ; mov ecx,20*65536 + 345 |
||
66 | ; xor edx,edx |
||
67 | ; int 0x40 |
||
68 | |||
69 | mov edi,the_mem ;clear buffer |
||
70 | mov ecx,512*384*3/4 |
||
71 | xor eax,eax |
||
72 | cld |
||
73 | rep stosd |
||
74 | |||
75 | mov eax,1 ;main loop |
||
76 | oop: |
||
77 | mov ebx,1 |
||
78 | oop1: |
||
79 | push eax |
||
80 | push ebx |
||
81 | mov [x],eax |
||
82 | mov [z],ebx |
||
83 | call fun |
||
84 | add [y],260 |
||
85 | add [x],40 |
||
86 | call rotateY |
||
87 | call put3dpixel |
||
88 | pop ebx |
||
89 | pop eax |
||
90 | add ebx,4 |
||
91 | cmp ebx,201 |
||
92 | jne oop1 |
||
93 | inc eax |
||
94 | cmp eax,300 |
||
95 | jne oop |
||
96 | |||
97 | mov eax,7 ;put image |
||
98 | mov ebx,the_mem |
||
99 | mov ecx,512*65536+384 |
||
100 | mov edx,0 |
||
101 | int 0x40 |
||
102 | |||
103 | jmp still |
||
104 | ;-------------------PROCEDURES------------------------------- |
||
105 | calc_deg: |
||
106 | cmp [deg_counter], 360 |
||
107 | jne go_deg |
||
108 | mov [deg_counter],0 |
||
109 | go_deg: |
||
110 | fldpi |
||
111 | fidiv [deg_div] |
||
112 | fimul [deg_counter] |
||
113 | fst [current_deg] |
||
114 | fsincos |
||
115 | fstp [cosbeta] |
||
116 | fstp [sinbeta] |
||
117 | inc [deg_counter] |
||
118 | ret |
||
119 | ;----------------- |
||
120 | rotateY: |
||
121 | mov eax,[z] |
||
122 | sub eax,[zo] |
||
123 | mov [subz],eax |
||
124 | mov eax,[x] |
||
125 | sub eax,[xo] |
||
126 | mov [subx],eax |
||
127 | |||
128 | fld [sinbeta] |
||
129 | fimul [subz] |
||
130 | fchs |
||
131 | fld [cosbeta] |
||
132 | fimul[subx] |
||
133 | faddp |
||
134 | fiadd [xo] |
||
135 | fistp [x] |
||
136 | |||
137 | fld [sinbeta] |
||
138 | fimul [subx] |
||
139 | fld [cosbeta] |
||
140 | fimul [subz] |
||
141 | faddp |
||
142 | fiadd [zo] |
||
143 | fistp [z] |
||
144 | ret |
||
145 | ;----------------------------- |
||
146 | fun: |
||
147 | finit |
||
148 | fild [x] |
||
149 | fisub [i150] |
||
150 | fidiv [xdiv] |
||
151 | fmul st,st0 |
||
152 | fld st0 |
||
153 | fild [z] |
||
154 | fisub [i100] |
||
155 | fidiv [zdiv] |
||
156 | fmul st,st0 |
||
157 | faddp |
||
158 | fsqrt |
||
159 | |||
160 | fld [current_deg] |
||
161 | fimul [cur_deg_mul] |
||
162 | faddp |
||
163 | fsin |
||
164 | fimul [ymul] |
||
165 | fistp [y] |
||
166 | ret |
||
167 | ;-------------------------- |
||
168 | put3dpixel: |
||
169 | fild [z] |
||
170 | fmul [sq] |
||
171 | fchs |
||
172 | fiadd [y] |
||
173 | fistp [y] |
||
174 | fild [z] |
||
175 | fmul [sq] |
||
176 | fiadd [x] |
||
177 | fistp [x] |
||
178 | ;mov eax,1 |
||
179 | ;mov ebx,[x] |
||
180 | ;mov ecx,[y] |
||
181 | ;mov edx,[col] |
||
182 | ;int 0x40 |
||
183 | mov eax,[y] ; calculating pixel position in buffer |
||
184 | dec eax |
||
185 | shl eax,9 |
||
186 | add eax,[x] |
||
187 | mov ebx,eax |
||
188 | shl eax,1 |
||
189 | add eax,ebx |
||
190 | add eax,the_mem |
||
191 | mov ebx,[col] |
||
192 | or [eax],ebx |
||
193 | ret |
||
194 | |||
195 | ; ********************************************* |
||
196 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
||
197 | ; ********************************************* |
||
198 | |||
199 | |||
200 | draw_window: |
||
201 | |||
202 | |||
203 | mov eax,12 ; function 12:tell os about windowdraw |
||
204 | mov ebx,1 ; 1, start of draw |
||
205 | int 0x40 |
||
206 | |||
207 | mov eax,48 |
||
208 | mov ebx,4 |
||
209 | int 0x40 |
||
210 | mov esi, eax |
||
211 | ; DRAW WINDOW |
||
212 | mov eax,0 ; function 0 : define and draw window |
||
213 | mov ebx,100*65536+512+9 ; [x start] *65536 + [x size] |
||
214 | mov ecx,100*65536+384+4 ; [y start] *65536 + [y size] |
||
215 | add ecx, esi |
||
216 | mov edx,0x74000000 ; color of work area RRGGBB,8->color gl |
||
217 | mov edi,labelt |
||
218 | int 0x40 |
||
219 | |||
220 | mov eax,12 ; function 12:tell os about windowdraw |
||
221 | mov ebx,2 ; 2, end of draw |
||
222 | int 0x40 |
||
223 | |||
224 | ret |
||
225 | |||
226 | ; DATA AREA |
||
227 | deg_div dd 90 |
||
228 | deg_counter dd ? |
||
229 | col dd 0x00ffffff |
||
230 | sq dd 0.707 ;sin pi/4 |
||
231 | cosbeta dd ? |
||
232 | sinbeta dd ? |
||
233 | x dd ? |
||
234 | y dd ? |
||
235 | z dd ? |
||
236 | xo dd 200 ;axle variables |
||
237 | ;yo dd 110 |
||
238 | zo dd 80 |
||
239 | xdiv dd 20 |
||
240 | zdiv dd 20 |
||
241 | ymul dd 20 |
||
242 | subx dd ? |
||
243 | ;suby dd ? |
||
244 | subz dd ? |
||
245 | current_deg dd ? ;real |
||
246 | cur_deg_mul dd 12 |
||
247 | i100 dd 100 |
||
248 | i150 dd 150 |
||
249 | labelt: |
||
250 | db 'Waved 3d form',0 |
||
251 | the_mem: |
||
252 | I_END: |
||
253 |