Subversion Repositories Kolibri OS

Rev

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

Rev 2493 Rev 2551
1
;
1
;
2
;   Fisheye Raycasting Engine Etc. FREE3D for MENUETOS by Dieter Marfurt
2
;   Fisheye Raycasting Engine Etc. FREE3D for MENUETOS by Dieter Marfurt
3
;   Version 0.4 (requires some texture-files to compile (see Data Section))
3
;   Version 0.4 (requires some texture-files to compile (see Data Section))
4
;   dietermarfurt@angelfire.com - www.melog.ch/mos_pub/
4
;   dietermarfurt@angelfire.com - www.melog.ch/mos_pub/
5
;   Don't hit me - I'm an ASM-Newbie... since years :)
5
;   Don't hit me - I'm an ASM-Newbie... since years :)
6
;
6
;
7
;   Compile with FASM for Menuet (requires .INC files - see DATA Section)
7
;   Compile with FASM for Menuet (requires .INC files - see DATA Section)
8
;
8
;
9
;   Willow - greatly srinked code size by using GIF texture and FPU to calculate sine table
9
;   Willow - greatly srinked code size by using GIF texture and FPU to calculate sine table
10
;
10
;
11
;   !!!! Don't use GIF_LITE.INC in your apps - it's modified for FREE3D !!!!
11
;   !!!! Don't use GIF_LITE.INC in your apps - it's modified for FREE3D !!!!
12
;
12
;
13
;   Heavyiron - new 0-function of drawing window from kolibri (do not work correctly with menuet)
13
;   Heavyiron - new 0-function of drawing window from kolibri (do not work correctly with menuet)
14
 
14
 
15
 
15
 
16
TEX_SIZE equ 64*64*4
16
TEX_SIZE equ 64*64*4
17
ceil = sinus+16*1024
17
ceil = sinus+16*1024
18
wall = ceil+TEX_SIZE*1
18
wall = ceil+TEX_SIZE*1
19
wall2 = ceil+TEX_SIZE*2
19
wall2 = ceil+TEX_SIZE*2
20
wall3 = ceil+TEX_SIZE*3
20
wall3 = ceil+TEX_SIZE*3
21
wall4 = ceil+TEX_SIZE*4
21
wall4 = ceil+TEX_SIZE*4
22
wall5 = ceil+TEX_SIZE*5
22
wall5 = ceil+TEX_SIZE*5
23
wall6 = ceil+TEX_SIZE*6
23
wall6 = ceil+TEX_SIZE*6
24
wall7 = ceil+TEX_SIZE*7
24
wall7 = ceil+TEX_SIZE*7
25
APP_MEM equ 0x200000
25
APP_MEM equ 0x200000
26
 
26
 
27
use32
27
use32
28
 
28
 
29
               org    0x0
29
               org    0x0
30
 
30
 
31
               db     'MENUET01'              ; 8 byte id
31
               db     'MENUET01'              ; 8 byte id
32
               dd     0x01                    ; header version
32
               dd     0x01                    ; header version
33
               dd     START                   ; start of code
33
               dd     START                   ; start of code
34
               dd     I_END                   ; size of image
34
               dd     I_END                   ; size of image
35
               dd     APP_MEM;0x100000        ; memory for app
35
               dd     APP_MEM;0x100000        ; memory for app
36
               dd     APP_MEM;0x100000        ; esp
36
               dd     APP_MEM;0x100000        ; esp
37
               dd     0x0 , 0x0               ; I_Param , I_Icon
37
               dd     0x0 , 0x0               ; I_Param , I_Icon
38
include 'lang.inc'
38
include 'lang.inc'
39
include '..\..\..\macros.inc'
39
include '..\..\..\macros.inc'
40
COLOR_ORDER equ OTHER
40
COLOR_ORDER equ OTHER
41
include 'gif_lite.inc'
41
include 'gif_lite.inc'
42
 
42
 
43
START:                          ; start of execution
43
START:                          ; start of execution
44
		mov  esi,textures
44
		mov  esi,textures
45
		mov  edi,ceil-8
45
		mov  edi,ceil-8
46
		call ReadGIF
46
		call ReadGIF
47
		mov  esi,sinus
47
		mov  esi,sinus
48
		mov  ecx,360*10
48
		mov  ecx,360*10
49
		fninit
49
		fninit
50
		fld  [sindegree]
50
		fld  [sindegree]
51
	.sinlp:
51
	.sinlp:
52
		fst  st1
52
		fst  st1
53
		fsin
53
		fsin
54
		fmul [sindiv]
54
		fmul [sindiv]
55
		fistp dword[esi]
55
		fistp dword[esi]
56
		add  esi,4
56
		add  esi,4
57
		fadd [sininc]
57
		fadd [sininc]
58
		loop .sinlp
58
		loop .sinlp
59
    call draw_window            ; at first, draw the window
59
    call draw_window            ; at first, draw the window
60
    call draw_stuff
60
    call draw_stuff
61
 
61
 
62
gamestart:
62
gamestart:
63
;   ******* MOUSE CHECK *******
63
;   ******* MOUSE CHECK *******
64
;    mov eax,37    ; check mouse (use mouse over window to navigate)
64
;    mov eax,37    ; check mouse (use mouse over window to navigate)
65
;    mov ebx,2     ; check mousebuttons
65
;    mov ebx,2     ; check mousebuttons
66
;    mcall
66
;    mcall
67
;    cmp eax,0    ; only use mouse when button down
67
;    cmp eax,0    ; only use mouse when button down
68
;    je noneed    ; deactivated cause of disappear-bug etc.
68
;    je noneed    ; deactivated cause of disappear-bug etc.
69
    mov eax,37
69
    mov eax,37
70
    mov ebx,1     ; check mouseposition
70
    mov ebx,1     ; check mouseposition
71
    mcall
71
    mcall
72
 
72
 
73
    mov ebx,eax
73
    mov ebx,eax
74
    shr eax,16
74
    shr eax,16
75
    and eax,0x0000FFFF  ; mousex
75
    and eax,0x0000FFFF  ; mousex
76
    and ebx,0x0000FFFF  ; mousey
76
    and ebx,0x0000FFFF  ; mousey
77
 
77
 
78
    cmp eax,5  ; mouse out of window ?
78
    cmp eax,5  ; mouse out of window ?
79
    jb check_refresh  ; it will prevent an app-crash
79
    jb check_refresh  ; it will prevent an app-crash
80
    cmp ebx,22
80
    cmp ebx,22
81
    jb check_refresh
81
    jb check_refresh
82
    cmp eax, 640
82
    cmp eax, 640
83
    jg check_refresh
83
    jg check_refresh
84
    cmp ebx,501
84
    cmp ebx,501
85
    jg check_refresh
85
    jg check_refresh
86
 
86
 
87
    cmp eax,315 ; navigating?
87
    cmp eax,315 ; navigating?
88
    jb m_left
88
    jb m_left
89
    cmp eax,325 ;
89
    cmp eax,325 ;
90
    jg m_right
90
    jg m_right
91
continue:
91
continue:
92
    cmp ebx,220 ;
92
    cmp ebx,220 ;
93
    jb s_up
93
    jb s_up
94
    cmp ebx,260 ;
94
    cmp ebx,260 ;
95
    jg s_down
95
    jg s_down
96
;   ******* END OF MOUSE CHECK *******
96
;   ******* END OF MOUSE CHECK *******
97
check_refresh:
97
check_refresh:
98
 
98
 
99
;    mov eax,23  ; wait for system event with 10 ms timeout
99
;    mov eax,23  ; wait for system event with 10 ms timeout
100
;    mov ebx,1   ; thats max 100 FPS
100
;    mov ebx,1   ; thats max 100 FPS
101
    mov eax,11 ; ask no wait for full speed
101
    mov eax,11 ; ask no wait for full speed
102
    mcall
102
    mcall
103
 
103
 
104
    cmp  eax,1                  ; window redraw request ?
104
    cmp  eax,1                  ; window redraw request ?
105
    je   red2
