home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / asm_programming / 3DSCAPE.ZIP / SUPPORT.ASM < prev   
Assembly Source File  |  1993-10-12  |  10KB  |  787 lines

  1. ;
  2. ;
  3. ;
  4.  
  5. .model small,c
  6.  
  7.             public Plot, sn_tbl, SwapScreens, DoPlasma, GetRand
  8.             public PlotProjection, screen, ClearMyScreen, view_screen
  9.             public SetMyMode, Project, grid, rand_seed
  10.             public pitch_sine,pitch_cosine,roll_sine,roll_cosine
  11.             public PutGrid, GetGrid
  12.  
  13.             extrn roll:word, cpitch:word, cz:word, cy:word
  14.             extrn gx:word, gy:word, gp:word, idx:word
  15.  
  16. EYEDIST        equ 8    ; perspective factor
  17. GRIDSIZE    equ 80
  18. VIEWSIZE    equ 61  ; Must be odd
  19. EXPAND        equ 5   ; distance between dots
  20. ARRAYSIZE    equ (GRIDSIZE*GRIDSIZE)
  21.  
  22. DEPTH_CUTOFF    equ 1300 ; point at which depth cueing starts
  23. DEPTH_SHIFT        equ 7 ; severity of depth cueing (high numbers = less severe)
  24.  
  25. .data
  26.  
  27.             align 2
  28.  
  29. vid_data    dw table_len
  30.  
  31.             dw 5f00h, 4f01h, 5002h, 8203h     ; CRTC Registers
  32.             dw 5404h, 8005h,0bf06h, 1f07h
  33.             dw 0008h, 0c009h, 000ah, 000bh
  34.             dw 000ch, 000dh, 000eh, 000fh
  35.             dw 9c10h, 8e11h, 8f12h, 2813h
  36.             dw 0014h, 9615h,0b916h,0E317h
  37.  
  38. table_len   equ ($-vid_data-1)/2
  39.  
  40. sn_tbl        dw (360+90) dup(0)
  41.  
  42.             align 2
  43.  
  44. point_size    equ 6
  45.  
  46. mx            dw 0
  47. my            dw 0
  48. gridptr        dw 0
  49.  
  50. point_grid    dw (VIEWSIZE*point_size) dup(0)
  51.  
  52. point_x        equ word ptr 0
  53. point_y        equ word ptr 2
  54. point_col    equ word ptr 4
  55.  
  56. rand_seed    dw 0
  57.  
  58.             align 4
  59.  
  60. screen        dd 0a0004000h
  61. view_screen dd 0a0000000h
  62.  
  63. pitch_sine    dd 0
  64. pitch_cosine dd 0
  65. roll_sine     dd 0
  66. roll_cosine    dd 0
  67.  
  68. grid        db ARRAYSIZE dup(0)
  69. grid_end    equ $
  70.  
  71. .code
  72.  
  73. .386
  74.  
  75. shift        equ 14
  76.  
  77.  
  78. param1        equ [bp+4]
  79. param2        equ [bp+6]
  80. param3        equ [bp+8]
  81. param4        equ [bp+10]
  82. param5        equ [bp+12]
  83. param6        equ [bp+14]
  84. param7        equ [bp+16]
  85. param8        equ [bp+18]
  86. param9        equ [bp+20]
  87.  
  88. RandPixel    proc near
  89.  
  90. x            equ word ptr param1
  91. y            equ word ptr param2
  92. x1            equ word ptr param3
  93. y1            equ word ptr param4
  94. x2            equ word ptr param5
  95. y2            equ word ptr param6
  96.  
  97.             push bp
  98.             mov bp,sp
  99.  
  100.             mov ax,x
  101.             sub ax,x1
  102.             cwd
  103.             xor ax,dx
  104.             sub ax,dx
  105.  
  106.             mov bx,ax
  107.  
  108.             mov ax,y
  109.             sub ax,y1
  110.             cwd
  111.             xor ax,dx
  112.             sub ax,dx
  113.  
  114.             add bx,ax
  115.  
  116.             call GetRand
  117.             xor ah,ah
  118.             sub ax,128
  119.  
  120.             imul bx
  121.             mov bx,GRIDSIZE/6
  122.             idiv bx
  123.  
  124.             push ax
  125.  
  126.             mov bx,y1
  127.             mov ax,x1
  128.             call GetGrid
  129.  
  130.             push ax
  131.  
  132.             mov bx,y2
  133.             mov ax,x2
  134.             call GetGrid
  135.  
  136.             pop bx
  137.             add ax,bx
  138.             sar ax,1
  139.  
  140.             pop bx
  141.             add ax,bx
  142.             cmp ax,1
  143.             jge rp_s1
  144.  
  145.             mov al,1
  146. rp_s1:
  147.             cmp ax,255
  148.             jle rp_s2
  149.  
  150.             mov al,255
  151. rp_s2:
  152.             xor ah,ah
  153.             push ax
  154.  
  155.             mov cl,al
  156.             mov bx,y
  157.             mov ax,x
  158.             call PutGrid
  159.             pop ax
  160.  
  161.             pop bp
  162.             ret
  163.  
  164. RandPixel    endp
  165.  
  166.  
  167. GetRand        proc near
  168.  
  169.             mov ax,rand_seed
  170.             add ax,56791
  171.             imul ax,13579
  172.             mov rand_seed,ax
  173.             and ax,07fffh
  174.             ret
  175.  
  176. GetRand        endp
  177.  
  178.  
  179. GetGrid        proc near
  180.  
  181.             imul bx,GRIDSIZE
  182.             add bx,ax
  183.             add bx,idx
  184.             sub bx,ARRAYSIZE
  185.             jnc no_add1
  186.             add bx,ARRAYSIZE
  187. no_add1:
  188.             mov al,[bx+grid]
  189.             xor ah,ah
  190.  
  191.             ret
  192.  
  193. GetGrid        endp
  194.  
  195.  
  196. PutGrid        proc near
  197.  
  198.             imul bx,GRIDSIZE
  199.             add bx,ax
  200.             add bx,idx
  201.             sub bx,ARRAYSIZE
  202.             jnc no_add2
  203.             add bx,ARRAYSIZE
  204. no_add2:
  205.             mov [bx+grid],cl
  206.  
  207.             ret
  208.  
  209. putGrid        endp
  210.  
  211.  
  212. DoPlasma    proc near
  213.  
  214. x1            equ word ptr param1
  215. y1            equ word ptr param2
  216. x2            equ word ptr param3
  217. y2            equ word ptr param4
  218.  
  219. x            equ word ptr [bp-2]
  220. y            equ word ptr [bp-4]
  221. s            equ word ptr [bp-6]
  222.  
  223.             push bp
  224.             mov bp,sp
  225.             sub sp,6
  226.  
  227.             mov ax,x2
  228.             sub ax,x1
  229.             cmp ax,1
  230.             jg not_return
  231.  
  232.             mov ax,y2
  233.             sub ax,y1
  234.             cmp ax,1
  235.             jg not_return
  236.             jmp exit_doplasma
  237.  
  238. not_return:
  239.  
  240.             mov ax,y1
  241.             add ax,y2
  242.             sar ax,1
  243.             mov y,ax
  244.  
  245.             mov ax,x1
  246.             add ax,x2
  247.             sar ax,1
  248.             mov x,ax
  249.  
  250.             mov bx,y1
  251.             call GetGrid
  252.  
  253.             or ax,ax
  254.             jnz dp_s1
  255.  
  256.             push y1
  257.             push x2
  258.             push y1
  259.             push x1
  260.             push y1
  261.             push x
  262.             call RandPixel
  263.             add sp,12
  264.  
  265. dp_s1:
  266.             mov s,ax
  267.  
  268.             mov bx,y
  269.             mov ax,x2
  270.             call GetGrid
  271.  
  272.             or ax,ax
  273.             jnz dp_s2
  274.  
  275.             push y2
  276.             push x2
  277.             push y1
  278.             push x2
  279.             push y
  280.             push x2
  281.             call RandPixel
  282.             add sp,12
  283.  
  284. dp_s2:
  285.             add s,ax
  286.  
  287.             mov bx,y2
  288.             mov ax,x
  289.             call GetGrid
  290.  
  291.             or ax,ax
  292.             jnz dp_s3
  293.  
  294.             push y2
  295.             push x2
  296.             push y2
  297.             push x1
  298.             push y2
  299.             push x
  300.             call RandPixel
  301.             add sp,12
  302.  
  303. dp_s3:
  304.             add s,ax
  305.  
  306.             mov bx,y
  307.             mov ax,x1
  308.             call GetGrid
  309.  
  310.             or ax,ax
  311.             jnz dp_s4
  312.  
  313.             push y2
  314.             push x1
  315.             push y1
  316.             push x1
  317.             push y
  318.             push x1
  319.             call RandPixel
  320.             add sp,12
  321.  
  322. dp_s4:
  323.             add s,ax
  324.  
  325.             mov bx,y
  326.             mov ax,x
  327.             call GetGrid
  328.  
  329.             or ax,ax
  330.             jnz no_plot
  331.  
  332.             mov cx,s
  333.             shr cx,2
  334.             mov bx,y
  335.             mov ax,x
  336.             call PutGrid
  337. no_plot:
  338.             push y
  339.             push x
  340.             push y1
  341.             push x1
  342.             call DoPlasma
  343.             add sp,8
  344.  
  345.             push y
  346.             push x2
  347.             push y1
  348.             push x
  349.             call DoPlasma
  350.             add sp,8
  351.  
  352.             push y2
  353.             push x
  354.             push y
  355.             push x1
  356.             call DoPlasma
  357.             add sp,8
  358.  
  359.             push y2
  360.             push x2
  361.             push y
  362.             push x
  363.             call DoPlasma
  364.             add sp,8
  365.  
  366. exit_doplasma:
  367.             leave
  368.             ret
  369.  
  370. DoPlasma    endp
  371.  
  372.  
  373. SwapScreens proc near
  374.  
  375.             mov dx, 03dah
  376. ss_1:
  377.             in al,dx
  378.             test al,8
  379.             jz ss_1
  380. ss_2:
  381.             in al,dx
  382.             test al,8
  383.             jnz ss_2
  384.  
  385.             cli
  386.             add word ptr view_screen,04000h
  387.             add word ptr screen,04000h
  388.  
  389.             mov bx,word ptr view_screen
  390.  
  391.             mov dx,03d4h
  392.             mov al,0dh
  393.             mov ah,bl
  394.             out dx,ax
  395.             dec al
  396.             mov ah,bh
  397.             out dx,ax
  398.             sti
  399.  
  400.             ret
  401.  
  402. SwapScreens endp
  403.  
  404.  
  405. Plot        proc near
  406.  
  407.             cmp bx, 319
  408.             jae Plot_quit
  409.  
  410.             cmp cx, 199
  411.             jae Plot_quit
  412.  
  413.             push di
  414.             push ax
  415.             les di,screen
  416.             mov dx,cx
  417.             shl dx,6
  418.             shl cx,4
  419.             add dx,cx
  420.  
  421.             mov cx,bx
  422.             shr bx,2
  423.             add bx,dx
  424.             add di,bx
  425.             mov dx,03c4h
  426.             mov ax,0102h
  427.             and cl,3
  428.             shl ah,cl
  429.             out dx,ax
  430.             pop ax
  431.             mov es:[di],al
  432.  
  433.             pop di
  434. Plot_quit:
  435.             ret
  436.  
  437. Plot        endp
  438.  
  439.  
  440. MatrixRotate proc near
  441.  
  442.             movsx esi,ax
  443.             imul esi,roll_cosine
  444.             movsx edx,bx
  445.             imul edx,roll_sine
  446.             sub esi,edx
  447.             sar esi, shift
  448.  
  449.             movsx ecx,ax
  450.             imul ecx,roll_sine
  451.             movsx edx,bx
  452.             imul edx,roll_cosine
  453.             add ecx,edx
  454.             sar ecx, shift
  455.  
  456.             mov ebx,ecx
  457.             imul ebx,pitch_cosine
  458.             movsx edx,di
  459.             imul edx,pitch_sine
  460.             sub ebx,edx
  461.             sar ebx, shift
  462.             mov ax,bx
  463.  
  464.             imul ecx,pitch_sine
  465.             movsx edx,di
  466.             imul edx,pitch_cosine
  467.             add ecx,edx
  468.             sar ecx, shift
  469.             mov dx,cx
  470.  
  471.             ret
  472.  
  473. MatrixRotate endp
  474.  
  475.  
  476. PlotProjection proc near
  477.  
  478.             push bp
  479.             mov bp,sp
  480.  
  481.             push si
  482.             push di
  483.  
  484.             movsx ebx,word ptr param3
  485.             mov di,gridptr
  486.  
  487.             cmp bx,1 shl EYEDIST
  488.             jg no_quit_proj
  489. quit_projection:
  490.  
  491.             mov point_col[di],0
  492.             jmp exit_projection
  493.  
  494. no_quit_proj:
  495.  
  496.             mov ax,param1
  497.             cwd
  498.             xor ax,dx
  499.             sub ax,dx
  500.             shr ax,2
  501.             add ax,bx
  502.  
  503.             shr byte ptr param4,2
  504.  
  505.             cmp ax,DEPTH_CUTOFF
  506.             jg do_depth
  507.  
  508.             push word ptr param4
  509.             jmp skip_depth
  510.  
  511. do_depth:
  512.  
  513.             sub ax,DEPTH_CUTOFF
  514.             shr ax,DEPTH_SHIFT
  515.  
  516.             cmp ax,4
  517.             jae quit_projection
  518.  
  519.             shl al,6
  520.             add al,param4
  521.             push ax
  522. skip_depth:
  523.  
  524.             movsx eax,word ptr param2
  525.             shl eax,EYEDIST
  526.             cdq
  527.             idiv ebx
  528.             add ax,100
  529.             mov cx,ax
  530.  
  531.             movsx eax,word ptr param1
  532.             shl eax,EYEDIST
  533.             cdq
  534.             idiv ebx
  535.             add ax,160
  536.             mov bx,ax
  537.             pop ax
  538.  
  539.             mov si,bx
  540.             push cx
  541.  
  542.             call Plot
  543.  
  544.             pop cx
  545.  
  546.             push ax
  547.  
  548.             cmp my,VIEWSIZE/2 shl EXPAND
  549.             jz skip_below
  550.  
  551.             cmp point_col[di],0
  552.             jz skip_below
  553.  
  554.             push cx
  555.  
  556.             mov bx,si
  557.             add bx,point_x[di]
  558.             sar bx,1
  559.             add cx,point_y[di]
  560.             sar cx,1
  561.             mov ax,point_col[di]
  562.  
  563.             call Plot
  564.  
  565.             pop cx
  566.  
  567.             cmp mx,VIEWSIZE/2 shl EXPAND
  568.             jz skip_below
  569.  
  570.             cmp point_col[di+point_size],0
  571.             jz skip_below
  572.  
  573.             push cx
  574.  
  575.             mov bx,si
  576.             add bx,point_x[di+point_size]
  577.             sar bx,1
  578.             add cx,point_y[di+point_size]
  579.             sar cx,1
  580.             mov ax,point_col[di+point_size]
  581.  
  582.             call Plot
  583.  
  584.             pop cx
  585.  
  586. skip_below:
  587.             cmp mx,-VIEWSIZE/2 shl EXPAND
  588.             jz skip_left
  589.  
  590.             cmp point_col[di-point_size],0
  591.             jz skip_left
  592.  
  593.             push cx
  594.  
  595.             mov bx,si
  596.             add bx,point_x[di-point_size]
  597.             sar bx,1
  598.             add cx,point_y[di-point_size]
  599.             sar cx,1
  600.             mov ax,point_col[di-point_size]
  601.  
  602.             call Plot
  603.  
  604.             pop cx
  605. skip_left:
  606.  
  607.             pop ax
  608.  
  609.             mov point_x[di],si
  610.             mov point_y[di],cx
  611.             mov point_col[di],ax
  612.  
  613. exit_projection:
  614.             pop di
  615.             pop si
  616.             pop bp
  617.             ret
  618.  
  619. PlotProjection endp
  620.  
  621.  
  622. SetMyMode    proc near
  623.  
  624.             push si
  625.             push di
  626.  
  627.             mov ax,013h
  628.             int 10h
  629.  
  630.             mov dx,03c4h
  631.             mov ax,0604h
  632.             out dx,ax
  633.  
  634.             mov ax,0f02h
  635.             out dx,ax
  636.  
  637.             xor di,di
  638.             mov ax,0a000h
  639.             mov es,ax
  640.             mov cx,07fffh
  641.             xor ax,ax
  642.  
  643.             rep stosw
  644.  
  645.             cli
  646.  
  647.             mov dx,03d4h
  648.             mov al,011h
  649.             out dx,al
  650.  
  651.             jmp $+2
  652.             inc dx
  653.             in al,dx
  654.             and al,07fh
  655.             out dx,al
  656.  
  657.             mov dx,03d4h
  658.             mov si,offset vid_data
  659.             cld
  660.             lodsw
  661.             mov cx,ax
  662. out_next:
  663.             lodsw
  664.             out dx,ax
  665.             loop out_next
  666.  
  667.             sti
  668.  
  669.             pop di
  670.             pop si
  671.  
  672.             ret
  673.  
  674. SetMyMode    endp
  675.  
  676.  
  677. ClearMyScreen proc near
  678.  
  679.             push di
  680.  
  681.             mov dx,03c4h
  682.             mov ax,0f02h
  683.             out dx,ax
  684.  
  685.             les di,screen
  686.             mov cx,4000
  687.             xor eax,eax
  688.  
  689.             rep stosd
  690.  
  691. ;            xor cx,cx
  692. ;            xor bx,bx
  693. ;            xor al,al
  694. ;
  695. ;next_col:
  696. ;            push ax
  697. ;            push bx
  698. ;            push cx
  699. ;            call Plot
  700. ;            pop cx
  701. ;            pop bx
  702. ;            pop ax
  703. ;            inc bx
  704. ;            inc al
  705. ;            jnz next_col
  706.  
  707.  
  708.             pop di
  709.             ret
  710.  
  711. ClearMyScreen endp
  712.  
  713.  
  714. Project        proc near
  715.  
  716. p            equ word ptr [bp-2]
  717.  
  718.             push bp
  719.             mov bp,sp
  720.             sub sp,2
  721.             push si
  722.             push di
  723.  
  724.             mov di,gp
  725.             mov p,di
  726.  
  727.             mov my,VIEWSIZE/2 shl EXPAND
  728.             jmp test_y
  729. next_y:
  730.  
  731.             mov gridptr, offset point_grid
  732.             mov mx,-VIEWSIZE/2 shl EXPAND
  733.             jmp test_x
  734. next_x:
  735.             mov di,p
  736.             movzx di,byte ptr [di]
  737.             cmp di,63
  738.             jae skip_levelsea
  739.             mov di,63
  740. skip_levelsea:
  741.  
  742.             mov ax,mx
  743.             mov bx,my
  744.             call MatrixRotate
  745.  
  746.             push di
  747.             sub dx,cz
  748.             push dx
  749.             sub ax,cy
  750.             push ax
  751.             push si
  752.             call PlotProjection
  753.             add sp,8
  754.  
  755.             add mx,1 shl EXPAND
  756.             inc p
  757.             cmp p,offset grid_end
  758.             jb skip_modp
  759.  
  760.             sub p,ARRAYSIZE
  761. skip_modp:
  762.             add gridptr,6
  763. test_x:
  764.             cmp mx,VIEWSIZE/2 shl EXPAND
  765.             jle next_x
  766.  
  767.             sub my,1 shl EXPAND
  768.             add p,GRIDSIZE-VIEWSIZE
  769.             cmp p,offset grid_end
  770.             jb test_y
  771.  
  772.             sub p,ARRAYSIZE
  773. test_y:
  774.             cmp my,-VIEWSIZE/2 shl EXPAND
  775.             jge next_y
  776.  
  777.  
  778. Project_quit:
  779.             pop di
  780.             pop si
  781.             leave
  782.             ret
  783.  
  784. Project        endp
  785.  
  786.             end
  787.