Subversion Repositories Kolibri OS

Rev

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