Subversion Repositories Kolibri OS

Rev

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
;
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
 
31 halyavin 298
    mov  eax,12                    ; function 12:tell os about windowdraw
299
    mov  ebx,1                     ; 1, start of draw
485 heavyiron 300
    mcall
272 serge 301
 
31 halyavin 302
                                   ; DRAW WINDOW
303
    mov  eax,0                     ; function 0 : define and draw window
304
    mov  ebx,50*65536+649         ; [x start] *65536 + [x size]
1416 leency 305
    mov  ecx,50*65536+506         ; [y start] *65536 + [y size]
306
    mov  edx,0x74ffffff            ; color of work area RRGGBB,8->color gl
485 heavyiron 307
    mov  edi,title
308
    mcall
272 serge 309
 
31 halyavin 310
    mov  eax,12                    ; function 12:tell os about windowdraw
311
    mov  ebx,2                     ; 2, end of draw
485 heavyiron 312
    mcall
272 serge 313
 
31 halyavin 314
    ret
272 serge 315
 
31 halyavin 316
;   *********************************************
317
;   *******       COMPUTE 3D-VIEW        ********
318
;   *********************************************
319
draw_stuff:
272 serge 320
 
321
 
31 halyavin 322
mov [step1],dword 1
323
;mov [step64],dword 64
324
    mov esi,[vheading]
325
    add esi,320
326
    mov [va],esi
327
    mov eax,[vheading]
328
    sub eax,320
329
    mov [vacompare],eax
330
;------------------------------------ CAST 640 PIXEL COLUMNS ---------------
331
; FOR A=320+heading to -319+heading step -1 (a is stored in [va])
332
;---------------------------------------------------------------------------
333
;    mov edx,5
334
    mov [vx1],dword 0  ;5  ;edx        ; init x1 ... pixelcolumn
335
for_a:
336
mov edx,[vx1]
337
mov [vx1b],edx
338
sub [vx1b],dword 320
339
    mov edx,[va]  ; a2
340
    cmp edx,-1   ; a2 is a mod 3600
341
    jg ok1
342
    add edx,3600
343
ok1:
344
    cmp edx,3600
345
    jb ok2
346
    sub edx,3600
347
ok2:
272 serge 348
 
31 halyavin 349
; get stepx and stepy
272 serge 350
;    mov ecx,edx
351
;    imul ecx,4
352
;    add ecx,sinus     ; pointer to stepx
353
    lea ecx, [sinus+edx*4]
31 halyavin 354
    mov esi,[ecx]
355
    sar esi,4         ; accuracy
356
    mov [vstepx],esi  ; store stepx
272 serge 357
 
358
;    mov esi,edx
359
;    imul esi,4
360
;    add esi,sinus  ; pointer to stepy
361
;    add esi,3600
362
    lea esi, [sinus+3600+edx*4]
31 halyavin 363
    cmp esi,eosinus ;cosinus taken from ((sinus plus 900) mod 3600)
364
    jb ok202
365
    sub esi,14400
366
    ok202:
272 serge 367
 
31 halyavin 368
    mov ecx,[esi]
369
    sar ecx,4
370
    mov [vstepy],ecx ; store stepy
272 serge 371
 
372
 
31 halyavin 373
    mov eax,[vpx]    ; get Camera Position
374
    mov ebx,[vpy]
375
    mov [vxx],eax    ; init caster position
376
    mov [vyy],ebx
272 serge 377
 
31 halyavin 378
    mov edi,0        ; init L (number of raycsting-steps)
379
    mov [step1],dword 1  ; init Caster stepwidth for L
272 serge 380
 
31 halyavin 381
 ;  raycast a pixel column.................................
382
raycast:
383
    add edi,[step1]  ; count caster steps
384
;jmp nodouble ; use this to prevent blinking/wobbling textures: much slower!
272 serge 385
 
31 halyavin 386
    cmp edi,32
387
    je double
388
    cmp edi,512
389
    je double
