Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
6387 leency 1
;
2
;   application     :  Tiny ray tracer
3
;   compilator	    :  Fasm
4
;   system	    :  MenuetOS64/KolibriOS
5
;   author	    :  Maciej Guba aka macgub
6
;   email	    :  macgub3@wp.pl
7
;   web 	    :  http://macgub.hekko.pl
8
 
9
timeout equ 3
10
XRES equ 500	    ; window size
11
YRES equ 500
12
maxx = XRES
13
maxy = YRES
14
use32
15
 
16
	       org    0x0
17
 
18
	       db     'MENUET01'	      ; 8 byte id
19
	       dd     0x01		      ; header version
20
	       dd     START		      ; start of code
21
	       dd     I_END		      ; size of image
22
	       dd     I_END		      ; memory for app
23
	       dd     I_END		    ; esp
24
	       dd     0x0 , 0x0 	      ; I_Param , I_Icon
25
 
26
START:				; start of execution
27
 
28
     call draw_window
29
 
30
still:
31
 
32
    mov  eax,23 		; wait here for event
33
    mov  ebx,timeout
34
    int  0x40
35
;    mov eax,11 		  ; check for event no wait
36
;    int 0x40
37
 
38
    cmp  eax,1			; redraw request ?
39
    je	 red
40
    cmp  eax,2			; key in buffer ?
41
    je	 key
42
    cmp  eax,3			; button in buffer ?
43
    je	 button
44
 
45
    jmp  noclose
46
 
47
  red:				; redraw
48
    call draw_window
49
    jmp  still
50
 
51
  key:				; key
52
    mov  eax,2			; just read it and ignore
53
    int  0x40
54
    jmp  still
55
 
56
  button:			; button
57
    mov  eax,17 		; get id
58
    int  0x40
59
 
60
    cmp  ah,1			; button id=1 ?
61
    jne  noclose
62
 
63
    mov  eax,-1 		; close this program
64
    int  0x40
65
  noclose:
66
 
67
; mov eax,13
68
; mov ebx,20*65536+maxx-25
69
; mov ecx,20*65536+maxy-25
70
; xor edx,edx
71
; int 0x40
72
 
73
 mov edi,screen
74
 mov ecx,maxx*maxy*3/4
75
 xor eax,eax
76
 cld
77
 rep stosd
78
 
79
 add [deg_counter],1
80
 cmp [deg_counter],360
81
 jne @f
82
 mov [deg_counter],0
83
@@:
84
 fninit
85
 fld	 [one_deg]
86
 fimul	 [deg_counter]
87
 fsincos
88
 fstp	 [sin]
89
 fstp	 [cos]
90
 
91
 mov  ecx,MAX_SPHERES	;MAX_LIGHTS
92
 mov  esi,non_rot_sphere  ;light
93
 mov  edi,sphere
94
 
95
.rotary:
96
 
97
 
98
 fld  dword[esi]
99
 fsub [xo]
100
 fmul [cos]
101
 fld  dword[esi+8]
102
 fsub [zo]
103
 fmul [sin]
104
 fchs
105
 faddp
106
 fadd [xo]   ; top of stack - new 'x'
107
 fstp dword[edi]
108
 
109
 fld  dword[esi+8]
110
 fsub [zo]
111
 fmul [cos]
112
 fld  dword[esi]
113
 fsub dword[xo]
114
 fmul [sin]
115
 faddp
116
 fadd [zo]
117
 fstp dword[edi+8]
118
; fld  dword[esi+4]
119
; fstp dword[edi+4]
120
 push dword[esi+4]
121
 pop  dword[edi+4]
122
 mov  dword[edi+12],0.0
123
 
124
 add  esi,12
125
 add  edi,16
126
 sub  ecx,1
127
 jnz  .rotary
128
 
129
 mov  ecx,MAX_LIGHTS
130
 mov  esi,non_rot_light
131
 mov  edi,light
132
 
133
.rotary_lights:
134
 
135
 
136
 fld  dword[esi]
137
 fsub [xo]
138
 fmul [cos]
139
 fld  dword[esi+4]
140
 fsub [yo]
141
 fmul [sin]
142
 fchs
143
 faddp
144
 fadd [xo]   ; top of stack - new 'x'
145
 fstp dword[edi]
146
 
147
 fld  dword[esi]
148
 fsub [xo]
149
 fmul [sin]
150
 fchs
151
 fld  dword[esi+4]
152
 fsub dword[yo]
153
 fmul [cos]
154
 faddp
155
 fadd [yo]
156
 fstp dword[edi+4]
157
; fld  dword[esi+8]
158
; fstp dword[edi+8]
159
 push dword[esi+8]
160
 pop  dword[edi+8]
161
 mov  dword[edi+12],0.0
162
 
163
 add  esi,12
164
 add  edi,16
165
 sub  ecx,1
166
 jnz  .rotary_lights
167
 
168
 
169
 
170
 call main_loop
171
 
6506 leency 172
 mov eax,7
173
 mov ebx,screen
174
 mov ecx,maxx*65536+maxy
175
 xor edx,edx
176
 int 0x40
6387 leency 177
 
178
 
179
 
6506 leency 180
 
181
 
6387 leency 182
jmp still
183
 
184
 
185
 
6507 leency 186
include 'ray.inc'
6387 leency 187
 
188
;   *********************************************
189
;   *******  WINDOW DEFINITIONS AND DRAW ********
190
;   *********************************************
191
draw_window:
6506 leency 192
    mov  eax,12 		   ; function 12:tell os about windowdraw
193
    mov  ebx,1			   ; 2, end of draw
194
    int  0x40
6387 leency 195
 
6506 leency 196
    mov  eax,48            ; get skin height
197
    mov  ebx,4
198
    int  0x40
6387 leency 199
 
6506 leency 200
    lea  ecx,[eax + (100 shl 16) + maxy+4]
201
    mov  edi,title
202
    xor  eax,eax
203
    mov  ebx,100*65536+maxx+9   ; [x start] *65536 + [x size]
204
    mov  edx,0x74000000    ; window type
205
	int  0x40
6387 leency 206
 
6506 leency 207
    mov  eax,12 		   ; function 12:tell os about windowdraw
208
    mov  ebx,2			   ; 2, end of draw
209
    int  0x40
6387 leency 210
 
211
    ret
212
 
213
title db 'Ray tracing',0
214
xo dd 0.5
215
yo dd 0.5
6506 leency 216
zo dd 0.5
6387 leency 217
deg_counter dw 0
218
one_deg dd 0.017453
219
include 'dataray.inc'
220
sin dd ?
221
cos dd ?
222
screen rb XRES * YRES * 3
223
mem_stack:
224
 rb 65536
225
I_END:
226