Subversion Repositories Kolibri OS

Rev

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