105
    je   red2
106
    cmp  eax,2                  ; key in buffer ?
106
    cmp  eax,2                  ; key in buffer ?
107
    je   key2
107
    je   key2
108
    cmp  eax,3                  ; button in buffer ?
108
    cmp  eax,3                  ; button in buffer ?
109
    je   button2
109
    je   button2
110
 
110
 
111
    mov edi,[mouseya] ; check flag if a refresh has to be done
111
    mov edi,[mouseya] ; check flag if a refresh has to be done
112
    cmp edi,1
112
    cmp edi,1
113
    jne gamestart
113
    jne gamestart
114
    mov [mouseya],dword 0
114
    mov [mouseya],dword 0
115
    call draw_stuff
115
    call draw_stuff
116
 
116
 
117
 
117
 
118
    jmp gamestart
118
    jmp gamestart
119
 
119
 
120
; END OF MAINLOOP
120
; END OF MAINLOOP
121
 
121
 
122
red2:                          ; redraw
122
red2:                          ; redraw
123
    call draw_window
123
    call draw_window
124
    call draw_stuff
124
    call draw_stuff
125
    jmp  gamestart
125
    jmp  gamestart
126
 
126
 
127
key2:                          ; key
127
key2:                          ; key
128
    mov  eax,2
128
    mov  eax,2
129
    mcall
129
    mcall
130
    cmp  al,1
130
    cmp  al,1
131
    je   gamestart     ; keybuffer empty
131
    je   gamestart     ; keybuffer empty
132
 
132
 
133
    cmp ah,27    ; esc=End App
133
    cmp ah,27    ; esc=End App
134
    je finish
134
    je finish
135
 
135
 
136
    cmp  ah,178  ; up
136
    cmp  ah,178  ; up
137
    je   s_up
137
    je   s_up
138
    cmp  ah,177  ; down
138
    cmp  ah,177  ; down
139
    je   s_down
139
    je   s_down
140
    cmp  ah,176  ; left
140
    cmp  ah,176  ; left
141
    je   s_left
141
    je   s_left
142
    cmp  ah,179  ; right
142
    cmp  ah,179  ; right
143
    je   s_right
143
    je   s_right
144
 
144
 
145
    jmp gamestart ; was any other key
145
    jmp gamestart ; was any other key
146
 
146
 
147
 
147
 
148
s_up:             ; walk forward (key or mouse)
148
s_up:             ; walk forward (key or mouse)
149
    mov eax,[vpx]
149
    mov eax,[vpx]
150
    mov ebx,[vpy]
150
    mov ebx,[vpy]
151
 
151
 
152
 
152
 
153
    mov ecx,[vheading]
153
    mov ecx,[vheading]
154
    mov edi,[sinus+ecx*4]
154
    mov edi,[sinus+ecx*4]
155
 
155
 
156
    mov edx,[vheading]
156
    mov edx,[vheading]
157
;    imul edx,4
157
;    imul edx,4
158
;    add edx,sinus
158
;    add edx,sinus
159
;    add edx,3600
159
;    add edx,3600
160
    lea edx, [sinus+3600+edx*4]
160
    lea edx, [sinus+3600+edx*4]
161
    cmp edx,eosinus ;cosinus taken from (sinus plus 900) mod 3600
161
    cmp edx,eosinus ;cosinus taken from (sinus plus 900) mod 3600
162
    jb ok200
162
    jb ok200
163
    sub edx,14400
163
    sub edx,14400
164
    ok200:
164
    ok200:
165
    mov esi,[edx]
165
    mov esi,[edx]
166
;    sal esi,1  ; edit walking speed here
166
;    sal esi,1  ; edit walking speed here
167
;    sal edi,1
167
;    sal edi,1
168
 
168
 
169
    add eax,edi ; newPx
169
    add eax,edi ; newPx
170
    add ebx,esi ; newPy
170
    add ebx,esi ; newPy
171
    mov edi,eax ; newPx / ffff
171
    mov edi,eax ; newPx / ffff
172
    mov esi,ebx ; newPy / ffff
172
    mov esi,ebx ; newPy / ffff
173
    sar edi,16
173
    sar edi,16
174
    sar esi,16
174
    sar esi,16
175
    mov ecx,esi
175
    mov ecx,esi
176
    sal ecx,5 ; equal *32
176
    sal ecx,5 ; equal *32
177
;    add ecx,edi
177
;    add ecx,edi
178
;    add ecx,grid
178
;    add ecx,grid
179
    lea ecx, [grid+ecx+edi]
179
    lea ecx, [grid+ecx+edi]
180
    cmp [ecx],byte 0  ; collision check
180
    cmp [ecx],byte 0  ; collision check
181
    jne cannotwalk0
181
    jne cannotwalk0
182
    mov [vpx],eax
182
    mov [vpx],eax
183
    mov [vpy],ebx
183
    mov [vpy],ebx
184
    mov [mouseya],dword 1 ; set refresh flag
184
    mov [mouseya],dword 1 ; set refresh flag
185
cannotwalk0:
185
cannotwalk0:
186
    jmp check_refresh
186
    jmp check_refresh
187
 
187
 
188
s_down:                    ; walk backward
188
s_down:                    ; walk backward
189
    mov eax,[vpx]
189
    mov eax,[vpx]
190
    mov ebx,[vpy]
190
    mov ebx,[vpy]
191
 
191
 
192
    mov ecx,[vheading]
192
    mov ecx,[vheading]
193
    mov edi,[sinus+ecx*4]
193
    mov edi,[sinus+ecx*4]
194
 
194
 
195
    mov edx,[vheading]
195
    mov edx,[vheading]
196
;    imul edx,4
196
;    imul edx,4
197
;    add edx,sinus
197
;    add edx,sinus
198
;    add edx,3600
198
;    add edx,3600
199
    lea edx, [sinus+3600+edx*4]
199
    lea edx, [sinus+3600+edx*4]
200
    cmp edx,eosinus ;cosinus taken from (sinus plus 900) mod 3600
200
    cmp edx,eosinus ;cosinus taken from (sinus plus 900) mod 3600
201
    jb ok201
201
    jb ok201
202
    sub edx,14400
202
    sub edx,14400
203
    ok201:
203
    ok201:
204
 
204
 
205
    mov esi,[edx]
205
    mov esi,[edx]
206
;    sal esi,1  ; edit walking speed here
206
;    sal esi,1  ; edit walking speed here
207
;    sal edi,1
207
;    sal edi,1
208
 
208
 
209
    sub eax,edi ; newPx
209
    sub eax,edi ; newPx
210
    sub ebx,esi ; newPy
210
    sub ebx,esi ; newPy
211
    mov edi,eax ; newPx / ffff
211
    mov edi,eax ; newPx / ffff
212
    mov esi,ebx ; newPy / ffff
212
    mov esi,ebx ; newPy / ffff
213
    sar edi,16
213
    sar edi,16
214
    sar esi,16
214
    sar esi,16
215
    mov ecx,esi
215
    mov ecx,esi
216
    sal ecx,5
216
    sal ecx,5
217
;    add ecx,edi
217
;    add ecx,edi
218
;    add ecx,grid
218
;    add ecx,grid
219
    lea ecx, [grid+ecx+edi]
219
    lea ecx, [grid+ecx+edi]
220
    cmp [ecx],byte 0
220
    cmp [ecx],byte 0
221
    jne cannotwalk1
221
    jne cannotwalk1
222
    mov [vpx],eax
222
    mov [vpx],eax
223
    mov [vpy],ebx
223
    mov [vpy],ebx
224
    mov [mouseya],dword 1
224
    mov [mouseya],dword 1
225
cannotwalk1:
225
cannotwalk1:
226
    jmp check_refresh
226
    jmp check_refresh
227
 
227
 
228
s_left:                                   ; turn left (key)
228
s_left:                                   ; turn left (key)
229
    mov edi,[vheading]  ; heading
229
    mov edi,[vheading]  ; heading
230
    add edi,50
230
    add edi,50
231
    cmp edi,3600