390
    cmp edi,1024
391
    je double
392
    jmp nodouble
272 serge 393
 
31 halyavin 394
    double:
395
    mov edx,[step1]
396
    sal edx,1
397
    mov [step1],edx
272 serge 398
 
31 halyavin 399
    mov edx,[vstepx]
400
    sal edx,1
401
    mov [vstepx],edx
272 serge 402
 
31 halyavin 403
    mov edx,[vstepy]
404
    sal edx,1
405
    mov [vstepy],edx
272 serge 406
 
31 halyavin 407
nodouble:
272 serge 408
 
31 halyavin 409
    mov eax,32000 ; 3600 ; determine Floors Height based on distance
410
    mov edx,0
411
    mov ebx,edi
272 serge 412
 
31 halyavin 413
    div ebx
414
    mov esi,eax
415
    mov [vdd],esi
416
    mov edx,260
417
    sub edx,esi
418
    mov [vh],edx
272 serge 419
 
31 halyavin 420
    cmp edx,22
421
    jb no_nu_pixel
422
    cmp edx,259
423
    jg no_nu_pixel ; draw only new pixels
424
    cmp edx,[h_old]
425
    je no_nu_pixel
272 serge 426
 
31 halyavin 427
    mov eax,[vxx] ; calc floor pixel
428
    mov ebx,[vyy]
272 serge 429
 
31 halyavin 430
    and eax,0x0000FFFF
431
    and ebx,0x0000FFFF
272 serge 432
 
31 halyavin 433
    shr eax,10
434
    shr ebx,10    ; pixel coords inside Texture x,y 64*64
435
    mov [xfrac],eax
436
    mov [yfrac],ebx
272 serge 437
 
438
 
439
 
31 halyavin 440
    ; plot floor pixel !!!!
441
    mov [vl],edi      ; save L
442
    mov [ytemp],esi ; remember L bzw. H
272 serge 443
 
31 halyavin 444
    mov edi,[yfrac] ; get pixel color of this floor pixel
445
    sal edi,8
446
    mov esi,[xfrac]
447
    sal esi,2
272 serge 448
;    add edi,esi
449
;    add edi,wall ; in fact its floor, just using the wall texture :)
450
    lea edi, [wall+edi+esi]
451
 
31 halyavin 452
    mov edx,[edi]
453
    mov [remesi],esi
272 serge 454
 
31 halyavin 455
    ;**** calculate pixel adress:****
456
    mov esi,[ytemp]
457
    add esi,240
458
    imul esi,1920
272 serge 459
;    add esi,[vx1]
460
;    add esi,[vx1]
461
;    add esi,[vx1]
462
;    add esi,0x80000
463
    mov eax, [vx1]
464
    lea eax, [eax+eax*2]
465
    lea esi, [0x80000+eax+esi]
466
 
31 halyavin 467
    cmp esi,0x80000+1920*480
468
    jg foff0
469
    cmp esi,0x80000
470
    jb foff0
471
    ; now we have the adress of the floor-pixel color in edi
472
    ; and the adress of the pixel in the image in esi
272 serge 473
 
31 halyavin 474
    mov edx,[edi]
475
    ;******************** custom distance DARKEN Floor
272 serge 476
 
31 halyavin 477
    mov eax,[vdd]
272 serge 478
 
31 halyavin 479
; jmp nodark0 ; use this to deactivate darkening floor (a bit faster)
272 serge 480
 
31 halyavin 481
    cmp eax,80
482
    jg nodark0
483
    ;                split rgb
272 serge 484
 
31 halyavin 485
    mov [blue],edx
486
    and [blue],dword 255
272 serge 487
 
31 halyavin 488
    shr edx,8
489
    mov [green],edx
490
    and [green],dword 255
272 serge 491
 
31 halyavin 492
    shr edx,8
493
    mov [red],edx
494
    and [red],dword 255
272 serge 495
 
31 halyavin 496
    mov eax,81    ; darkness parameter
