home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / gallery / a_render.asm < prev    next >
Assembly Source File  |  1993-07-21  |  7KB  |  290 lines

  1. ;  A_RENDER.ASM -- draws scenery // A.R-M. 7/93
  2.  
  3.         IDEAL
  4.         MODEL Compact, Pascal
  5.         RADIX 10
  6.         P286
  7.  
  8.         INCLUDE "globals.inc"
  9.         INCLUDE "a_ray_t.inc"        ; include SRay type def
  10.  
  11. SideMargin = (160-WindowWidth/2)/16  ; margin before screen start
  12.  
  13. MACRO   TURN TurnAngle
  14.         push [Ray]
  15.         push TurnAngle
  16.         call TurnRay
  17.         ENDM
  18.  
  19.         DATASEG
  20.  
  21. EXTRN Column0 : Byte
  22. EXTRN NumberOfBearings : Word
  23. EXTRN ScrHeight : Word
  24.  
  25. RenderRay       SRay    <>
  26.  
  27.  
  28.         CODESEG
  29.  
  30. EXTRN FillWithFloorSky : NEAR
  31.  
  32. EXTRN ShootRay    : NEAR
  33. EXTRN Project     : NEAR
  34. EXTRN Dump16cols  : NEAR
  35.  
  36. PUBLIC Render           ;(Ray:Near ptr; WallTextures:Near ptr)
  37. PUBLIC TurnRay          ;(Ray:Near ptr; Angle:integer)
  38. PUBLIC AdvanceRay       ;(Ray:Near ptr; AdvX,AdvY : integer);
  39.  
  40. ; Note: WallTextures format:
  41. ;
  42. ;           dd  P(south), P(west), P(north), P(east)  ; wall code 1
  43. ;           dd  P(south), P(west), P(north), P(east)  ; wall code 2
  44. ;           . . . . . . . . . . . . . . . . . . . . .
  45. ;           dd  P(south), P(west), P(north), P(east)  ; wall code n
  46.  
  47. ; where P(north) = seg:ofs pointer to texture for north side of
  48. ; wall, etc.  (wall code 0 is reserved for empty squares)
  49.  
  50.  
  51.         PROC Render NEAR
  52.         ARG Ray : NEAR PTR SRay, WallTextures : NEAR PTR
  53.         LOCAL SaveSector : Word, SaveAngle : Word, SaveLength : Word, \
  54.               ColumnAddress : Word, \
  55.               ScrOfs : Word, Xcoord : Word, Xblock : Word, \
  56.               Step : Word, ColMask : Word
  57.           pusha
  58.  
  59.           mov di, [Ray]
  60.           mov ax, [di+SRay.Angle]
  61.           mov bx, [di+SRay.Sector]
  62.           mov cx, [di+SRay.Length]
  63.           mov [SaveAngle], ax
  64.           mov [SaveSector],bx
  65.           mov [SaveLength], cx
  66.  
  67.           Turn +160d-16d*SideMargin
  68.  
  69.           xor ax, ax
  70.           mov [di+SRay.Length], ax ; set length to 0
  71.  
  72.           mov ax, 100d           ; center screen vertically
  73.           mov bx, [ScrHeight]
  74.           shr bx,1
  75.           sub ax, bx             ; ax = 100-ScrHeight/2
  76.           shl ax,4
  77.           mov bx, ax
  78.           shl ax,2
  79.           add bx, ax             ; bx = (100-ScrHeight/2)*80
  80.           add bx, 4*SideMargin
  81.  
  82.           mov [ScrOfs], bx
  83.  
  84. ; Loop for 1 to 20 16-pixel blocks ─┐
  85.  
  86.           mov [Xcoord], 16d*SideMargin
  87.           mov [Xblock], 0
  88.  
  89.           mov cx, 20d-2*SideMargin
  90. @@loop1:  push cx
  91.  
  92.           mov [ColMask], 1
  93.  
  94. ; Loop for 1 to 4 Mask offsets at same addr ─┐
  95.  
  96.           mov [ColumnAddress], offset Column0
  97.           call FillWithFloorSky
  98.  
  99.           mov cx, 4
  100. @@loop2:  push cx
  101.  
  102.           mov [Step], 0
  103.  
  104. ; Loop for 1 to 4 bytes in a dword ─┐
  105.  
  106.           mov cx, 4
  107. @@loop3:  push cx
  108.  
  109.           push [Ray]                 ; = offset Ray
  110.           push offset RenderRay
  111.           call ShootRay
  112.  
  113. ; ┌─ - - - -  DRAW ONE COLUMN  - - - - - ─┐
  114.  
  115. ; RenderRay.Length = path length
  116. ;               al = contents code
  117. ;               ah = wall side (0..3)
  118. ;               dx = offset along wall (0..32767)
  119.  
  120.           push ax
  121.           dec al
  122.           xor bx, bx
  123.           add bl, al
  124.           shl bx, 2                   ; bx = offset WallTextures
  125.           add bl, ah                  ;      + 16*(contents code, al)
  126.           shl bx, 2                   ;      +  4*(wall side, ah)
  127.           add bx, [WallTextures]
  128.  
  129.           les di, [dword ptr bx]      ; es:di -> Texture
  130.  
  131. IF TexRes EQ 128d
  132.           xor dl, dl
  133.           shr dx,1                    ; dx now from (0..127)*128
  134. ENDIF
  135. IF TexRes EQ 64d
  136.           and dx, 0111111000000000b
  137.           shr dx, 3                   ; dx now from (0..63)*64
  138. ENDIF
  139.           add di, dx                  ; es:di -> Texture[column]
  140.  
  141.           pop ax
  142.           push ds
  143.           push [ColumnAddress]
  144.           push es
  145.           push di                     ; FAR PTR to column of texture
  146.           push ax                     ; wall side
  147.           push [Step]                 ; 0,1,2,3 column no. in dword
  148.           push [Xcoord]
  149.           mov dx, [RenderRay.Length]
  150.           push dx                     ; distance for projection
  151.           call Project                ; project column on screen
  152.  
  153. ; └─ - - - - - - - - - - - - - - - - - - ─┘
  154.  
  155.           inc [Step]
  156.           Turn -4
  157.           add [Xcoord],4
  158.  
  159.           pop cx
  160.           loop @@loop3
  161.  
  162. ; end for bytes in a dword ─┘
  163.  
  164.           add [ColumnAddress], 200d*4
  165.  
  166.           shl [ColMask],1
  167.           Turn +15
  168.           sub [Xcoord],15
  169.  
  170.           pop cx
  171.           loop @@loop2
  172.  
  173. ; end for mask values ─┘
  174.  
  175.           push [ScrOfs]               ; ofs in current page
  176.           push [Xblock]
  177.           call Dump16cols             ; dump 4 cols to screen
  178.  
  179.           add [ScrOfs], 4
  180.           Turn -12
  181.           add [Xcoord],12
  182.  
  183.           inc [Xblock]
  184.           pop cx
  185.  
  186.           loop @@OutOf
  187.           jmp @@Range
  188. @@OutOf:  jmp @@loop1    ; this was a "loop @@loop1", but it got
  189. @@Range:                 ; one miserable byte out of range!
  190.  
  191. ; end for the 20 16-pixel blocks ─┘
  192.  
  193. ; restore Ray's bearing & length
  194.  
  195.           mov di, [Ray]
  196.           mov ax, [SaveAngle]
  197.           mov bx, [SaveSector]
  198.           mov cx, [SaveLength]
  199.           mov [di+SRay.Angle], ax
  200.           mov [di+SRay.Sector],bx
  201.           mov [di+SRay.Length],cx
  202.  
  203.           popa
  204.           ret
  205.         ENDP
  206.  
  207. ; Another little message for debugger fans:
  208.  
  209.         db '. Hiya, there! How''s it going? :-) // ARM .'
  210.  
  211. ; // TurnRay
  212.  
  213.         PROC TurnRay NEAR
  214.         ARG Ray : NEAR PTR SRay, TurnAngle : Word
  215.         USES ax, bx, cx, di
  216.  
  217.           mov cx, [NumberOfBearings]
  218.  
  219.           mov di, [Ray]
  220.           mov ax, [di+SRay.Angle]
  221.           mov bx, [di+SRay.Sector]
  222.  
  223.           add ax, [TurnAngle]
  224.           js @@negative
  225.           cmp ax, cx
  226.           jl @@leave
  227.  
  228. @@positive:
  229.           inc bx
  230.           cmp bx,8
  231.           jne @@2
  232.           xor bx,bx
  233. @@2:      sub ax, cx
  234.           cmp ax, cx
  235.           jge @@positive
  236.           jmp @@leave
  237.  
  238. @@negative:
  239.           dec bx
  240.           jns @@1
  241.           mov bx, 7
  242. @@1:      add ax, cx
  243.           js @@negative
  244.  
  245. @@leave:
  246.           mov [di+SRay.Sector], bx
  247.           mov [di+SRay.Angle], ax
  248.           ret
  249.         ENDP
  250.  
  251.  
  252. ; // AdvanceRay
  253.  
  254.         PROC AdvanceRay NEAR
  255.         ARG Ray : NEAR PTR SRay, AdvX : Word, AdvY : Word
  256. P386
  257.           mov di, [Ray]
  258.  
  259.           movzx ax, [di+SRay.MapX]
  260.           shl eax,16
  261.           mov bx, [di+SRay.FineX]
  262.           shl bx,1
  263.           mov ax,bx
  264.           movzx ebx, [AdvX]
  265.           add eax,ebx
  266.           shr ax,1
  267.           mov [di+SRay.FineX], ax
  268.           shr eax,16
  269.           mov [di+SRay.MapX], al
  270.  
  271.           movzx ax, [di+SRay.MapY]
  272.           shl eax,16
  273.           mov bx, [di+SRay.FineY]
  274.           shl bx,1
  275.           mov ax,bx
  276.           movzx ebx, [AdvY]
  277.           add eax,ebx
  278.           shr ax,1
  279.           mov [di+SRay.FineY], ax
  280.           shr eax,16
  281.           mov [di+SRay.MapY], al
  282.  
  283. P286
  284.           ret
  285.         ENDP
  286.  
  287.  
  288.         END
  289.  
  290.