231
    cmp edi,3600
232
    jb ok_heading0
232
    jb ok_heading0
233
    sub edi,3600
233
    sub edi,3600
234
    ok_heading0:
234
    ok_heading0:
235
    mov [vheading],edi
235
    mov [vheading],edi
236
    mov [mouseya],dword 1
236
    mov [mouseya],dword 1
237
    jmp check_refresh
237
    jmp check_refresh
238
 
238
 
239
s_right:                                  ; turn right
239
s_right:                                  ; turn right
240
    mov edi,[vheading]
240
    mov edi,[vheading]
241
    sub edi,50
241
    sub edi,50
242
    cmp edi,-1
242
    cmp edi,-1
243
    jg ok_heading1
243
    jg ok_heading1
244
    add edi,3600
244
    add edi,3600
245
    ok_heading1:
245
    ok_heading1:
246
    mov [vheading],edi
246
    mov [vheading],edi
247
    mov [mouseya],dword 1
247
    mov [mouseya],dword 1
248
    jmp check_refresh
248
    jmp check_refresh
249
 
249
 
250
m_left:                                   ; turn left (mouse)
250
m_left:                                   ; turn left (mouse)
251
    mov edi,[vheading]  ; heading
251
    mov edi,[vheading]  ; heading
252
    mov ecx,315
252
    mov ecx,315
253
    sub ecx,eax
253
    sub ecx,eax
254
    sar ecx,2
254
    sar ecx,2
255
    add edi,ecx
255
    add edi,ecx
256
    cmp edi,3600
256
    cmp edi,3600
257
    jb ok_heading2
257
    jb ok_heading2
258
    sub edi,3600
258
    sub edi,3600
259
    ok_heading2:
259
    ok_heading2:
260
    mov [vheading],edi
260
    mov [vheading],edi
261
    mov [mouseya],dword 1
261
    mov [mouseya],dword 1
262
    jmp continue    ; allow both: walk and rotate
262
    jmp continue    ; allow both: walk and rotate
263
 
263
 
264
m_right:                                  ; turn right
264
m_right:                                  ; turn right
265
    mov edi,[vheading]
265
    mov edi,[vheading]
266
    sub eax,325
266
    sub eax,325
267
    sar eax,2
267
    sar eax,2
268
    sub edi,eax
268
    sub edi,eax
269
    cmp edi,-1
269
    cmp edi,-1
270
    jg ok_heading3
270
    jg ok_heading3
271
    add edi,3600
271
    add edi,3600
272
    ok_heading3:
272
    ok_heading3:
273
    mov [vheading],edi
273
    mov [vheading],edi
274
    mov [mouseya],dword 1
274
    mov [mouseya],dword 1
275
    jmp continue
275
    jmp continue
276
 
276
 
277
 
277
 
278
 
278
 
279
  button2:                       ; button
279
  button2:                       ; button
280
    mov  eax,17                  ; get id
280
    mov  eax,17                  ; get id
281
    mcall
281
    mcall
282
    cmp  ah,1                   ; button id=1 ?
282
    cmp  ah,1                   ; button id=1 ?
283
    jne  gamestart
283
    jne  gamestart
284
 
284
 
285
; eo GAME mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
285
; eo GAME mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
286
 finish:
286
 finish:
287
    mov  eax,-1                 ; close this program
287
    mov  eax,-1                 ; close this program
288
    mcall
288
    mcall
289
 
289
 
290
 
290
 
291
;   *********************************************
291
;   *********************************************
292
;   *******  WINDOW DEFINITIONS AND DRAW ********
292
;   *******  WINDOW DEFINITIONS AND DRAW ********
293
;   *********************************************
293
;   *********************************************
294
 
294
 
295
 
295
 
296
draw_window:
296
draw_window:
297
 
297
 
298
	mcall	12,1
298
	mcall	12,1
299
	
299
	
300
	mcall 48, 4                             ;get skin width
300
	mcall 48, 4                             ;get skin width
301
	lea	ecx, [50*65536+484+eax]             ;[y start] *65536 + [y size] + [skin_height]
301
	lea	ecx, [50*65536+484+eax]             ;[y start] *65536 + [y size] + [skin_height]
302
	mcall	0,<50,649>,,0x34ffffff,,title   ;draw window
302
	mcall	0,<50,649>,,0x74ffffff,,title   ;draw window
303
 
303
 
304
	mcall	12,2
304
	mcall	12,2
305
 
305
 
306
    ret
306
    ret
307
 
307
 
308
;   *********************************************
308
;   *********************************************
309
;   *******       COMPUTE 3D-VIEW        ********
309
;   *******       COMPUTE 3D-VIEW        ********
310
;   *********************************************
310
;   *********************************************
311
draw_stuff:
311
draw_stuff:
312
 
312
 
313
 
313
 
314
mov [step1],dword 1
314
mov [step1],dword 1
315
;mov [step64],dword 64
315
;mov [step64],dword 64
316
    mov esi,[vheading]
316
    mov esi,[vheading]
317
    add esi,320
317
    add esi,320
318
    mov [va],esi
318
    mov [va],esi
319
    mov eax,[vheading]
319
    mov eax,[vheading]
320
    sub eax,320
320
    sub eax,320
321
    mov [vacompare],eax
321
    mov [vacompare],eax
322
;------------------------------------ CAST 640 PIXEL COLUMNS ---------------
322
;------------------------------------ CAST 640 PIXEL COLUMNS ---------------
323
; FOR A=320+heading to -319+heading step -1 (a is stored in [va])
323
; FOR A=320+heading to -319+heading step -1 (a is stored in [va])
324
;---------------------------------------------------------------------------
324
;---------------------------------------------------------------------------
325
;    mov edx,5
325
;    mov edx,5
326
    mov [vx1],dword 0  ;5  ;edx        ; init x1 ... pixelcolumn
326
    mov [vx1],dword 0  ;5  ;edx        ; init x1 ... pixelcolumn
327
for_a:
327
for_a:
328
mov edx,[vx1]
328
mov edx,[vx1]
329
mov [vx1b],edx
329
mov [vx1b],edx
330
sub [vx1b],dword 320
330
sub [vx1b],dword 320
331
    mov edx,[va]  ; a2
331
    mov edx,[va]  ; a2
332
    cmp edx,-1   ; a2 is a mod 3600
332
    cmp edx,-1   ; a2 is a mod 3600
333
    jg ok1
333
    jg ok1
334
    add edx,3600
334
    add edx,3600
335
ok1:
335
ok1:
336
    cmp edx,3600
336
    cmp edx,3600
337
    jb ok2
337
    jb ok2
338
    sub edx,3600
338
    sub edx,3600
339
ok2:
339
ok2:
340
 
340
 
341
; get stepx and stepy
341
; get stepx and stepy
342
;    mov ecx,edx
342
;    mov ecx,edx
343
;    imul ecx,4
343
;    imul ecx,4
344
;    add ecx,sinus     ; pointer to stepx
344
;    add ecx,sinus     ; pointer to stepx
345
    lea ecx, [sinus+edx*4]
345
    lea ecx, [sinus+edx*4]
346
    mov esi,[ecx]
346
    mov esi,[ecx]
347
    sar esi,4         ; accuracy
347
    sar esi,4         ; accuracy
348
    mov [vstepx],esi  ; store stepx
348
    mov [vstepx],esi  ; store stepx
349
 
349
 
350
;    mov esi,edx
350
;    mov esi,edx
351
;    imul esi,4
351
;    imul esi,4
352
;    add esi,sinus  ; pointer to stepy
352
;    add esi,sinus  ; pointer to stepy
353
;    add esi,3600
353
;    add esi,3600
354
    lea esi, [sinus+3600+edx*4]
354
    lea esi, [sinus+3600+edx*4]
355
    cmp esi,eosinus ;cosinus taken from ((sinus plus 900) mod 3600)
355
    cmp esi,eosinus ;cosinus taken from ((sinus plus 900) mod 3600)
356
    jb ok202
356
    jb ok202
357
    sub esi,14400
