home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / !FALCON / !BONUS / GAMES / ENGINES / DOOMES19.ZIP / DOOM_ES / BSPD.S < prev    next >
Text File  |  1997-06-16  |  26KB  |  724 lines

  1. *=======================================================*
  2. *    BSP-Descent: latest update 25/03/96        *
  3. *=======================================================*
  4. *    Descend BSP tree, generating sectors & walls.    *
  5. *=======================================================*
  6.  
  7. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  8. *    Descend Binary Space Partitioning Tree        *
  9. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  10.     txtlong
  11. *-------------------------------------------------------*
  12. descend_bsp:
  13. *-------------------------------------------------------*
  14. *    Place start & terminator on heap and descend    *
  15. *-------------------------------------------------------*
  16.     move.l        sp,bsp_return
  17.     lea        display_struct,a6
  18.     move.w        NumNodes,d0
  19.     push.w        #terminator
  20.     subq.w        #1,d0
  21.     push.w        d0
  22.     bra        next_node
  23. *-------------------------------------------------------*
  24. *    Thread returns here when tree is exhausted    *
  25. *-------------------------------------------------------*
  26. finish_tree:
  27. *-------------------------------------------------------*
  28.     move.l        bsp_return,sp
  29.     rts
  30.  
  31. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  32. *    [node] = [sector] -> draw this node        *
  33. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  34.     txtlong
  35. *-------------------------------------------------------*
  36. ssector_node:
  37. *-------------------------------------------------------*
  38. *    Stop drawing when [width] columns are filled    *
  39. *-------------------------------------------------------*
  40.     tst.w        display_columns(a6)
  41.     beq.s        finish_tree
  42. *-------------------------------------------------------*
  43. *    Stop drawing when last node has been popped    *
  44. *-------------------------------------------------------*
  45.     not.w        d0
  46.     beq.s        finish_tree
  47.     eor.w        #$7FFF,d0
  48.  
  49. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  50. *    Render ssector into run-buffer            *
  51. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  52. build_ssector:
  53. *-------------------------------------------------------*
  54. *    Locate [segs] for this [ssector]        *
  55. *-------------------------------------------------------*
  56.     move.l        display_ssectors(a6),a0
  57.     move.w        ssec_first(a0,d0.w*4),d4
  58.     move.w        ssec_segments(a0,d0.w*4),d3
  59. *-------------------------------------------------------*
  60. *    Locate [linedef] & [sidedef] for first [seg]    *
  61. *-------------------------------------------------------*
  62.     move.l        display_segs(a6),a2
  63.     move.w        d4,d2
  64.     mulu.w        #seg_len,d2
  65.     add.l        d2,a2
  66.     move.w        seg_linedef(a2),d0
  67.     move.w        seg_sidedef(a2),d2
  68. *-------------------------------------------------------*
  69. *    Locate right [sidedef] for this [linedef]    *
  70. *-------------------------------------------------------*
  71.     move.l        display_linedefs(a6),a0
  72.     mulu.w        #linedef_len,d0
  73.     add.l        d0,a0
  74.     move.w        linedef_right(a0,d2.w*2),d1 
  75. *-------------------------------------------------------*
  76. *    Locate [sector] for this [sidedef]        *
  77. *-------------------------------------------------------*
  78.     move.l        display_sidedefs(a6),a0
  79.     mulu.w        #sidedef_len,d1
  80.     add.l        d1,a0
  81.     move.w        sidedef_sector(a0),d1    
  82. *-------------------------------------------------------*
  83. *    Set up floor & ceiling heights for this sector    *
  84. *-------------------------------------------------------*
  85.     move.l        display_sectors(a6),a0
  86.     mulu.w        #sector_len,d1
  87.     add.l        d1,a0
  88.     move.l        a0,display_sectorptr(a6)
  89. *-------------------------------------------------------*
  90.     move.w        sector_floorht(a0),display_fh(a6)
  91.     move.w        sector_ceilht(a0),display_ch(a6)
  92.     move.w        sector_ftns(a0),display_ft(a6)
  93.     move.w        sector_ctns(a0),display_ct(a6)
  94. *-------------------------------------------------------*
  95. *    Are we in this sector?                *
  96. *-------------------------------------------------------*
  97.     tst.b        display_firstssec(a6)
  98.     beq.s        .skip
  99.     clr.b        display_firstssec(a6)
  100. *-------------------------------------------------------*
  101. *    Set viewcone to (sector_height+player_height)    *
  102. *-------------------------------------------------------*
  103.     move.w        display_fh(a6),d0
  104.     add.w        #player_height,d0
  105.     add.w        pho,d0
  106.     move.w        d0,display_ph(a6)
  107. *-------------------------------------------------------*
  108. *    Set up segment-heap for loop            *
  109. *-------------------------------------------------------*
  110. .skip:    move.l        d4,d2
  111.     move.w        d2,display_segbase(a6)
  112.     move.w        d3,display_segnum(a6)
  113.     ble        next_node
  114. *-------------------------------------------------------*
  115. *    Process simple lighting effects (temporary!)    *
  116. *-------------------------------------------------------*
  117.     bsr        process_lighting
  118. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  119. *    Render segments surrounding this ssector    *
  120. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  121. segment_loop:
  122. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  123. *    Hidden surface removal stage #1            *
  124. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  125. *    Is viewer on left or right side of this line?    *
  126. *-------------------------------------------------------*
  127. *    ((y2-y1)*(x1-Px))) => (((x2-x1)*(y1-Py)) ?    *
  128. *-------------------------------------------------------*
  129.     move.l        display_vertices(a6),a0
  130.     moveq        #0,d0
  131.     moveq        #0,d1
  132.     move.w        linedef_from(a2),d0
  133.     move.w        linedef_to(a2),d1
  134.     move.w        vtx_x(a0,d0.l*4),d5
  135.     move.w        vtx_x(a0,d1.l*4),d6
  136.     move.w        vtx_y(a0,d0.l*4),d0
  137.     move.w        vtx_y(a0,d1.l*4),d1
  138.     sub.w        d5,d6            ; x2-x1
  139.     sub.w        d0,d1            ; y2-y1
  140.     sub.w        display_px(a6),d5    ; x1-px
  141.     sub.w        display_py(a6),d0    ; y1-py
  142.     muls.w        d6,d0            ; (x2-x1)*(y1-Py)
  143.     muls.w        d5,d1            ; (x1-px)*(y2-y1)
  144.     cmp.l        d0,d1
  145.     bpl        invisible
  146. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  147. *    Segment is visible                *
  148. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  149.     pea        (a2)
  150. *-------------------------------------------------------*
  151.     move.w        display_segbase(a6),d0
  152.     move.l        display_segs(a6),a5
  153.     mulu.w        #seg_len,d0
  154.     add.l        d0,a5
  155. *-------------------------------------------------------*
  156. *    Locate segment vertices                *
  157. *-------------------------------------------------------*
  158.     move.l        seg_length(a5),umag
  159.     move.w        seg_distance(a5),x_offset
  160.     move.l        display_vertices(a6),a0
  161.     moveq        #0,d0
  162.     move.w        seg_from(a5),d0
  163.     move.l        a0,a1
  164.     moveq        #0,d1
  165.     move.w        seg_to(a5),d1 
  166.     lsl.l        #2,d0
  167.     lsl.l        #2,d1
  168.     add.l        d0,a0            ; a+(d*4)
  169.     add.l        d1,a1            ; a+(d*4)
  170. *-------------------------------------------------------*
  171. *    Fetch X1,Y1 / X2,Y2 & centre around viewpoint    *
  172. *-------------------------------------------------------*
  173.     lea        DSPHostStat.w,a2
  174.     lea        DSPHost16.w,a3
  175.     dspwaitwrite.0    (a2)
  176.     move.w        #projectwall_command,(a3)
  177.     dspwaitwrite.0    (a2)
  178.     move.w        (a0)+,(a3)
  179.     dspwaitwrite.0    (a2)
  180.     move.w        (a0)+,(a3)
  181.     dspwaitwrite.0    (a2)
  182.     move.w        (a1)+,(a3)
  183.     dspwaitwrite.0    (a2)
  184.     move.w        (a1)+,(a3)
  185.     lea        DSPHost32.w,a4
  186.     dspwaitread.0    (a2)
  187.     tst.w        (a3)
  188.     beq        end_segment
  189.     dspwaitread.0    (a2)
  190.     move.l        (a4),d3
  191.     lsl.l        #8,d3
  192.     dspwaitread.0    (a2)
  193.     move.l        (a4),d4
  194.     lsl.l        #8,d4
  195.     dspwaitread.0    (a2)
  196.     move.l        (a4),d5
  197.     lsl.l        #8,d5
  198.     dspwaitread.0    (a2)
  199.     move.l        (a4),d6
  200.     lsl.l        #8,d6
  201.     dspwaitread.0    (a2)
  202.     move.l        (a4),d1
  203.     lsl.l        #8,d1
  204.     dspwaitread.0    (a2)
  205.     move.l        (a4),d2
  206.     lsl.l        #8,d2
  207. *-------------------------------------------------------*
  208. *    Write coordinates into addwall struct        *
  209. *-------------------------------------------------------*
  210. .draw:    move.l        d1,addwall_rz2(a6)
  211.     move.l        d2,addwall_rz1(a6)
  212.     move.l        d3,addwall_i1(a6)
  213.     move.l        d4,addwall_z1(a6)
  214.     move.l        d5,addwall_i2(a6)
  215.     move.l        d6,addwall_z2(a6)
  216. *-------------------------------------------------------*
  217. *    Look up linedef for this seg            *
  218. *-------------------------------------------------------*
  219.     move.w        seg_linedef(a5),d1
  220.     move.l        display_linedefs(a6),a0
  221.     mulu.w        #linedef_len,d1
  222.     add.l        d1,a0
  223. *-------------------------------------------------------*
  224. *    Determine one or two-sided linedef        *
  225. *-------------------------------------------------------*
  226.     move.w        linedef_attrib(a0),d0
  227.     or.w        #$100,linedef_attrib(a0)
  228.     move.b        d0,linedef_flags
  229.     and.b        #attrib_twosided,d0
  230.     move.b        d0,twosided_flag
  231. *-------------------------------------------------------*
  232. *    Determine which sidedef is facing us        *
  233. *-------------------------------------------------------*
  234.     move.w        seg_sidedef(a5),d0
  235.     move.w        linedef_right(a0,d0.w*2),d5    ; visible sidedef
  236.     bchg        #0,d0
  237.     move.w        linedef_right(a0,d0.w*2),d6    ; invisible sidedef
  238. *-------------------------------------------------------*
  239. *    Look up sidedef for visible side of linedef    *
  240. *-------------------------------------------------------*
  241.     move.l        display_sidedefs(a6),a3
  242.     mulu.w        #sidedef_len,d5
  243.     move.l        a3,a4
  244.     add.l        d5,a3
  245. *-------------------------------------------------------*
  246. *    Locate [sector] on opposite side of [linedef]    *
  247. *-------------------------------------------------------*
  248.     tst.b        twosided_flag
  249.     beq.s        .nts
  250.     mulu.w        #sidedef_len,d6
  251.     add.l        d6,a4
  252.     move.w        sidedef_sector(a4),d6        ; a+(d*30)
  253.     move.l        display_sectors(a6),a4
  254.     mulu.w        #sector_len,d6
  255.     add.l        d6,a4
  256. .nts:    move.b        #0,addwall_opaque(a6)
  257.     tst.b        twosided_flag
  258.     beq        sector_wall
  259.  
  260. *-------------------------------------------------------*
  261. *    Check for lower wall texture            *
  262. *-------------------------------------------------------*
  263. lower_texture:
  264. *-------------------------------------------------------*
  265.     move.l        display_sectorptr(a6),a5
  266.     move.w        sidedef_ltns(a3),d0
  267. *-------------------------------------------------------*
  268. *    Determine wall height                *
  269. *-------------------------------------------------------*
  270.     move.w        sector_floorht(a4),d1
  271.     cmp.w        sector_ceilht(a5),d1
  272.     bmi.s        .clip
  273.     move.w        sector_ceilht(a5),d1
  274. .clip:    move.w        sector_floorht(a5),d2 
  275.     neg.w        d1
  276.     add.w        display_ph(a6),d1
  277.     neg.w        d2
  278.     add.w        display_ph(a6),d2
  279. *-------------------------------------------------------*
  280. *    Render if (y2-y1) <= 0                *
  281. *-------------------------------------------------------*
  282.     cmp.w        d1,d2
  283.     ble.s        optimise_lower
  284. *-------------------------------------------------------*
  285. *    Render if texture valid
  286. *-------------------------------------------------------*
  287.     cmp.w        #texcode_none,d0
  288.     beq.s        ignore_lower
  289. *-------------------------------------------------------*
  290. *    Optimise for identical opposing sectors        *
  291. *-------------------------------------------------------*
  292. optimise_lower:
  293. *-------------------------------------------------------*
  294. *    Force wall if textures differ            *
  295. *-------------------------------------------------------*
  296.     move.w        sector_ftns(a4),d3
  297.     cmp.w        sector_ftns(a5),d3
  298.     bne.s        add_lower
  299. *-------------------------------------------------------*
  300. *    Allow skip if both textures are sky        *
  301. *-------------------------------------------------------*
  302.     cmp.w        sky_index,d3
  303.     beq        ignore_lower
  304. *-------------------------------------------------------*
  305. *    Force wall if floor heights differ        *
  306. *-------------------------------------------------------*
  307.     cmp.w        d1,d2
  308.     bne.s        add_lower
  309. *-------------------------------------------------------*
  310. *    Force wall if lighting methods differ        *
  311. *-------------------------------------------------------*
  312.     move.w        sector_special(a4),d3
  313.     cmp.w        sector_special(a5),d3
  314.     bne.s        add_lower
  315. *-------------------------------------------------------*
  316. *    Force wall if light levels differ        *
  317. *-------------------------------------------------------*
  318.     move.w        sector_light(a4),d3
  319.     cmp.w        sector_light(a5),d3
  320.     beq.s        ignore_lower
  321. *-------------------------------------------------------*
  322. *    Lower wall segment passed all tests        *
  323. *-------------------------------------------------------*
  324. add_lower:
  325. *-------------------------------------------------------*
  326. *    Load wall structure                *
  327. *-------------------------------------------------------*
  328.     cmp.w        d1,d2
  329.     bpl.s        .clip
  330.     move.w        d2,d1
  331.     ble.s        ignore_lower
  332. .clip:    move.w        d1,addwall_y1(a6)
  333.     move.w        d2,addwall_y2(a6)
  334.     move.w        d0,wall_id
  335. *-------------------------------------------------------*
  336. *    Calculate texture pegging            *
  337. *-------------------------------------------------------*
  338.     moveq        #0,d1
  339.     btst        #4,linedef_flags
  340.     beq.s        .np
  341.     move.w        display_ch(a6),d1
  342.     sub.w        sector_floorht(a4),d1
  343. .np:    move.w        d1,peg
  344. *-------------------------------------------------------*
  345. *    Add lower wall to rendering buffer        *
  346. *-------------------------------------------------------*
  347.     move.b        #lower_command,addwall_type(a6)
  348.     bsr        add_wall_segment 
  349. *-------------------------------------------------------*
  350. *    Early abort check                *
  351. *-------------------------------------------------------*
  352.     tst.w        display_columns(a6)
  353.     beq        end_segment         
  354. *-------------------------------------------------------*
  355. ignore_lower:
  356. *-------------------------------------------------------*
  357.  
  358. *-------------------------------------------------------*
  359. *    Check for upper wall texture            *
  360. *-------------------------------------------------------*
  361. upper_texture:
  362. *-------------------------------------------------------*
  363.     move.l        display_sectorptr(a6),a5
  364.     move.w        sidedef_utns(a3),d0
  365. *-------------------------------------------------------*
  366. *    Determine wall height                *
  367. *-------------------------------------------------------*
  368.     move.w        sector_ceilht(a4),d2
  369.     cmp.w        sector_floorht(a5),d2
  370.     bpl.s        .clip
  371.     move.w        sector_floorht(a5),d2
  372. .clip:    move.w        sector_ceilht(a5),d1 
  373.     neg.w        d1
  374.     add.w        display_ph(a6),d1
  375.     neg.w        d2
  376.     add.w        display_ph(a6),d2
  377. *-------------------------------------------------------*
  378. *    Render if (y2-y1) <= 0                *
  379. *-------------------------------------------------------*
  380.     cmp.w        d1,d2
  381.     ble.s        optimise_upper
  382. *-------------------------------------------------------*
  383. *    Render if texture valid
  384. *-------------------------------------------------------*
  385.     cmp.w        #texcode_none,d0
  386.     beq        ignore_upper
  387. *-------------------------------------------------------*
  388. *    Optimise for identical opposing sectors        *
  389. *-------------------------------------------------------*
  390. optimise_upper:
  391. *-------------------------------------------------------*
  392. *    Force wall if textures differ            *
  393. *-------------------------------------------------------*
  394.     move.w        sector_ctns(a4),d3
  395.     cmp.w        sector_ctns(a5),d3
  396.     bne.s        add_upper
  397. *-------------------------------------------------------*
  398. *    Allow skip if both textures are sky        *
  399. *-------------------------------------------------------*
  400.     cmp.w        sky_index,d3
  401.     beq        ignore_upper
  402. *-------------------------------------------------------*
  403. *    Force wall if floor heights differ        *
  404. *-------------------------------------------------------*
  405.     cmp.w        d1,d2
  406.     bne.s        add_upper
  407. *-------------------------------------------------------*
  408. *    Force wall if lighting methods differ        *
  409. *-------------------------------------------------------*
  410.     move.w        sector_special(a4),d3
  411.     cmp.w        sector_special(a5),d3
  412.     bne.s        add_upper
  413. *-------------------------------------------------------*
  414. *    Force wall if light levels differ        *
  415. *-------------------------------------------------------*
  416.     move.w        sector_light(a4),d3
  417.     cmp.w        sector_light(a5),d3
  418.     beq.s        ignore_upper
  419. *-------------------------------------------------------*
  420. *    Upper wall segment passed all tests        *
  421. *-------------------------------------------------------*
  422. add_upper:
  423. *-------------------------------------------------------*
  424. *    Load wall structure                *
  425. *-------------------------------------------------------*
  426.     cmp.w        d1,d2
  427.     bpl.s        .clip
  428.     move.w        d1,d2
  429.     bpl.s        ignore_upper
  430. .clip:    move.w        d1,addwall_y1(a6)
  431.     move.w        d2,addwall_y2(a6)
  432.     move.w        d0,wall_id
  433. *-------------------------------------------------------*
  434. *    Calculate texture pegging            *
  435. *-------------------------------------------------------*
  436.     moveq        #0,d1
  437.     btst        #3,linedef_flags
  438.     bne.s        .np
  439.     tst.w        d0
  440.     bmi.s        .np
  441.     move.l        graphics_array,a0
  442.     move.l        (a0,d0.w*4),a0
  443.     move.w        tex_height(a0),d1
  444.     add.w        sector_ceilht(a4),d1
  445.     sub.w        sector_ceilht(a5),d1
  446. .np:    move.w        d1,peg
  447. *-------------------------------------------------------*
  448. *    Add upper wall to rendering buffer        *
  449. *-------------------------------------------------------*
  450.     move.b        #upper_command,addwall_type(a6)
  451.     bsr        add_wall_segment 
  452. *-------------------------------------------------------*
  453. *    Early abort check                *
  454. *-------------------------------------------------------*
  455.     tst.w        display_columns(a6)
  456.     beq        end_segment         
  457. *-------------------------------------------------------*
  458. ignore_upper:
  459. *-------------------------------------------------------*
  460.  
  461. *-------------------------------------------------------*
  462. sector_wall:    
  463. *-------------------------------------------------------*
  464. *    Check for normal texture            *
  465. *-------------------------------------------------------*
  466.     move.w        sidedef_mtns(a3),d2
  467.     move.w        d2,wall_id
  468.     cmp.w        #texcode_none,d2
  469.     beq        sector_window
  470. *-------------------------------------------------------*
  471. *    Determine texture height for vertical pegging    *
  472. *-------------------------------------------------------*
  473.     clr.w        peg
  474.     clr.w        th
  475.     tst.w        d2
  476.     bmi.s        .notex
  477.     move.l        graphics_array,a0
  478.     move.l        (a0,d2.w*4),a0
  479.     move.w        tex_height(a0),th
  480. *-------------------------------------------------------*
  481. *    Determine texture type (2 sided = transparent)    *
  482. *-------------------------------------------------------*
  483. .notex:    tst.b        twosided_flag
  484.     beq.s        .solid_wall
  485. *-------------------------------------------------------*
  486. *    Wall is 'transparent' middle texture        *
  487. *-------------------------------------------------------*
  488. .transparent_wall:
  489. *-------------------------------------------------------*
  490.     move.b        #trans_command,addwall_type(a6)
  491.     move.b        #1,addwall_opaque(a6)
  492. *-------------------------------------------------------*
  493. *    Unmapped transparents treated as solid        *
  494. *-------------------------------------------------------*
  495.     tst.w        d2
  496.     bmi.s        .normal_height    
  497. *-------------------------------------------------------*
  498. *    Determine transparent texture base        *
  499. *-------------------------------------------------------*
  500.     move.w        display_ph(a6),d0
  501.     btst        #4,linedef_flags
  502.     bne.s        .lower_unpegged
  503. *-------------------------------------------------------*
  504.     move.w        display_ch(a6),d3
  505.     move.w        d0,d1
  506.     cmp.w        sector_ceilht(a4),d3
  507.     bmi.s        .cins
  508.     move.w        sector_ceilht(a4),d3
  509. .cins:    sub.w        d3,d1
  510.     move.w        d1,d2
  511.     add.w        th,d2
  512.     bra.s        .add_wall
  513. *-------------------------------------------------------*
  514. .lower_unpegged:
  515. *-------------------------------------------------------*
  516.     move.w        display_fh(a6),d4
  517.     move.w        d0,d2
  518.     cmp.w        sector_floorht(a4),d4
  519.     bpl.s        .fins
  520.     move.w        sector_floorht(a4),d4
  521. .fins:    sub.w        d4,d2
  522.     move.w        d2,d1
  523.     sub.w        th,d1
  524.     bra.s        .add_wall
  525. *-------------------------------------------------------*
  526. *    Wall is 'solid' middle texture            *
  527. *-------------------------------------------------------*
  528. .solid_wall:
  529. *-------------------------------------------------------*
  530.     move.b        #wall_command,addwall_type(a6)
  531.     move.b        #0,addwall_opaque(a6)
  532. *-------------------------------------------------------*
  533. *    Calculate vertical pegging index        *
  534. *-------------------------------------------------------*
  535.     btst        #4,linedef_flags
  536.     beq.s        .normal_height
  537.     move.w        th,d0
  538.     add.w        display_fh(a6),d0
  539.     sub.w        display_ch(a6),d0
  540.     move.w        d0,peg    
  541. *-------------------------------------------------------*
  542. *    Caclulate wall base & top edge            *
  543. *-------------------------------------------------------*
  544. .normal_height:
  545. *-------------------------------------------------------*
  546.     move.w        display_ph(a6),d0
  547.     move.w        d0,d1
  548.     sub.w        display_ch(a6),d1
  549.     move.w        d0,d2
  550.     sub.w        display_fh(a6),d2
  551. *-------------------------------------------------------*
  552. *    Add middle wall to rendering list        *
  553. *-------------------------------------------------------*
  554. .add_wall:
  555. *-------------------------------------------------------*
  556. *    Force wall if opaque                *
  557. *-------------------------------------------------------*
  558.     tst.b        addwall_opaque(a6)
  559.     beq.s        .go
  560. *-------------------------------------------------------*
  561. *    Allow skip if ceiling = floor            *
  562. *-------------------------------------------------------*
  563.     cmp.w        d1,d2
  564.     beq.s        sector_window
  565. *-------------------------------------------------------*
  566. .go:    move.w        d1,addwall_y1(a6)
  567.     move.w        d2,addwall_y2(a6)
  568.     bsr        add_wall_segment
  569. *-------------------------------------------------------*
  570. sector_window:
  571. *-------------------------------------------------------*
  572.  
  573. *-------------------------------------------------------*
  574. end_segment:
  575. *-------------------------------------------------------*
  576.     pop.l        a2
  577. *-------------------------------------------------------*
  578. *    Proceed to next segment                *
  579. *-------------------------------------------------------*
  580. invisible:
  581. *-------------------------------------------------------*
  582.     lea        seg_len(a2),a2
  583.     addq.w        #1,display_segbase(a6)
  584.     subq.w        #1,display_segnum(a6)
  585.     beq.s        end_ssector
  586.     tst.w        display_columns(a6)
  587.     bne        segment_loop
  588. *-------------------------------------------------------*
  589. end_ssector:
  590. *-------------------------------------------------------*
  591.     bsr        get_ssector
  592. *-------------------------------------------------------*
  593. *    Fetch next node from heap and descend again    *
  594. *-------------------------------------------------------*
  595. next_node:
  596. *-------------------------------------------------------*
  597.     move.w        (sp)+,d0
  598.     bmi        ssector_node
  599.  
  600. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  601. *    [node] /= [sector] -> descend again        *
  602. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  603. dividing_node:
  604. *-------------------------------------------------------*
  605.     move.l        display_nodes(a6),a1
  606.     mulu.w        #node_len,d0
  607.     add.l        d0,a1
  608. *-------------------------------------------------------*
  609. *    Inverse descent rules for left side of tree    *
  610. *-------------------------------------------------------*
  611. *    (dy*(x1-Px))) => ((dx*(y1-Py)) ?        *
  612. *-------------------------------------------------------*
  613.     move.w        node_dx(a1),d2
  614.     move.w        node_x(a1),d0
  615.     move.w        node_dy(a1),d3
  616.     move.w        node_y(a1),d1
  617.     add.w        d2,d0            ; x2 = (x1+dx)
  618.     sub.w        display_px(a6),d0    ; (x2-px)
  619.     add.w        d3,d1            ; y2 = (y1+dy)
  620.     sub.w        display_py(a6),d1    ; (xy-py)
  621.     muls.w        d2,d1            ; (y2-py) * dx
  622.     muls.w        d3,d0            ; (x2-px) * dy
  623.     cmp.l        d0,d1 
  624.     bmi.s        node_leftside
  625. *-------------------------------------------------------*
  626. *    Viewer is on right side of node divider        *
  627. *-------------------------------------------------------*
  628. node_rightside:
  629. *-------------------------------------------------------*
  630.     lea        node_lvtx(a1),a0
  631.     bsr.s        nodeincone
  632.     beq.s        .noln
  633.     move.w        node_left(a1),-(sp)
  634. .noln:    lea        node_rvtx(a1),a0
  635.     bsr.s        nodeincone
  636.     beq.s        next_node
  637.     move.w        node_right(a1),-(sp) 
  638.     bra.s        next_node
  639. *-------------------------------------------------------*
  640. *    Viewer is on left side of node divider        *
  641. *-------------------------------------------------------*
  642. node_leftside:
  643. *-------------------------------------------------------*
  644.     lea        node_rvtx(a1),a0
  645.     bsr.s        nodeincone
  646.     beq.s        .noln
  647.     move.w        node_right(a1),-(sp) 
  648. .noln:    lea        node_lvtx(a1),a0
  649.     bsr.s        nodeincone
  650.     beq.s        next_node
  651.     move.w        node_left(a1),-(sp)
  652.     bra.s        next_node
  653.  
  654. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  655. *    Determine visibility of a child node.        *
  656. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  657. *    Only exposed nodes are dealt with.        *
  658. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  659.  
  660. *-------------------------------------------------------*
  661. *    Check #1 -> Octal node elimination        * 
  662. *-------------------------------------------------------*
  663. *    All nodes are checked against the 3 octal    *
  664. *    segments immediately in front of viewcone.    *
  665. *    Nodes from 5 of all 8 octants are discarded.    *
  666. *-------------------------------------------------------*
  667. *    Check #2 -> Canonical volume intersection    * 
  668. *-------------------------------------------------------*
  669. *    The remaining nodes are fully intersected    *
  670. *    with the projected canonical view volume.    *
  671. *    Any nodes outside the viewcone are discarded.    *
  672. *-------------------------------------------------------*
  673. *    Check #3 -> Occlusion check            * 
  674. *-------------------------------------------------------*
  675. *    Any nodes remaining in view are checked        *
  676. *    against the occlusion table. Any nodes        *
  677. *    completely occluded by walls are discarded.    *
  678. *-------------------------------------------------------*
  679.     txtlong
  680. *-------------------------------------------------------*
  681. *    This function is now completely DSP based    *
  682. *-------------------------------------------------------*
  683. nodeincone:
  684. *-------------------------------------------------------*
  685.     lea        DSPHostStat.w,a2
  686.     lea        DSPHost16.w,a3
  687.     move.l        a0,a4
  688.     moveq        #nodeincone_command,d0
  689.     dspwaitwrite.0    (a2)
  690.     move.w        d0,(a3)
  691.     move.w        (a4)+,d0
  692.     dspwaitwrite.0    (a2)
  693.     move.w        d0,(a3)
  694.     move.w        (a4)+,d0
  695.     dspwaitwrite.0    (a2)
  696.     move.w        d0,(a3)
  697.     move.w        (a4)+,d0
  698.     dspwaitwrite.0    (a2)
  699.     move.w        d0,(a3)
  700.     move.w        (a4)+,d0
  701.     dspwaitwrite.0    (a2)
  702.     move.w        d0,(a3)
  703.     dspwaitread.0    (a2)
  704.     tst.w        (a3)
  705.     rts
  706.  
  707. *-------------------------------------------------------*
  708.             bsslong
  709. *-------------------------------------------------------*
  710.  
  711. bsp_return:        ds.l    1        ; BSP stack base
  712.  
  713. wall_id:        ds.w    1
  714. x_offset:        ds.w    1
  715. peg:            ds.w    1
  716. th:            ds.w    1
  717.  
  718. linedef_flags:        ds.b    1
  719. twosided_flag:        ds.b    1        ; transparent wall flag
  720.  
  721. *-------------------------------------------------------*
  722.             txtlong
  723. *-------------------------------------------------------*
  724.