Subversion Repositories Kolibri OS

Rev

Rev 6506 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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