357
    sub esi,14400
358
    ok202:
358
    ok202:
359
 
359
 
360
    mov ecx,[esi]
360
    mov ecx,[esi]
361
    sar ecx,4
361
    sar ecx,4
362
    mov [vstepy],ecx ; store stepy
362
    mov [vstepy],ecx ; store stepy
363
 
363
 
364
 
364
 
365
    mov eax,[vpx]    ; get Camera Position
365
    mov eax,[vpx]    ; get Camera Position
366
    mov ebx,[vpy]
366
    mov ebx,[vpy]
367
    mov [vxx],eax    ; init caster position
367
    mov [vxx],eax    ; init caster position
368
    mov [vyy],ebx
368
    mov [vyy],ebx
369
 
369
 
370
    mov edi,0        ; init L (number of raycsting-steps)
370
    mov edi,0        ; init L (number of raycsting-steps)
371
    mov [step1],dword 1  ; init Caster stepwidth for L
371
    mov [step1],dword 1  ; init Caster stepwidth for L
372
 
372
 
373
 ;  raycast a pixel column.................................
373
 ;  raycast a pixel column.................................
374
raycast:
374
raycast:
375
    add edi,[step1]  ; count caster steps
375
    add edi,[step1]  ; count caster steps
376
;jmp nodouble ; use this to prevent blinking/wobbling textures: much slower!
376
;jmp nodouble ; use this to prevent blinking/wobbling textures: much slower!
377
 
377
 
378
    cmp edi,32
378
    cmp edi,32
379
    je double
379
    je double
380
    cmp edi,512
380
    cmp edi,512
381
    je double
381
    je double
382
    cmp edi,1024
382
    cmp edi,1024
383
    je double
383
    je double
384
    jmp nodouble
384
    jmp nodouble
385
 
385
 
386
    double:
386
    double:
387
    mov edx,[step1]
387
    mov edx,[step1]
388
    sal edx,1
388
    sal edx,1
389
    mov [step1],edx
389
    mov [step1],edx
390
 
390
 
391
    mov edx,[vstepx]
391
    mov edx,[vstepx]
392
    sal edx,1
392
    sal edx,1
393
    mov [vstepx],edx
393
    mov [vstepx],edx
394
 
394
 
395
    mov edx,[vstepy]
395
    mov edx,[vstepy]
396
    sal edx,1
396
    sal edx,1
397
    mov [vstepy],edx
397
    mov [vstepy],edx
398
 
398
 
399
nodouble:
399
nodouble:
400
 
400
 
401
    mov eax,32000 ; 3600 ; determine Floors Height based on distance
401
    mov eax,32000 ; 3600 ; determine Floors Height based on distance
402
    mov edx,0
402
    mov edx,0
403
    mov ebx,edi
403
    mov ebx,edi
404
 
404
 
405
    div ebx
405
    div ebx
406
    mov esi,eax
406
    mov esi,eax
407
    mov [vdd],esi
407
    mov [vdd],esi
408
    mov edx,260
408
    mov edx,260
409
    sub edx,esi
409
    sub edx,esi
410
    mov [vh],edx
410
    mov [vh],edx
411
 
411
 
412
    cmp edx,22
412
    cmp edx,22
413
    jb no_nu_pixel
413
    jb no_nu_pixel
414
    cmp edx,259
414
    cmp edx,259
415
    jg no_nu_pixel ; draw only new pixels
415
    jg no_nu_pixel ; draw only new pixels
416
    cmp edx,[h_old]
416
    cmp edx,[h_old]
417
    je no_nu_pixel
417
    je no_nu_pixel
418
 
418
 
419
    mov eax,[vxx] ; calc floor pixel
419
    mov eax,[vxx] ; calc floor pixel
420
    mov ebx,[vyy]
420
    mov ebx,[vyy]
421
 
421
 
422
    and eax,0x0000FFFF
422
    and eax,0x0000FFFF
423
    and ebx,0x0000FFFF
423
    and ebx,0x0000FFFF
424
 
424
 
425
    shr eax,10
425
    shr eax,10
426
    shr ebx,10    ; pixel coords inside Texture x,y 64*64
426
    shr ebx,10    ; pixel coords inside Texture x,y 64*64
427
    mov [xfrac],eax
427
    mov [xfrac],eax
428
    mov [yfrac],ebx
428
    mov [yfrac],ebx
429
 
429
 
430
 
430
 
431
 
431
 
432
    ; plot floor pixel !!!!
432
    ; plot floor pixel !!!!
433
    mov [vl],edi      ; save L
433
    mov [vl],edi      ; save L
434
    mov [ytemp],esi ; remember L bzw. H
434
    mov [ytemp],esi ; remember L bzw. H
435
 
435
 
436
    mov edi,[yfrac] ; get pixel color of this floor pixel
436
    mov edi,[yfrac] ; get pixel color of this floor pixel
437
    sal edi,8
437
    sal edi,8
438
    mov esi,[xfrac]
438
    mov esi,[xfrac]
439
    sal esi,2
439
    sal esi,2
440
;    add edi,esi
440
;    add edi,esi
441
;    add edi,wall ; in fact its floor, just using the wall texture :)
441
;    add edi,wall ; in fact its floor, just using the wall texture :)
442
    lea edi, [wall+edi+esi]
442
    lea edi, [wall+edi+esi]
443
 
443
 
444
    mov edx,[edi]
444
    mov edx,[edi]
445
    mov [remesi],esi
445
    mov [remesi],esi
446
 
446
 
447
    ;**** calculate pixel adress:****
447
    ;**** calculate pixel adress:****
448
    mov esi,[ytemp]
448
    mov esi,[ytemp]
449
    add esi,240
449
    add esi,240
450
    imul esi,1920
450
    imul esi,1920
451
;    add esi,[vx1]
451
;    add esi,[vx1]
452
;    add esi,[vx1]
452
;    add esi,[vx1]
453
;    add esi,[vx1]
453
;    add esi,[vx1]
454
;    add esi,0x80000
454
;    add esi,0x80000
455
    mov eax, [vx1]
455
    mov eax, [vx1]
456
    lea eax, [eax+eax*2]
456
    lea eax, [eax+eax*2]
457
    lea esi, [0x80000+eax+esi]
457
    lea esi, [0x80000+eax+esi]
458
 
458
 
459
    cmp esi,0x80000+1920*480
459
    cmp esi,0x80000+1920*480
460
    jg foff0
460
    jg foff0
461
    cmp esi,0x80000
461
    cmp esi,0x80000
462
    jb foff0
462
    jb foff0
463
    ; now we have the adress of the floor-pixel color in edi
463
    ; now we have the adress of the floor-pixel color in edi
464
    ; and the adress of the pixel in the image in esi
464
    ; and the adress of the pixel in the image in esi
465
 
465
 
466
    mov edx,[edi]
466
    mov edx,[edi]
467
    ;******************** custom distance DARKEN Floor
467
    ;******************** custom distance DARKEN Floor
468
 
468
 
469
    mov eax,[vdd]
469
    mov eax,[vdd]
470
 
470
 
471
; jmp nodark0 ; use this to deactivate darkening floor (a bit faster)
471
; jmp nodark0 ; use this to deactivate darkening floor (a bit faster)
472
 
472
 
473
    cmp eax,80
473
    cmp eax,80
474
    jg nodark0
474
    jg nodark0
475
    ;                split rgb
475
    ;                split rgb
476
 
476
 
477
    mov [blue],edx
477
    mov [blue],edx
478
    and [blue],dword 255
478
    and [blue],dword 255
479
 
479
 
480
    shr edx,8
480
    shr edx,8
481
    mov [green],edx
481
    mov [green],edx
482
    and [green],dword 255
482
    and [green],dword 255
483
 
483
 
484
    shr edx,8
484
    shr edx,8
485
    mov [red],edx
485
    mov [red],edx
486
    and [red],dword 255
486
    and [red],dword 255
487
 
487
 
488
    mov eax,81    ; darkness parameter
488
    mov eax,81    ; darkness parameter
