Subversion Repositories Kolibri OS

Rev

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