497
    sub eax,[vdd]
498
    sal eax,1
272 serge 499
 
31 halyavin 500
;                        reduce rgb
501
    sub [red],eax
502
    cmp [red], dword 0
503
    jg notblack10
504
    mov [red],dword 0
505
    notblack10:
272 serge 506
 
31 halyavin 507
    sub [green],eax
508
    cmp [green],dword 0
509
    jg notblack20
510
    mov [green],dword 0
511
    notblack20:
272 serge 512
 
31 halyavin 513
    mov edx,[blue]
514
    sub [blue],eax
515
    cmp [blue],dword 0
516
    jg notblack30
517
    mov [blue],dword 0
518
    notblack30:
272 serge 519
 
31 halyavin 520
    shl dword [red],16  ; reassemble rgb
521
    shl dword [green],8
522
    mov edx,[red]
523
    or edx,[green]
524
    or edx,[blue]
272 serge 525
 
31 halyavin 526
nodark0:
527
;   eo custom darken floor
272 serge 528
 
529
 
31 halyavin 530
    mov eax,edx
531
    mov [esi],eax ; actually draw the floor pixel
272 serge 532
 
31 halyavin 533
 ; paint "forgotten" pixels
272 serge 534
 
31 halyavin 535
    mov edx,[lasty]
536
    sub edx,1920
537
    cmp esi,edx
538
    je foff0
539
    mov [esi+1920],eax
272 serge 540
 
31 halyavin 541
    sub edx,1920
542
    cmp esi,edx
543
    je foff0
544
    mov [edx+1920],eax
272 serge 545
 
31 halyavin 546
    sub edx,1920
547
    cmp esi,edx
548
    je foff0
549
    mov [edx+1920],eax
272 serge 550
 
31 halyavin 551
foff0:
552
mov [lasty],esi
553
;**** end of draw floor pixel ****
272 serge 554
 
31 halyavin 555
    mov esi,[remesi]
556
    mov edi,[vl] ; restore L
272 serge 557
 
31 halyavin 558
no_nu_pixel:
272 serge 559
 
560
 
31 halyavin 561
    mov esi,[vh]
562
    mov [h_old],esi
272 serge 563
 
31 halyavin 564
    mov eax,[vxx]
565
    mov ebx,[vyy]
272 serge 566
 
31 halyavin 567
    add eax,[vstepx]  ; casting...
568
    add ebx,[vstepy]
272 serge 569
 
31 halyavin 570
    mov [vxx],eax
571
    mov [vyy],ebx
272 serge 572
 
31 halyavin 573
    sar eax,16
574
    sar ebx,16
272 serge 575
 
31 halyavin 576
    mov [vpxi],eax    ; casters position in Map Grid
577
    mov [vpyi],ebx
272 serge 578
 
31 halyavin 579
    mov edx,ebx
580
;    imul edx,32
581
    shl edx,5
272 serge 582
;    add edx,grid
583
;    add edx,eax
584
    lea edx, [grid+edx+eax]
585
 
31 halyavin 586
    cmp [edx],byte 0   ; raycaster reached a wall? (0=no)
587
    jne getout
588
    cmp edi,10000        ; limit view range
589
    jb raycast
590
;................................................
591
getout:
592
    mov eax,[edx]      ; store Grid Wall Value for Texture Selection
593
    mov [vk],eax
272 serge 594
 
31 halyavin 595
 call blur  ; deactivate this (blurs the near floor) : a bit faster
272 serge 596
 
31 halyavin 597
; simply copy floor to ceil pixel column here
598
;jmp nocopy ; use this for test purposes
272 serge 599
 
31 halyavin 600
    pusha
601
    mov eax,0x80000+1920*240
602
    mov ebx,0x80000+1920*240
272 serge 603
 
31 halyavin 604
copyfloor:
605
    sub eax,1920
606
    add ebx,1920
272 serge 607
 
