Subversion Repositories Kolibri OS

Rev

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