489
    sub eax,[vdd]
489
    sub eax,[vdd]
490
    sal eax,1
490
    sal eax,1
491
 
491
 
492
;                        reduce rgb
492
;                        reduce rgb
493
    sub [red],eax
493
    sub [red],eax
494
    cmp [red], dword 0
494
    cmp [red], dword 0
495
    jg notblack10
495
    jg notblack10
496
    mov [red],dword 0
496
    mov [red],dword 0
497
    notblack10:
497
    notblack10:
498
 
498
 
499
    sub [green],eax
499
    sub [green],eax
500
    cmp [green],dword 0
500
    cmp [green],dword 0
501
    jg notblack20
501
    jg notblack20
502
    mov [green],dword 0
502
    mov [green],dword 0
503
    notblack20:
503
    notblack20:
504
 
504
 
505
    mov edx,[blue]
505
    mov edx,[blue]
506
    sub [blue],eax
506
    sub [blue],eax
507
    cmp [blue],dword 0
507
    cmp [blue],dword 0
508
    jg notblack30
508
    jg notblack30
509
    mov [blue],dword 0
509
    mov [blue],dword 0
510
    notblack30:
510
    notblack30:
511
 
511
 
512
    shl dword [red],16  ; reassemble rgb
512
    shl dword [red],16  ; reassemble rgb
513
    shl dword [green],8
513
    shl dword [green],8
514
    mov edx,[red]
514
    mov edx,[red]
515
    or edx,[green]
515
    or edx,[green]
516
    or edx,[blue]
516
    or edx,[blue]
517
 
517
 
518
nodark0:
518
nodark0:
519
;   eo custom darken floor
519
;   eo custom darken floor
520
 
520
 
521
 
521
 
522
    mov eax,edx
522
    mov eax,edx
523
    mov [esi],eax ; actually draw the floor pixel
523
    mov [esi],eax ; actually draw the floor pixel
524
 
524
 
525
 ; paint "forgotten" pixels
525
 ; paint "forgotten" pixels
526
 
526
 
527
    mov edx,[lasty]
527
    mov edx,[lasty]
528
    sub edx,1920
528
    sub edx,1920
529
    cmp esi,edx
529
    cmp esi,edx
530
    je foff0
530
    je foff0
531
    mov [esi+1920],eax
531
    mov [esi+1920],eax
532
 
532
 
533
    sub edx,1920
533
    sub edx,1920
534
    cmp esi,edx
534
    cmp esi,edx
535
    je foff0
535
    je foff0
536
    mov [edx+1920],eax
536
    mov [edx+1920],eax
537
 
537
 
538
    sub edx,1920
538
    sub edx,1920
539
    cmp esi,edx
539
    cmp esi,edx
540
    je foff0
540
    je foff0
541
    mov [edx+1920],eax
541
    mov [edx+1920],eax
542
 
542
 
543
foff0:
543
foff0:
544
mov [lasty],esi
544
mov [lasty],esi
545
;**** end of draw floor pixel ****
545
;**** end of draw floor pixel ****
546
 
546
 
547
    mov esi,[remesi]
547
    mov esi,[remesi]
548
    mov edi,[vl] ; restore L
548
    mov edi,[vl] ; restore L
549
 
549
 
550
no_nu_pixel:
550
no_nu_pixel:
551
 
551
 
552
 
552
 
553
    mov esi,[vh]
553
    mov esi,[vh]
554
    mov [h_old],esi
554
    mov [h_old],esi
555
 
555
 
556
    mov eax,[vxx]
556
    mov eax,[vxx]
557
    mov ebx,[vyy]
557
    mov ebx,[vyy]
558
 
558
 
559
    add eax,[vstepx]  ; casting...
559
    add eax,[vstepx]  ; casting...
560
    add ebx,[vstepy]
560
    add ebx,[vstepy]
561
 
561
 
562
    mov [vxx],eax
562
    mov [vxx],eax
563
    mov [vyy],ebx
563
    mov [vyy],ebx
564
 
564
 
565
    sar eax,16
565
    sar eax,16
566
    sar ebx,16
566
    sar ebx,16
567
 
567
 
568
    mov [vpxi],eax    ; casters position in Map Grid
568
    mov [vpxi],eax    ; casters position in Map Grid
569
    mov [vpyi],ebx
569
    mov [vpyi],ebx
570
 
570
 
571
    mov edx,ebx
571
    mov edx,ebx
572
;    imul edx,32
572
;    imul edx,32
573
    shl edx,5
573
    shl edx,5
574
;    add edx,grid
574
;    add edx,grid
575
;    add edx,eax
575
;    add edx,eax
576
    lea edx, [grid+edx+eax]
576
    lea edx, [grid+edx+eax]
577
 
577
 
578
    cmp [edx],byte 0   ; raycaster reached a wall? (0=no)
578
    cmp [edx],byte 0   ; raycaster reached a wall? (0=no)
579
    jne getout
579
    jne getout
580
    cmp edi,10000        ; limit view range
580
    cmp edi,10000        ; limit view range
581
    jb raycast
581
    jb raycast
582
;................................................
582
;................................................
583
getout:
583
getout:
584
    mov eax,[edx]      ; store Grid Wall Value for Texture Selection
584
    mov eax,[edx]      ; store Grid Wall Value for Texture Selection
585
    mov [vk],eax
585
    mov [vk],eax
586
 
586
 
587
 call blur  ; deactivate this (blurs the near floor) : a bit faster
587
 call blur  ; deactivate this (blurs the near floor) : a bit faster
588
 
588
 
589
; simply copy floor to ceil pixel column here
589
; simply copy floor to ceil pixel column here
590
;jmp nocopy ; use this for test purposes
590
;jmp nocopy ; use this for test purposes
591
 
591
 
592
    pusha
592
    pusha
593
    mov eax,0x80000+1920*240
593
    mov eax,0x80000+1920*240
594
    mov ebx,0x80000+1920*240
594
    mov ebx,0x80000+1920*240
595
 
595
 
596
copyfloor:
596
copyfloor:
597
    sub eax,1920
597
    sub eax,1920
598
    add ebx,1920
598
    add ebx,1920
599
 
599
 
600
;    mov ecx,0
600
;    mov ecx,0
601
;    add ecx,[vx1]
601
;    add ecx,[vx1]
602
;    add ecx,[vx1]
602
;    add ecx,[vx1]
603
;    add ecx,[vx1]
603
;    add ecx,[vx1]
604
    mov ecx, [vx1]
604
    mov ecx, [vx1]
605
    lea ecx, [ecx+ecx*2]
605
    lea ecx, [ecx+ecx*2]
606
 
606
 
607
;    mov edx,ecx
607
;    mov edx,ecx
608
;    add ecx,eax
608
;    add ecx,eax
609
;    add edx,ebx
609
;    add edx,ebx
610
    lea edx, [ecx+ebx]
610
    lea edx, [ecx+ebx]
611
    add ecx,eax
611
    add ecx,eax
612
 
612
 
613
    mov esi,[edx]
613
    mov esi,[edx]
614
    mov [ecx],esi
614
    mov [ecx],esi
615
 
615
 
616
    cmp eax,0x80000
616
    cmp eax,0x80000
617
    jg copyfloor
617
    jg copyfloor
618
 
618
 
619
    popa
619
    popa
620
; *** end of copy floor to ceil
620
; *** end of copy floor to ceil
621
;nocopy:
621
;nocopy:
622
;__________________________________________________________________________
622
;__________________________________________________________________________
623
 
623
 
624
 
624
 
625
; draw this pixelrows wall
625
; draw this pixelrows wall
626
    mov [vl],edi
626
    mov [vl],edi
627
 
627
 
628
    mov edi,260
628
    mov edi,260
629
    sub edi,[vdd]
629
    sub edi,[vdd]
630
    cmp edi,0
630
    cmp edi,0
631
    jg ok3
631
    jg ok3
632
    xor edi,edi
632
    xor edi,edi
633
    ok3:
633
    ok3:
634
    mov [vbottom],edi  ; end wall ceil (or window top)
634
    mov [vbottom],edi  ; end wall ceil (or window top)
635
 
635
 
636
    mov esi,262
636
    mov esi,262
637
    add esi,[vdd]  ; start wall floor
637
    add esi,[vdd]  ; start wall floor
638
 
638
 
639
    xor edi,edi
639
    xor edi,edi
640
 
640
 
641
; somethin is wrong with xfrac,so recalc...
641
; somethin is wrong with xfrac,so recalc...
642
 
642
 
643
    mov eax,[vxx]
643
    mov eax,[vxx]
644
    and eax,0x0000FFFF
644
    and eax,0x0000FFFF
645
    shr eax,10
645
    shr eax,10
646
    mov [xfrac],eax
646
    mov [xfrac],eax
647
 
647
 
648
    mov eax,[vyy]
648
    mov eax,[vyy]
649
    and eax,0x0000FFFF
649
    and eax,0x0000FFFF
650
    shr eax,10
650
    shr eax,10
651
    mov [yfrac],eax
651
    mov [yfrac],eax
652
 
652
 
653
    pixelrow:
653
    pixelrow:
654
 
654
 
655
; find each pixels color:
655
; find each pixels color:
656
 
656
 
657
    add edi,64
657
    add edi,64
658
    sub esi,1
658
    sub esi,1
659
    cmp esi, 502  ; dont calc offscreen-pixels
659
    cmp esi, 502  ; dont calc offscreen-pixels
660
    jg speedup
660
    jg speedup
661
 
661
 
662
    xor edx,edx
662
    xor edx,edx
663
    mov eax, edi
663
    mov eax, edi
664
    mov ebx,[vdd]
664
    mov ebx,[vdd]
665
;    add ebx,[vdd]
665
;    add ebx,[vdd]
666
    add ebx, ebx
666
    add ebx, ebx
667
    div ebx
667
    div ebx
668
    and eax,63
668
    and eax,63
669
    mov [ytemp],eax   ; get y of texture for wall
669
    mov [ytemp],eax   ; get y of texture for wall
670
 
670
 
671
    mov eax,[xfrac]
671
    mov eax,[xfrac]
672
    add eax,[yfrac]
672
    add eax,[yfrac]
673
 
673
 
674
    and eax,63
674
    and eax,63
675
    mov [xtemp],eax   ; get x of texture for wall
675
    mov [xtemp],eax   ; get x of texture for wall
676
 
676
 
677
    ; now prepare to plot that wall-pixel...
677
    ; now prepare to plot that wall-pixel...
678
    mov [remedi],edi
678
    mov [remedi],edi
679
 
679
 
680
    mov edi,[ytemp]
680
    mov edi,[ytemp]
681
    sal edi,8
681
    sal edi,8
682
    mov edx,[xtemp]
682
    mov edx,[xtemp]
683
    sal edx,2
683
    sal edx,2
684
    add edi,edx
684
    add edi,edx
685
 
685
 
686
    mov eax,[vk] ; determine which texture should be used
686
    mov eax,[vk] ; determine which texture should be used
687
    and eax,255
687
    and eax,255
688
 
688
 
689
    cmp eax,1
689
    cmp eax,1
690
    jne checkmore1
690
    jne checkmore1
691
    add edi,ceil
691
    add edi,ceil
692
    jmp foundtex
692
    jmp foundtex
693
    checkmore1:
693
    checkmore1:
694
 
694
 
695
    cmp eax,2
695
    cmp eax,2
696
    jne checkmore2
696
    jne checkmore2
697
    add edi,wall
697
    add edi,wall
698
    jmp foundtex
698
    jmp foundtex
699
    checkmore2:
699
    checkmore2:
700
 
700
 
701
    cmp eax,3
701
    cmp eax,3
702
    jne checkmore3
702
    jne checkmore3
703
    add edi,wall2
703
    add edi,wall2
704
    jmp foundtex
704
    jmp foundtex
705
    checkmore3:
705
    checkmore3:
706
 
706
 
707
    cmp eax,4
707
    cmp eax,4
708
    jne checkmore4
708
    jne checkmore4
709
    add edi,wall3
709
    add edi,wall3
710
    jmp foundtex
710
    jmp foundtex
711
    checkmore4:
711
    checkmore4:
712
 
712
 
713
    cmp eax,5
713
    cmp eax,5
714
    jne checkmore5
714
    jne checkmore5
715
    add edi,wall4
715
    add edi,wall4
716
    jmp foundtex
716
    jmp foundtex
717
    checkmore5:
717
    checkmore5:
718
 
718
 
719
    cmp eax,6
719
    cmp eax,6
720
    jne checkmore6
720
    jne checkmore6
721
    add edi,wall5
721
    add edi,wall5
722
    jmp foundtex
722
    jmp foundtex
723
    checkmore6:
723
    checkmore6:
724
 
724
 
725
    cmp eax,7
725
    cmp eax,7
726
    jne checkmore7
726
    jne checkmore7
727
    add edi,wall6
727
    add edi,wall6
728
    jmp foundtex
728
    jmp foundtex
729
    checkmore7:
729
    checkmore7:
730
 
730
 
731
    cmp eax,8
731
    cmp eax,8
732
    jne checkmore8
732
    jne checkmore8
733
    add edi,wall7
733
    add edi,wall7
734
    jmp foundtex
734
    jmp foundtex
735
    checkmore8:
735
    checkmore8:
736
 
736
 
737
    foundtex:
737
    foundtex:
738
 
738
 
739
    mov edx,[edi]    ; get pixel color inside texture
739
    mov edx,[edi]    ; get pixel color inside texture
740
 
740
 
741
; ***pseudoshade south-west
741
; ***pseudoshade south-west
742
jmp east ; activate this for southwest pseudoshade : a bit slower + blink-bug
742
jmp east ; activate this for southwest pseudoshade : a bit slower + blink-bug
743
    mov edi,[yfrac]
743
    mov edi,[yfrac]
744
    mov [pseudo],dword 0 ; store flag for custom distance darkening
744
    mov [pseudo],dword 0 ; store flag for custom distance darkening
745
    cmp edi,[xfrac]
745
    cmp edi,[xfrac]
746
    jge east
746
    jge east
747
    and edx,0x00FEFEFE
747
    and edx,0x00FEFEFE
748
    shr edx,1
748
    shr edx,1
749
    mov [pseudo],dword 1
749
    mov [pseudo],dword 1
750
east:
750
east:
751
 
751
 
752
 call dark_distance ; deactivate wall distance darkening: a bit faster
752
 call dark_distance ; deactivate wall distance darkening: a bit faster
753
 
753
 
754
; ******* DRAW WALL PIXEL *******
754
; ******* DRAW WALL PIXEL *******
755
    mov eax,esi
755
    mov eax,esi
756
;    sub eax,22
756
;    sub eax,22
757
    lea eax, [esi-22]
757
    lea eax, [esi-22]
758
    imul eax,1920
758
    imul eax,1920
759
;    add eax,[vx1]
759
;    add eax,[vx1]
760
;    add eax,[vx1]
760
;    add eax,[vx1]
761
;    add eax,[vx1]
761
;    add eax,[vx1]
762
;    add eax,0x80000
762
;    add eax,0x80000
763
    mov ebx, [vx1]
763
    mov ebx, [vx1]
764
    lea ebx, [ebx+ebx*2]
764
    lea ebx, [ebx+ebx*2]
765
    lea eax, [eax+0x80000+ebx]
765
    lea eax, [eax+0x80000+ebx]
766
 
766
 
767
    cmp eax,0x80000+1920*480
767
    cmp eax,0x80000+1920*480
768
    jg dont_draw
768
    jg dont_draw
769
    cmp eax,0x80000
769
    cmp eax,0x80000
770
    jb dont_draw
770
    jb dont_draw
771
    mov [eax],edx ; actually set the pixel in the image
771
    mov [eax],edx ; actually set the pixel in the image
772
; *** eo draw wall pixel
772
; *** eo draw wall pixel
773
dont_draw:
773
dont_draw:
774
    mov edi,[remedi]