608
;    mov ecx,0
609
;    add ecx,[vx1]
610
;    add ecx,[vx1]
611
;    add ecx,[vx1]
612
    mov ecx, [vx1]
613
    lea ecx, [ecx+ecx*2]
614
 
615
;    mov edx,ecx
616
;    add ecx,eax
617
;    add edx,ebx
618
    lea edx, [ecx+ebx]
31 halyavin 619
    add ecx,eax
272 serge 620
 
31 halyavin 621
    mov esi,[edx]
622
    mov [ecx],esi
272 serge 623
 
31 halyavin 624
    cmp eax,0x80000
625
    jg copyfloor
272 serge 626
 
31 halyavin 627
    popa
628
; *** end of copy floor to ceil
629
;nocopy:
630
;__________________________________________________________________________
272 serge 631
 
632
 
31 halyavin 633
; draw this pixelrows wall
634
    mov [vl],edi
272 serge 635
 
31 halyavin 636
    mov edi,260
637
    sub edi,[vdd]
638
    cmp edi,0
639
    jg ok3
640
    xor edi,edi
641
    ok3:
642
    mov [vbottom],edi  ; end wall ceil (or window top)
272 serge 643
 
31 halyavin 644
    mov esi,262
645
    add esi,[vdd]  ; start wall floor
272 serge 646
 
31 halyavin 647
    xor edi,edi
272 serge 648
 
31 halyavin 649
; somethin is wrong with xfrac,so recalc...
272 serge 650
 
31 halyavin 651
    mov eax,[vxx]
652
    and eax,0x0000FFFF
653
    shr eax,10
654
    mov [xfrac],eax
272 serge 655
 
31 halyavin 656
    mov eax,[vyy]
657
    and eax,0x0000FFFF
658
    shr eax,10
659
    mov [yfrac],eax
272 serge 660
 
31 halyavin 661
    pixelrow:
272 serge 662
 
31 halyavin 663
; find each pixels color:
272 serge 664
 
31 halyavin 665
    add edi,64
666
    sub esi,1
667
    cmp esi, 502  ; dont calc offscreen-pixels
668
    jg speedup
272 serge 669
 
31 halyavin 670
    xor edx,edx
671
    mov eax, edi
672
    mov ebx,[vdd]
272 serge 673
;    add ebx,[vdd]
674
    add ebx, ebx
31 halyavin 675
    div ebx
676
    and eax,63
677
    mov [ytemp],eax   ; get y of texture for wall
272 serge 678
 
31 halyavin 679
    mov eax,[xfrac]
680
    add eax,[yfrac]
272 serge 681
 
31 halyavin 682
    and eax,63
683
    mov [xtemp],eax   ; get x of texture for wall
272 serge 684
 
31 halyavin 685
    ; now prepare to plot that wall-pixel...
686
    mov [remedi],edi
272 serge 687
 
31 halyavin 688
    mov edi,[ytemp]
689
    sal edi,8
690
    mov edx,[xtemp]
691
    sal edx,2
692
    add edi,edx
272 serge 693
 
31 halyavin 694
    mov eax,[vk] ; determine which texture should be used
695
    and eax,255
272 serge 696
 
31 halyavin 697
    cmp eax,1
698
    jne checkmore1
699
    add edi,ceil
700
    jmp foundtex
701
    checkmore1:
272 serge 702
 
31 halyavin 703
    cmp eax,2
704
    jne checkmore2
705
    add edi,wall
706
    jmp foundtex
707
    checkmore2:
272 serge 708
 
31 halyavin 709
    cmp eax,3
710
    jne checkmore3
711
    add edi,wall2
712
    jmp foundtex
713
    checkmore3:
272 serge 714
 
31 halyavin 715
    cmp eax,4
716
    jne checkmore4
717
    add edi,wall3
718
    jmp foundtex
719
    checkmore4:
272 serge 720
 
31 halyavin 721
    cmp eax,5
722
    jne checkmore5
723
    add edi,wall4
724
    jmp foundtex
