home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / graphic / voxel.asm < prev    next >
Assembly Source File  |  1995-07-28  |  4KB  |  135 lines

  1. data segment
  2.   extrn vscreen:dword           ;pointer to landscape data
  3.   extrn x,y: word               ;coordinates of trapezoid
  4.   extrn vpage:word              ;current video page
  5. data ends
  6.  
  7. code segment
  8. assume cs:code,ds:data
  9.  
  10.  
  11. ;variables with fractional part (lower 8 bits):
  12.  
  13. offst dd 0                      ;current offset
  14. step dd 0                       ;pixel size
  15. row_start dd 0                  ;beginning of current row
  16. row_step dd 0                   ;distance from next row
  17.  
  18.  
  19. r_count dw 0                    ;counter for depth
  20. shrink dw 0                     ;correction on lower screen border
  21.  
  22. row dd 0                        ;current screen row number
  23. vpage_cs dw 0                   ;video page in the code segment
  24.  
  25.  
  26. .386
  27. public Draw_Voxel
  28. Draw_Voxel proc pascal
  29. ;shows landscape on current video page
  30. ;reads data from vscreen starting from position (x/y)
  31.  
  32.   mov ax,vpage                  ;note number of video page
  33.   mov vpage_cs,ax
  34.  
  35.   push ds
  36.   mov ax,0a000h                 ;load destination segment
  37.   mov es,ax
  38.  
  39.   mov ax,320                    ;calculate offset in landscape
  40.   imul y
  41.   add ax,x
  42.  
  43.   lds si,vscreen                ;take data from vscreen
  44.   add si,ax                     ;add offset
  45.   shl esi,8                     ;convert to fixed point number
  46.  
  47.   mov offst,esi                 ;initial values for pixel ...
  48.   mov row_start,esi             ;... and row
  49.  
  50.   mov step,100h                 ;first scaling factor 1
  51.   mov row,100*256               ;begin in screen row 100
  52.   mov row_step,14040h           ;distance of rows 320,25
  53.   mov shrink,0                  ;first no correction
  54.   mov r_count,160               ;number of rows to calculate
  55.  
  56. next_y:
  57.   mov eax,row                   ;get current (screen) row number
  58.   mov ebx,eax                   ;store
  59.   shr eax,8                     ;convert to whole number
  60.   add eax,50                    ;50 pixels down
  61.   imul eax,80                   ;convert to offset
  62.   mov di,ax                     ;store as destination pointer
  63.  
  64.   cmp di,199*80                 ;screen border exceeded ?
  65.   jb normal
  66.   mov di,199*80                 ;yes, then position on last row
  67.  
  68.   mov eax,row                   ;difference to bottom screen border
  69.   shr eax,8
  70.   sub eax,149
  71.   mov shrink,ax                 ;and note as correction
  72.  
  73. normal:
  74.   add di,vpage_cs               ;add current video page
  75.  
  76.   imul ebx,16500                ;multiply row number by 1,007
  77.   shr ebx,14                    ;calculate * 16500 / 16384
  78.   mov row,ebx                   ;and store
  79.  
  80.   mov bp,80                     ;number of pixels per row
  81. next_x:
  82.   mov esi,offst                 ;load current pixel offset
  83.   shr esi,8                     ;convert to whole number
  84.   xor eax,eax
  85.   mov al,[si]                   ;load dot from landscape
  86.   mov cx,ax                     ;store
  87.  
  88.   cmp cx,99                     ;color (=height) < 100
  89.   ja fill_bar
  90.   mov ax,99                     ;then set to 99
  91.  
  92. fill_bar:
  93.   shl ax,5                      ;vanishing point projection: height * 32
  94.   xor dx,dx
  95.   push bp
  96.   mov bp,r_count                ;divides by the distance
  97.   add bp,50
  98.   idiv bp
  99.   pop bp
  100.  
  101.   sub ax,shrink                 ;perform correction
  102.   jbe continue                  ;if <= 0, don't even draw
  103.  
  104.   push di
  105. next_fill:
  106.   mov es:[di],cl                ;enter color
  107.   sub di,80                     ;address next highest row
  108.   dec al                        ;decrement counter
  109.   jne next_fill                 ;continue ?
  110.   pop di
  111.  
  112. continue:
  113.   inc di                        ;address next byte on the screen
  114.   mov esi,step                  ;get step
  115.   add esi,offst                 ;increment
  116.   mov offst,esi                 ;and rewrite
  117.  
  118.   dec bp                        ;next dot
  119.   jne next_x
  120.  
  121.   mov esi,row_step              ;shift beginning of row
  122.   add esi,row_start
  123.   mov row_start,esi
  124.   mov offst,esi                 ;reload pixel offset also
  125.  
  126.   dec step                      ;decrement scaling factor
  127.   dec r_count                   ;continue row counter
  128.   jne next_y
  129.   pop ds
  130.   ret
  131. Draw_Voxel endp
  132.  
  133. code ends
  134. end
  135.