Subversion Repositories Kolibri OS

Rev

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

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