725
    checkmore5:
272 serge 726
 
31 halyavin 727
    cmp eax,6
728
    jne checkmore6
729
    add edi,wall5
730
    jmp foundtex
731
    checkmore6:
272 serge 732
 
31 halyavin 733
    cmp eax,7
734
    jne checkmore7
735
    add edi,wall6
736
    jmp foundtex
737
    checkmore7:
272 serge 738
 
31 halyavin 739
    cmp eax,8
740
    jne checkmore8
741
    add edi,wall7
742
    jmp foundtex
743
    checkmore8:
272 serge 744
 
31 halyavin 745
    foundtex:
272 serge 746
 
31 halyavin 747
    mov edx,[edi]    ; get pixel color inside texture
272 serge 748
 
31 halyavin 749
; ***pseudoshade south-west
750
jmp east ; activate this for southwest pseudoshade : a bit slower + blink-bug
751
    mov edi,[yfrac]
752
    mov [pseudo],dword 0 ; store flag for custom distance darkening
753
    cmp edi,[xfrac]
754
    jge east
755
    and edx,0x00FEFEFE
756
    shr edx,1
757
    mov [pseudo],dword 1
758
east:
272 serge 759
 
31 halyavin 760
 call dark_distance ; deactivate wall distance darkening: a bit faster
272 serge 761
 
31 halyavin 762
; ******* DRAW WALL PIXEL *******
763
    mov eax,esi
272 serge 764
;    sub eax,22
765
    lea eax, [esi-22]
31 halyavin 766
    imul eax,1920
272 serge 767
;    add eax,[vx1]
768
;    add eax,[vx1]
769
;    add eax,[vx1]
770
;    add eax,0x80000
771
    mov ebx, [vx1]
772
    lea ebx, [ebx+ebx*2]
773
    lea eax, [eax+0x80000+ebx]
774
 
31 halyavin 775
    cmp eax,0x80000+1920*480
776
    jg dont_draw
777
    cmp eax,0x80000
778
    jb dont_draw
779
    mov [eax],edx ; actually set the pixel in the image
780
; *** eo draw wall pixel
781
dont_draw:
782
    mov edi,[remedi]
783
speedup:
784
    cmp esi,[vbottom]  ; end of this column?
785
    jg pixelrow
272 serge 786
 
31 halyavin 787
    mov edi,[vl]  ; restoring
788
    mov eax,[vx1] ; inc X1
789
    add eax,1
790
    mov [vx1],eax
272 serge 791
 
31 halyavin 792
    ;*** NEXT A ***
793
    mov esi,[va]
794
    sub esi,1
795
    mov [va],esi
796
    cmp esi,[vacompare]
797
    jg for_a
798
    ;*** EO NEXT A ***
799
;---------------------------------------------------------------------------
272 serge 800
 
801
 
31 halyavin 802
; **** put image !!!!!****
803
; ***********************
804
    mov eax,7
805
    mov ebx,0x80000
806
    mov ecx,640*65536+480
316 heavyiron 807
    xor edx,edx
485 heavyiron 808
    mcall
272 serge 809
 
31 halyavin 810
    ret
272 serge 811
 
31 halyavin 812
blur:
272 serge 813
 
31 halyavin 814
pusha
815
mov eax,0x080000+360*1920
272 serge 816
 
31 halyavin 817
copyfloor2:
818
    add eax,1920
272 serge 819
;    mov ebx,eax
820
;    add ebx,[vx1]
821
;    add ebx,[vx1]
822
;    add ebx,[vx1]
823
    mov ebx,[vx1]
824
    lea ebx, [ebx+ebx*2]
825
    add ebx, eax
826
 
827
 
31 halyavin 828
    mov ecx,[ebx-15]
829
    and ecx,0x00FEFEFE
830
    shr ecx,1
831
    mov edx,[ebx-12]
832
    and edx,0x00FEFEFE
833
    shr edx,1
834
    add edx,ecx
835
    and edx,0x00FEFEFE