774
    mov edi,[remedi]
775
speedup:
775
speedup:
776
    cmp esi,[vbottom]  ; end of this column?
776
    cmp esi,[vbottom]  ; end of this column?
777
    jg pixelrow
777
    jg pixelrow
778
 
778
 
779
    mov edi,[vl]  ; restoring
779
    mov edi,[vl]  ; restoring
780
    mov eax,[vx1] ; inc X1
780
    mov eax,[vx1] ; inc X1
781
    add eax,1
781
    add eax,1
782
    mov [vx1],eax
782
    mov [vx1],eax
783
 
783
 
784
    ;*** NEXT A ***
784
    ;*** NEXT A ***
785
    mov esi,[va]
785
    mov esi,[va]
786
    sub esi,1
786
    sub esi,1
787
    mov [va],esi
787
    mov [va],esi
788
    cmp esi,[vacompare]
788
    cmp esi,[vacompare]
789
    jg for_a
789
    jg for_a
790
    ;*** EO NEXT A ***
790
    ;*** EO NEXT A ***
791
;---------------------------------------------------------------------------
791
;---------------------------------------------------------------------------
792
 
792
 
793
 
793
 
794
; **** put image !!!!!****
794
; **** put image !!!!!****
795
; ***********************
795
; ***********************
796
    mov eax,7
796
    mov eax,7
797
    mov ebx,0x80000
797
    mov ebx,0x80000
798
    mov ecx,640*65536+480
798
    mov ecx,640*65536+480
799
    xor edx,edx
799
    xor edx,edx
800
    mcall
800
    mcall
801
 
801
 
802
    ret
802
    ret
803
 
803
 
804
blur:
804
blur:
805
 
805
 
806
pusha
806
pusha
807
mov eax,0x080000+360*1920
807
mov eax,0x080000+360*1920
808
 
808
 
809
copyfloor2:
809
copyfloor2:
810
    add eax,1920
810
    add eax,1920
811
;    mov ebx,eax
811
;    mov ebx,eax
812
;    add ebx,[vx1]
812
;    add ebx,[vx1]
813
;    add ebx,[vx1]
813
;    add ebx,[vx1]
814
;    add ebx,[vx1]
814
;    add ebx,[vx1]
815
    mov ebx,[vx1]
815
    mov ebx,[vx1]
816
    lea ebx, [ebx+ebx*2]
816
    lea ebx, [ebx+ebx*2]
817
    add ebx, eax
817
    add ebx, eax
818
 
818
 
819
 
819
 
820
    mov ecx,[ebx-15]
820
    mov ecx,[ebx-15]
821
    and ecx,0x00FEFEFE
821
    and ecx,0x00FEFEFE
822
    shr ecx,1
822
    shr ecx,1
823
    mov edx,[ebx-12]
823
    mov edx,[ebx-12]
824
    and edx,0x00FEFEFE
824
    and edx,0x00FEFEFE
825
    shr edx,1
825
    shr edx,1
826
    add edx,ecx
826
    add edx,ecx
827
    and edx,0x00FEFEFE
827
    and edx,0x00FEFEFE
828
    shr edx,1
828
    shr edx,1
829
 
829
 
830
     mov ecx,[ebx-9]
830
     mov ecx,[ebx-9]
831
     and ecx,0x00FEFEFE
831
     and ecx,0x00FEFEFE
832
     shr ecx,1
832
     shr ecx,1
833
     add edx,ecx
833
     add edx,ecx
834
 
834
 
835
      and edx,0x00FEFEFE
835
      and edx,0x00FEFEFE
836
      shr edx,1
836
      shr edx,1
837
 
837
 
838
      mov ecx,[ebx-6]
838
      mov ecx,[ebx-6]
839
      and ecx,0x00FEFEFE
839
      and ecx,0x00FEFEFE
840
      shr ecx,1
840
      shr ecx,1
841
      add edx,ecx
841
      add edx,ecx
842
 
842
 
843
       and edx,0x00FEFEFE
843
       and edx,0x00FEFEFE
844
       shr edx,1
844
       shr edx,1
845
 
845
 
846
       mov ecx,[ebx-3]
846
       mov ecx,[ebx-3]
847
       and ecx,0x00FEFEFE
847
       and ecx,0x00FEFEFE
848
       shr ecx,1
848
       shr ecx,1
849
       add edx,ecx
849
       add edx,ecx
850
 
850
 
851
        and edx,0x00FEFEFE
851
        and edx,0x00FEFEFE
852
        shr edx,1
852
        shr edx,1
853
 
853
 
854
        mov ecx,[ebx]
854
        mov ecx,[ebx]
855
        and ecx,0x00FEFEFE
855
        and ecx,0x00FEFEFE
856
        shr ecx,1
856
        shr ecx,1
857
        add edx,ecx
857
        add edx,ecx
858
 
858
 
859
    mov [ebx],edx
859
    mov [ebx],edx
860
 
860
 
861
    cmp eax,0x80000+478*1920
861
    cmp eax,0x80000+478*1920
862
    jb copyfloor2
862
    jb copyfloor2
863
 
863
 
864
popa
864
popa
865
 
865
 
866
ret
866
ret
867
 
867
 
868
 
868
 
869
 
869
 
870
; ******* Darken by Distance *******
870
; ******* Darken by Distance *******
871
dark_distance:
871
dark_distance:
872
 
872
 
873
; color must be in edx, wall height in [vdd]
873
; color must be in edx, wall height in [vdd]
874
 
874
 
875
    mov eax,[vdd]
875
    mov eax,[vdd]
876
    cmp eax,50
876
    cmp eax,50
877
    jg nodark
877
    jg nodark
878
    ;                split rgb
878
    ;                split rgb
879
 
879
 
880
    mov [blue],edx
880
    mov [blue],edx
881
    and [blue],dword 255
881
    and [blue],dword 255
882
 
882
 
883
    shr edx,8
883
    shr edx,8
884
    mov [green],edx
884
    mov [green],edx
885
    and [green],dword 255
885
    and [green],dword 255
886
 
886
 
887
    shr edx,8
887
    shr edx,8
888
    mov [red],edx
888
    mov [red],edx
889
    and [red],dword 255
889
    and [red],dword 255
890
 
890
 
891
    mov eax,51    ; darkness parameter
891
    mov eax,51    ; darkness parameter
892
    sub eax,[vdd]
892
    sub eax,[vdd]
893
    cmp [pseudo],dword 1
893
    cmp [pseudo],dword 1
894
    je isdarkside
894
    je isdarkside
895
    sal eax,2
895
    sal eax,2
896
isdarkside:
896
isdarkside:
897
 
897
 
898
;                        reduce rgb
898
;                        reduce rgb
899
    sub [red],eax
899
    sub [red],eax
900
    cmp [red], dword 0
900
    cmp [red], dword 0
901
    jg notblack10b
901
    jg notblack10b
902
    mov [red],dword 0
902
    mov [red],dword 0
903
    notblack10b:
903
    notblack10b:
904
 
904
 
905
    sub [green],eax
905
    sub [green],eax
906
    cmp [green],dword 0
906
    cmp [green],dword 0
907
    jg notblack20b
907
    jg notblack20b
908
    mov [green],dword 0
908
    mov [green],dword 0
909
    notblack20b:
909
    notblack20b:
910
 
910
 
911
    mov edx,[blue]
911
    mov edx,[blue]
912
    sub [blue],eax
912
    sub [blue],eax
913
    cmp [blue],dword 0
913
    cmp [blue],dword 0
914
    jg notblack30b
914
    jg notblack30b
915
    mov [blue],dword 0
915
    mov [blue],dword 0
916
    notblack30b:
916
    notblack30b:
917
 
917
 
918
    shl dword [red],16 ; reassemble rgb
918
    shl dword [red],16 ; reassemble rgb
919
    shl dword [green],8
919
    shl dword [green],8
920
    mov edx,[red]
920
    mov edx,[red]
921
    or edx,[green]
921
    or edx,[green]
922
    or edx,[blue]
922
    or edx,[blue]
923
    mov eax,edx
923
    mov eax,edx
924
 
924
 
925
nodark:
925
nodark:
926
 
926
 
927
    ret
927
    ret
928
 
928
 
929
 
929
 
930
; DATA AREA
930
; DATA AREA
931
 
931
 
932
;ceil=ceil
932
;ceil=ceil
933
;wall=wall floor
933
;wall=wall floor
934
;2 corner stone
934
;2 corner stone
935
;3 leaf mosaic
935
;3 leaf mosaic
936
;4 closed window
936
;4 closed window
937
;5 greek mosaic
937
;5 greek mosaic
938
;6 old street stones
938
;6 old street stones
939
;7 maya wall
939
;7 maya wall
940
 
940
 
941
grid:  ; 32*32 Blocks, Map: 0 = Air, 1 to 8 = Wall
941
grid:  ; 32*32 Blocks, Map: 0 = Air, 1 to 8 = Wall
942
db 2,1,2,1,2,1,2,1,2,1,2,1,1,1,1,1,1,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
942
db 2,1,2,1,2,1,2,1,2,1,2,1,1,1,1,1,1,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
943
db 1,0,0,0,1,0,0,0,0,0,0,3,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8
943
db 1,0,0,0,1,0,0,0,0,0,0,3,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8
944
db 5,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8
944
db 5,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8
945
db 1,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,1,0,0,0,0,3,3,3,3,0,0,0,0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,1,0,1,1,1,1,4,1,0,1,3,0,0,0,0,6,0,0,1,0,1,0,4,0,0,0,0,0,4,0,1
968
db 1,1,0,1,1,1,1,4,1,0,1,3,0,0,0,0,6,0,0,1,0,1,0,4,0,0,0,0,0,4,0,1
969
db 5,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,6,0,0,5,0,1,0,4,0,0,0,0,0,4,0,1
969
db 5,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,6,0,0,5,0,1,0,4,0,0,0,0,0,4,0,1
970
db 1,0,0,0,1,0,0,5,0,0,0,3,0,0,0,0,6,1,5,1,0,1,0,4,4,0,0,0,4,4,0,1
970
db 1,0,0,0,1,0,0,5,0,0,0,3,0,0,0,0,6,1,5,1,0,1,0,4,4,0,0,0,4,4,0,1
971
db 5,0,0,0,0,0,0,5,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,4,4,4,4,4,0,0,1
971
db 5,0,0,0,0,0,0,5,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,4,4,4,4,4,0,0,1
972
db 1,4,1,4,1,4,1,4,1,4,1,3,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1
972
db 1,4,1,4,1,4,1,4,1,4,1,3,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1
973
db 2,1,2,1,2,1,2,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
973
db 2,1,2,1,2,1,2,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
974
 
974
 
975
vpx:
975
vpx:
976
dd 0x0001FFFF ; initial player position * 0xFFFF
976
dd 0x0001FFFF ; initial player position * 0xFFFF
977
 vpy:
977
 vpy:
978
dd 0x0001FFFF
978
dd 0x0001FFFF
979
 
979
 
980
title    db   'FISHEYE RAYCASTING ENGINE ETC. FREE3D',0
980
title    db   'FISHEYE RAYCASTING ENGINE ETC. FREE3D',0
981
 
981
 
982
sindegree dd 0.0
982
sindegree dd 0.0
983
sininc    dd 0.0017453292519943295769236907684886
983
sininc    dd 0.0017453292519943295769236907684886
984
sindiv    dd 6553.5
984
sindiv    dd 6553.5
985
textures:
985
textures:
986
	file 'texture.gif'
986
	file 'texture.gif'
987
 
987
 
988
align 4
988
align 4
989
 
989
 
990
col1:
990
col1:
991
 dd ?;-
991
 dd ?;-
992
; misc raycaster vars:
992
; misc raycaster vars:
993
vxx:
993
vxx:
994
 dd ?;-
994
 dd ?;-
995
vyy:
995
vyy:
996
 dd ?;-
996
 dd ?;-
997
vl:
997
vl:
998
 dd ?;-
998
 dd ?;-
999
vstepx:
999
vstepx:
1000
 dd ?;-
1000
 dd ?;-
1001
vstepy:
1001
vstepy:
1002
 dd ?;-
1002
 dd ?;-
1003
vxxint:
1003
vxxint:
1004
 dd ?;-
1004
 dd ?;-
1005
vyyint:
1005
vyyint:
1006
 dd ?;-
1006
 dd ?;-
1007
vk:
1007
vk:
1008
 dd ?;-
1008
 dd ?;-
1009
va:
1009
va:
1010
 dd ?;-
1010
 dd ?;-
1011
va2:
1011
va2:
1012
 dd ?;-
1012
 dd ?;-
1013
vdd:
1013
vdd:
1014
 dd ?;-
1014
 dd ?;-
1015
vx1:
1015
vx1:
1016
 dd ?;-
1016
 dd ?;-
1017
vx1b:
1017
vx1b:
1018
 dd ?;-
1018
 dd ?;-
1019
vh:
1019
vh:
1020
 dd ?;-
1020
 dd ?;-
1021
vdt:
1021
vdt:
1022
 dd ?;-
1022
 dd ?;-
1023
vheading: ; initial heading: 0 to 3599
1023
vheading: ; initial heading: 0 to 3599
1024
 dd ?;-
1024
 dd ?;-
1025
vacompare:
1025
vacompare:
1026
 dd ?;-
1026
 dd ?;-
1027
vpxi:
1027
vpxi:
1028
 dd ?;-
1028
 dd ?;-
1029
vpyi:
1029
vpyi:
1030
 dd ?;-
1030
 dd ?;-
1031
wtolong:
1031
wtolong:
1032
 dw ?,?;-,?;-
1032
 dw ?,?;-,?;-
1033
 
1033
 
1034
xtemp:
1034
xtemp:
1035
 dd ?;-
1035
 dd ?;-
1036
ytemp:
1036
ytemp:
1037
 dd ?;-
1037
 dd ?;-
1038
xfrac:
1038
xfrac:
1039
 dd ?;-
1039
 dd ?;-
1040
yfrac:
1040
yfrac:
1041
 dd ?;-
1041
 dd ?;-
1042
h_old:
1042
h_old:
1043
 dd ?;-
1043
 dd ?;-
1044
vbottom:
1044
vbottom:
1045
 dd ?;-
1045
 dd ?;-
1046
mouseya:
1046
mouseya:
1047
 dd ?;-
1047
 dd ?;-
1048
remeax:
1048
remeax:
1049
 dd ?;-
1049
 dd ?;-
1050
remebx:
1050
remebx:
1051
 dd ?;-
1051
 dd ?;-
1052
remecx:
1052
remecx:
1053
 dd ?;-
1053
 dd ?;-
1054
remedx:
1054
remedx:
1055
 dd ?;-
1055
 dd ?;-
1056
remedi:
1056
remedi:
1057
 dd ?;-
1057
 dd ?;-
1058
remesi:
1058
remesi:
1059
 dd ?;-
1059
 dd ?;-
1060
red:
1060
red:
1061
 dd ?;-
1061
 dd ?;-
1062
green:
1062
green:
1063
 dd ?;-
1063
 dd ?;-
1064
blue:
1064
blue:
1065
 dd ?;-
1065
 dd ?;-
1066
pseudo:
1066
pseudo:
1067
 dd ?;-
1067
 dd ?;-
1068
step1:
1068
step1:
1069
 dd ?;-
1069
 dd ?;-
1070
step64:
1070
step64:
1071
 dd ?;-
1071
 dd ?;-
1072
lasty:
1072
lasty:
1073
 dd ?;-
1073
 dd ?;-
1074
 
1074
 
1075
I_END:
1075
I_END:
1076
IncludeUGlobals
1076
IncludeUGlobals
1077
sinus rd 360*10
1077
sinus rd 360*10
1078
eosinus:
1078
eosinus: