Subversion Repositories Kolibri OS

Rev

Rev 552 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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