836
    shr edx,1
272 serge 837
 
31 halyavin 838
     mov ecx,[ebx-9]
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-6]
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-3]
855
       and ecx,0x00FEFEFE
856
       shr ecx,1
857
       add edx,ecx
272 serge 858
 
31 halyavin 859
        and edx,0x00FEFEFE
860
        shr edx,1
272 serge 861
 
31 halyavin 862
        mov ecx,[ebx]
863
        and ecx,0x00FEFEFE
864
        shr ecx,1
865
        add edx,ecx
272 serge 866
 
31 halyavin 867
    mov [ebx],edx
272 serge 868
 
31 halyavin 869
    cmp eax,0x80000+478*1920
870
    jb copyfloor2
272 serge 871
 
31 halyavin 872
popa
272 serge 873
 
31 halyavin 874
ret
272 serge 875
 
876
 
877
 
31 halyavin 878
; ******* Darken by Distance *******
879
dark_distance:
272 serge 880
 
31 halyavin 881
; color must be in edx, wall height in [vdd]
272 serge 882
 
31 halyavin 883
    mov eax,[vdd]
884
    cmp eax,50
885
    jg nodark
886
    ;                split rgb
272 serge 887
 
31 halyavin 888
    mov [blue],edx
889
    and [blue],dword 255
272 serge 890
 
31 halyavin 891
    shr edx,8
892
    mov [green],edx
893
    and [green],dword 255
272 serge 894
 
31 halyavin 895
    shr edx,8
896
    mov [red],edx
897
    and [red],dword 255
272 serge 898
 
31 halyavin 899
    mov eax,51    ; darkness parameter
900
    sub eax,[vdd]
901
    cmp [pseudo],dword 1
902
    je isdarkside
903
    sal eax,2
904
isdarkside:
272 serge 905
 
31 halyavin 906
;                        reduce rgb
907
    sub [red],eax
908
    cmp [red], dword 0
909
    jg notblack10b
910
    mov [red],dword 0
911
    notblack10b:
272 serge 912
 
31 halyavin 913
    sub [green],eax
914
    cmp [green],dword 0
915
    jg notblack20b
916
    mov [green],dword 0
917
    notblack20b:
272 serge 918
 
31 halyavin 919
    mov edx,[blue]
920
    sub [blue],eax
921
    cmp [blue],dword 0
922
    jg notblack30b
923
    mov [blue],dword 0
924
    notblack30b:
272 serge 925
 
31 halyavin 926
    shl dword [red],16 ; reassemble rgb
927
    shl dword [green],8
928
    mov edx,[red]
929
    or edx,[green]
930
    or edx,[blue]
931
    mov eax,edx
272 serge 932
 
31 halyavin 933
nodark:
272 serge 934
 
31 halyavin 935
    ret
272 serge 936
 
937
 
31 halyavin 938
; DATA AREA
272 serge 939
 
31 halyavin 940
;ceil=ceil
941
;wall=wall floor
942
;2 corner stone
943
;3 leaf mosaic
944
;4 closed window
945
;5 greek mosaic
946
;6 old street stones
947
;7 maya wall
272 serge 948
 
31 halyavin 949
grid:  ; 32*32 Blocks, Map: 0 = Air, 1 to 8 = Wall
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
951
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
952
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
953
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
954
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
955
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
956
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
957
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
958
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
959
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
960
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
961
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
962
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
963
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
964
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
965
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
966
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
967
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
968
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
969
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
970
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
971
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
972
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
973
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
974
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
975
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
976
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
977
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
978
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
979
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
980
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
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
272 serge 982
 
37 halyavin 983
vpx:
984
dd 0x0001FFFF ; initial player position * 0xFFFF
985
 vpy:
986
dd 0x0001FFFF
272 serge 987
 
485 heavyiron 988
title    db   'FISHEYE RAYCASTING ENGINE ETC. FREE3D',0
272 serge 989
 
37 halyavin 990
sindegree dd 0.0
991
sininc    dd 0.0017453292519943295769236907684886
272 serge 992
sindiv    dd 6553.5
37 halyavin 993
textures:
994
	file 'texture.gif'
272 serge 995
 
996
align 4
997
 
31 halyavin 998
col1:
37 halyavin 999
 dd ?;-
31 halyavin 1000
; misc raycaster vars:
1001
vxx:
37 halyavin 1002
 dd ?;-
31 halyavin 1003
vyy:
37 halyavin 1004
 dd ?;-
31 halyavin 1005
vl:
37 halyavin 1006
 dd ?;-
31 halyavin 1007
vstepx:
37 halyavin 1008
 dd ?;-
31 halyavin 1009
vstepy:
37 halyavin 1010
 dd ?;-
31 halyavin 1011
vxxint:
37 halyavin 1012
 dd ?;-
31 halyavin 1013
vyyint:
37 halyavin 1014
 dd ?;-
31 halyavin 1015
vk:
37 halyavin 1016
 dd ?;-
31 halyavin 1017
va:
37 halyavin 1018
 dd ?;-
31 halyavin 1019
va2:
37 halyavin 1020
 dd ?;-
31 halyavin 1021
vdd:
37 halyavin 1022
 dd ?;-
31 halyavin 1023
vx1:
37 halyavin 1024
 dd ?;-
31 halyavin 1025
vx1b:
37 halyavin 1026
 dd ?;-
31 halyavin 1027
vh:
37 halyavin 1028
 dd ?;-
31 halyavin 1029
vdt:
37 halyavin 1030
 dd ?;-
31 halyavin 1031
vheading: ; initial heading: 0 to 3599
37 halyavin 1032
 dd ?;-
31 halyavin 1033
vacompare:
37 halyavin 1034
 dd ?;-
31 halyavin 1035
vpxi:
37 halyavin 1036
 dd ?;-
31 halyavin 1037
vpyi:
37 halyavin 1038
 dd ?;-
31 halyavin 1039
wtolong:
37 halyavin 1040
 dw ?,?;-,?;-
272 serge 1041
 
31 halyavin 1042
xtemp:
37 halyavin 1043
 dd ?;-
31 halyavin 1044
ytemp:
37 halyavin 1045
 dd ?;-
31 halyavin 1046
xfrac:
37 halyavin 1047
 dd ?;-
31 halyavin 1048
yfrac:
37 halyavin 1049
 dd ?;-
31 halyavin 1050
h_old:
37 halyavin 1051
 dd ?;-
31 halyavin 1052
vbottom:
37 halyavin 1053
 dd ?;-
31 halyavin 1054
mouseya:
37 halyavin 1055
 dd ?;-
31 halyavin 1056
remeax:
37 halyavin 1057
 dd ?;-
31 halyavin 1058
remebx:
37 halyavin 1059
 dd ?;-
31 halyavin 1060
remecx:
37 halyavin 1061
 dd ?;-
31 halyavin 1062
remedx:
37 halyavin 1063
 dd ?;-
31 halyavin 1064
remedi:
37 halyavin 1065
 dd ?;-
31 halyavin 1066
remesi:
37 halyavin 1067
 dd ?;-
31 halyavin 1068
red:
37 halyavin 1069
 dd ?;-
31 halyavin 1070
green:
37 halyavin 1071
 dd ?;-
31 halyavin 1072
blue:
37 halyavin 1073
 dd ?;-
31 halyavin 1074
pseudo:
37 halyavin 1075
 dd ?;-
31 halyavin 1076
step1:
37 halyavin 1077
 dd ?;-
31 halyavin 1078
step64:
37 halyavin 1079
 dd ?;-
31 halyavin 1080
lasty:
37 halyavin 1081
 dd ?;-
272 serge 1082
 
1083
I_END:
552 diamond 1084
IncludeUGlobals
272 serge 1085
sinus rd 360*10
37 halyavin 1086
eosinus: