home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / DEMOS / MEGADEMO / PASSIONP.ARJ / PASSIONP.MSA / SHADING / SHADING.S < prev    next >
Text File  |  1997-03-05  |  12KB  |  549 lines

  1. ; *************************************************************************
  2. ; ****                       ****
  3. ; ****        Gouraud Shaded cube.           ****
  4. ; ****              By Alain BROBECKER           ****
  5. ; ****         Coded Between 22nd and 26th of june 1994.           ****
  6. ; ****                       ****
  7. ; *************************************************************************
  8. nb_brows    equ 8
  9.  
  10. supervisor:
  11.   move.l    #$0,-(sp)
  12.   move.w    #$20,-(sp)
  13.   trap    #$1
  14.   addq.l    #$6,sp
  15.  
  16. initialisations:    
  17.   dc.w    $a00a    ; Fuck the mouse.
  18.   move.b    #$12,$fffffc02.w
  19.   move.b    $484.w,old_conterm
  20.   clr.b    $484.w    ; No bip, no repeat.
  21.   move.l    $114.w,old_timerc ; Unusefull for a demo.
  22.   move.l    #null_timerc,$114.w ; Put a "null" routine.
  23.   move.l    $70.w,old_vbl    ; I have to use my own Vbl.
  24.   move.l    #null_vbl,$70.w    ; A "null" vbl for the moment.
  25.  
  26.   move.w    #$25,-(sp) 
  27.   trap    #$e    ; Vsync
  28.   addq.l    #$2,sp
  29.   move.b    $ffff8260.w,old_rez ; Save screen features.
  30.   move.b    $ffff8201.w,old_screen
  31.   move.b    $ffff8203.w,old_screen+1
  32.   move.b    $ffff820d.w,old_screen+2
  33.  
  34.   move.b    #$0,$ffff8260.w
  35.  
  36. ; Put our colors:
  37.   move.l    #colors,a0
  38.   move.w    #$8240,a1
  39.  rept    8
  40.   move.l    (a0)+,(a1)+
  41.  endr
  42.   
  43. ; *************************************************************************
  44.  
  45.   move.l    #$0,$466.w
  46.  
  47. vbl_one:
  48.   jsr    wait_vbl
  49.   move.l    #screen1,a6
  50.  
  51. .clear_box:
  52.   move.l    a6,a0
  53.   move.l    #old_box1,a1
  54.   move.w    (a1)+,d0    ; Extremities of the box to clear.
  55.   move.w    (a1)+,d1
  56.   move.w    (a1)+,d2
  57.   move.w    (a1)+,d3
  58.   jsr    clear_4_bpl
  59.  
  60. .angles:
  61.   subq.w    #$1,y_pos
  62.   move.w    angle1,d0
  63.   addq.w    #$5,d0
  64.   and.w    #$ff,d0
  65.   move.w    d0,angle1
  66.   move.w    angle2,d1
  67.   addq.w    #$2,d1
  68.   and.w    #$ff,d1
  69.   move.w    d1,angle2
  70.  
  71. .rotation:
  72.   move.l    #object_brows,a0
  73.   move.l    #new_coords,a1
  74.   jsr    rotation
  75.  
  76. .calc_intensities:
  77.   move.l    #new_coords,a0
  78.   move.l    a0,a1
  79.   move.l    #inverses,a2
  80.   moveq.l    #nb_brows,d0
  81.   subq.w    #$1,d0
  82.   move.w    #159,d6    ; For recentering.
  83.   move.w    y_pos,d7
  84. .one_brow:
  85.   move.w    (a0)+,d1    ; d1=x.
  86.   move.w    (a0)+,d2    ; d2=y.
  87.   move.w    (a0)+,d3    ; d3=z.
  88.   add.w    #$100,d3    ; d3=z+256.
  89.   move.w    d3,d4
  90.   adD.w    d1,d4
  91.   add.w    d3,d3
  92.   move.w    (a2,d3.w),d3    ; d3=16384/(z+256).
  93.   muls.w    d3,d1
  94.   lsr.l    #$6,d1    ; d1=x*256/(z+256).
  95.   add.w    d6,d1    ; Recenter.
  96.   move.w    d1,(a1)+    ; Save.
  97.   muls.w    d3,d2
  98.   lsr.l    #$6,d2    ; d2=y*256/(z+256).
  99.   add.w    d7,d2    ; Recenter.
  100.   move.w    d2,(a1)+    ; Save.
  101.   add.w    #80*2,d4    ; d4=x+z+2*80.
  102.   lsl.w    #$7,d4    ; d4=intensity.
  103.   move.w    #$a800,d1
  104.   sub.w    d4,d1
  105.   move.w    d1,(a1)+
  106.   dbra    d0,.one_brow
  107.   
  108. .search_box:
  109.   move.l    #new_coords,a0
  110.   move.w    (a0)+,d0
  111.   move.w    d0,d1    ; x1=x2=first x.
  112.   move.w    (a0)+,d2
  113.   move.w    d2,d3    ; y1=y2=first y.
  114.   moveq.l    #nb_brows,d7
  115.   subq.l    #$2,d7
  116. .search:
  117.   move.l    (a0)+,d4    ; d4=x.
  118.   move.w    (a0)+,d5    ; d5=y.
  119.   cmp.w    d0,d4    ; x<x1?
  120.   bge.s    .no_x1
  121.   move.w    d4,d0
  122. .no_x1:
  123.   cmp.w    d1,d4    ; x>x2?
  124.   ble.s    .no_x2
  125.   move.w    d4,d1
  126. .no_x2:
  127.   cmp.w    d2,d5    ; y<y1?
  128.   bge.s    .no_y1
  129.   move.w    d5,d2
  130. .no_y1:
  131.   cmp.w    d3,d5    ; y>y2?
  132.   ble.s    .no_y2
  133.   move.w    d5,d3
  134. .no_y2:
  135.   dbra    d7,.search
  136.   move.l    #old_box1,a0
  137.   movem.w    d0-3,(a0)    ; Save the box.
  138.  
  139. .print_cube:
  140.   move.l    a6,a0
  141.   move.l    #object_faces,a2
  142.   move.l    #new_coords,a3
  143.   move.w    (a2)+,d7    ; Nb of faces.
  144.   subq.w    #$1,d7
  145. .one_face:
  146.   move.w    (a2)+,d6    ; Nb of points for this face.
  147.   move.w    d6,d0
  148.   move.l    #face_coords,a1
  149.   subq.l    #$1,d6
  150. .one_coord:
  151.   move.w    (a2)+,d1
  152.   move.l    (a3,d1.w),(a1)+
  153.   move.w    $4(a3,d1.w),(a1)+
  154.   dbra    d6,.one_coord
  155. .test_visibility:
  156.   move.l    #face_coords,a1
  157.   move.w    (a1)+,d1    ; x1.
  158.   move.w    (a1)+,d2    ; y1.
  159.   addq.w    #$2,a1
  160.   move.w    (a1)+,d3    ; x2.
  161.   move.w    (a1)+,d4    ; y2.
  162.   addq.w    #$2,a1
  163.   move.w    (a1)+,d5    ; x3.
  164.   move.w    (a1)+,d6    ; y3.
  165.   sub.w    d3,d1    ; d1=x1-x2.
  166.   sub.w    d4,d2    ; d2=y1-y2.
  167.   sub.w    d3,d5    ; d5=x3-x2.
  168.   sub.w    d4,d6    ; d6=y3-y2.
  169.   muls.w    d1,d6
  170.   muls.w    d2,d5
  171.   sub.l    d5,d6    ; d6=(x1-x2)*(y3-y2)-(y1-y2)*(x3-x2).
  172.   ble.s    .next_face
  173. .visible:
  174.   move.l    #face_coords,a1
  175.   jsr    shaded_poly
  176. .next_face:
  177.   dbra    d7,.one_face
  178.  
  179.   move.l    a6,d0
  180.   move.l    d0,d1
  181.   swap.w    d0
  182.   move.b    d0,$ffff8201.w
  183.   swap.w    d0
  184.   rol.w    #$8,d0
  185.   move.b    d0,$ffff8203.w
  186.   move.b    d1,$ffff820d.w
  187.  
  188. vbl_two:
  189.   jsr    wait_vbl
  190.   move.l    #screen2,a6
  191.  
  192. .clear_box:
  193.   move.l    a6,a0
  194.   move.l    #old_box2,a1
  195.   move.w    (a1)+,d0    ; Extremities of the box to clear.
  196.   move.w    (a1)+,d1
  197.   move.w    (a1)+,d2
  198.   move.w    (a1)+,d3
  199.   jsr    clear_4_bpl
  200.  
  201. .angles:
  202.   subq.w    #$1,y_pos
  203.   move.w    angle1,d0
  204.   addq.w    #$5,d0
  205.   and.w    #$ff,d0
  206.   move.w    d0,angle1
  207.   move.w    angle2,d1
  208.   addq.w    #$2,d1
  209.   and.w    #$ff,d1
  210.   move.w    d1,angle2
  211.  
  212. .rotation:
  213.   move.l    #object_brows,a0
  214.   move.l    #new_coords,a1
  215.   jsr    rotation
  216.  
  217. .calc_intensities:
  218.   move.l    #new_coords,a0
  219.   move.l    a0,a1
  220.   move.l    #inverses,a2
  221.   moveq.l    #nb_brows,d0
  222.   subq.w    #$1,d0
  223.   move.w    #159,d6    ; For recentering.
  224.   move.w    y_pos,d7
  225. .one_brow:
  226.   move.w    (a0)+,d1    ; d1=x.
  227.   move.w    (a0)+,d2    ; d2=y.
  228.   move.w    (a0)+,d3    ; d3=z.
  229.   add.w    #$100,d3    ; d3=z+256.
  230.   move.w    d3,d4
  231.   adD.w    d1,d4
  232.   add.w    d3,d3
  233.   move.w    (a2,d3.w),d3    ; d3=16384/(z+256).
  234.   muls.w    d3,d1
  235.   lsr.l    #$6,d1    ; d1=x*256/(z+256).
  236.   add.w    d6,d1    ; Recenter.
  237.   move.w    d1,(a1)+    ; Save.
  238.   muls.w    d3,d2
  239.   lsr.l    #$6,d2    ; d2=y*256/(z+256).
  240.   add.w    d7,d2    ; Recenter.
  241.   move.w    d2,(a1)+    ; Save.
  242.   add.w    #80*2,d4    ; d4=x+z+2*80.
  243.   lsl.w    #$7,d4    ; d4=intensity.
  244.   move.w    #$a800,d1
  245.   sub.w    d4,d1
  246.   move.w    d1,(a1)+
  247.   dbra    d0,.one_brow
  248.   
  249. .search_box:
  250.   move.l    #new_coords,a0
  251.   move.w    (a0)+,d0
  252.   move.w    d0,d1    ; x1=x2=first x.
  253.   move.w    (a0)+,d2
  254.   move.w    d2,d3    ; y1=y2=first y.
  255.   moveq.l    #nb_brows,d7
  256.   subq.l    #$2,d7
  257. .search:
  258.   move.l    (a0)+,d4    ; d4=x.
  259.   move.w    (a0)+,d5    ; d5=y.
  260.   cmp.w    d0,d4    ; x<x1?
  261.   bge.s    .no_x1
  262.   move.w    d4,d0
  263. .no_x1:
  264.   cmp.w    d1,d4    ; x>x2?
  265.   ble.s    .no_x2
  266.   move.w    d4,d1
  267. .no_x2:
  268.   cmp.w    d2,d5    ; y<y1?
  269.   bge.s    .no_y1
  270.   move.w    d5,d2
  271. .no_y1:
  272.   cmp.w    d3,d5    ; y>y2?
  273.   ble.s    .no_y2
  274.   move.w    d5,d3
  275. .no_y2:
  276.   dbra    d7,.search
  277.   move.l    #old_box2,a0
  278.   movem.w    d0-3,(a0)    ; Save the box.
  279.  
  280. .print_cube:
  281.   move.l    a6,a0
  282.   move.l    #object_faces,a2
  283.   move.l    #new_coords,a3
  284.   move.w    (a2)+,d7    ; Nb of faces.
  285.   subq.w    #$1,d7
  286. .one_face:
  287.   move.w    (a2)+,d6    ; Nb of points for this face.
  288.   move.w    d6,d0
  289.   move.l    #face_coords,a1
  290.   subq.l    #$1,d6
  291. .one_coord:
  292.   move.w    (a2)+,d1
  293.   move.l    (a3,d1.w),(a1)+
  294.   move.w    $4(a3,d1.w),(a1)+
  295.   dbra    d6,.one_coord
  296. .test_visibility:
  297.   move.l    #face_coords,a1
  298.   move.w    (a1)+,d1    ; x1.
  299.   move.w    (a1)+,d2    ; y1.
  300.   addq.w    #$2,a1
  301.   move.w    (a1)+,d3    ; x2.
  302.   move.w    (a1)+,d4    ; y2.
  303.   addq.w    #$2,a1
  304.   move.w    (a1)+,d5    ; x3.
  305.   move.w    (a1)+,d6    ; y3.
  306.   sub.w    d3,d1    ; d1=x1-x2.
  307.   sub.w    d4,d2    ; d2=y1-y2.
  308.   sub.w    d3,d5    ; d5=x3-x2.
  309.   sub.w    d4,d6    ; d6=y3-y2.
  310.   muls.w    d1,d6
  311.   muls.w    d2,d5
  312.   sub.l    d5,d6    ; d6=(x1-x2)*(y3-y2)-(y1-y2)*(x3-x2).
  313.   ble.s    .next_face
  314. .visible:
  315.   move.l    #face_coords,a1
  316.   jsr    shaded_poly
  317. .next_face:
  318.   dbra    d7,.one_face
  319.  
  320.   move.l    a6,d0
  321.   move.l    d0,d1
  322.   swap.w    d0
  323.   move.b    d0,$ffff8201.w
  324.   swap.w    d0
  325.   rol.w    #$8,d0
  326.   move.b    d0,$ffff8203.w
  327.   move.b    d1,$ffff820d.w
  328.  
  329.   move.w    y_pos,d0
  330.   cmp.w    #-50,d0
  331.   ble.s    the_end
  332.   
  333.   cmpi.b    #$39,$fffffc02.w
  334.   bne    vbl_one
  335.  
  336. the_end:
  337.   move.w    #$25,-(sp) 
  338.   trap    #$e    ; Vsync
  339.   addq.l    #$2,sp
  340.  
  341.   move.b    old_rez,$ffff8260.w ; Restore screen features.
  342.   move.b    old_screen,$ffff8201.w
  343.   move.b    old_screen+1,$ffff8203.w
  344.   move.b    old_screen+2,$ffff820d.w
  345.  
  346.   move.l    old_vbl,$70.w    ; Restore the Vbl.
  347.   move.l    old_timerc,$114.w ; Restore old timerC rout.
  348.   move.b    old_conterm,$484.w
  349.   move.b    #$8,$fffffc02.w ; Restore mouse.
  350.   dc.w    $a009
  351.  
  352.   move.w    #$25,-(sp) 
  353.   trap    #$e    ; Vsync
  354.   addq.l    #$2,sp
  355.  
  356.   move.w    #$000,$ffff8240.w ; Devpac does not restore colors.
  357.   move.w    #$445,$ffff8242.w
  358.   move.w    #$445,$ffff8244.w
  359.   move.w    #$445,$ffff8246.w
  360.     
  361.   clr.w    -(sp)
  362.   trap    #$1
  363.  
  364. ; ************************************************************************
  365. null_timerc:        ; "Null" routine for the timerC.
  366.   addq.l    #$1,$4ba.w    ; Increment interrupt counter.
  367.   bclr.b    #$5,$fffffa11.w    ; Interrupt no more in service.
  368.   rte
  369.  
  370. ; ************************************************************************
  371. null_vbl:        ; "Null" vbl routine.
  372.   addq.l    #$1,$466.w    ; Increment _frclock.
  373.   cmp.l    #$0,$4d2.w    ; A music routine?
  374.   beq.s    .no_music
  375. .music:        ; Yes, so execute it.
  376.   move.l    a0,-(sp)
  377.   move.l    $4d2.w,a0
  378.   jsr    (a0)
  379.   move.l    (sp)+,a0
  380. .no_music:
  381.   rte
  382.  
  383.     
  384.   
  385.  
  386.  
  387. ; *************************************************************************
  388. ; More or less (Certainly less) interesting routines.
  389. wait_vbl:
  390.   move.w    d0,-(sp)
  391.   move.w    $468.w,d0
  392. .wait:
  393.   cmp.w    $468.w,d0
  394.   beq.s    .wait
  395.   move.w    (sp)+,d0
  396.   rts
  397.  
  398. ; *************************************************************************
  399. ; Routine which clears a box in 4 planes.
  400. ; Parameters:    a0.l = ramvideo adress.
  401. ;    d0.w = x1.
  402. ;    d1.w = x2.
  403. ;    d2.w = y1.
  404. ;    d3.w = y2.
  405.  
  406. clear_4_bpl:        ; First see if the box is visible.
  407.   movem.l    d0-3/a0-1,-(sp)
  408.   tst.w    d3    ; y2<0?
  409.   blt.s    .end
  410.   cmp.w    #199,d2    ; y1>199.
  411.   ble.s    .clipping
  412. .end:
  413.   movem.l    (sp)+,d0-3/a0-1
  414.   rts
  415. .clipping:
  416.   tst.w    d2    ; y1<0?
  417.   bge.s    .no_clip_up
  418.   moveq.l    #$0,d2    ; Then y1=0.
  419. .no_clip_up:
  420.   cmp.w    #199,d3    ; y2>199?
  421.   ble.s    .no_clip_down
  422.   move.w    #199,d3    ; Then y2=199
  423. .no_clip_down:
  424.   sub.w    d2,d3    ; d3=y2-y1=dy.
  425.   addq.w    #$1,d3
  426.   move.w    d3,$ffff8a38.w    ; Lines per bit-block.
  427.   move.l    #y_table,a1    
  428.   add.w    d2,d2
  429.   add.w    (a1,d2.w),a0    ; a0 points on good line.
  430.   move.w    #$fff0,d2
  431.   and.w    d2,d0    ; d0=x1 mod(16).
  432.   and.w    d2,d1    ; d1=x2 mod(16).
  433.   add.w    #$10,d1    ; d1=x2 mod(16)+16.
  434.   sub.w    d0,d1    ; d1=x2 mod(16)+16-x1 mod(16).
  435.   lsr.w    #$1,d0
  436.   add.w    d0,a0    ; a0 points on good word.
  437.   move.l    a0,$ffff8a32.w    ; Dest adress.
  438.   lsr.w    #$2,d1    ; d2=nb of words.
  439.   move.w    d1,$ffff8a36.w    ; Words per line.
  440.   move.w    #$2,$ffff8a2e.w ; Dest x inc.
  441.   add.w    d1,d1
  442.   move.w    #162,d3
  443.   sub.w    d1,d3
  444.   move.w    d3,$ffff8a30.w    ; Dest y inc.
  445.   moveq.l    #-1,d0
  446.   move.l    d0,$ffff8a28.w    ; Endmasks set to ones.
  447.   move.w    d0,$ffff8a2c.w
  448.   move.w    #$200,$ffff8a3a.w ; Fill with zeroes.
  449.   move.b    #$c0,$ffff8a3c.w
  450.   movem.l    (sp)+,d0-3/a0-1
  451.   rts
  452.  
  453. ; *************************************************************************
  454. ; The interesting routines.
  455.  
  456. rotation:
  457.   include    'a:\shading\rotation.s'
  458.  
  459.   Section TEXT
  460.   
  461. shaded_poly:
  462.   include    'a:\shading\shade.s'
  463.     
  464. ; *************************************************************************
  465.   Section DATA
  466.  
  467. object_brows:        ; Definition of the cube.
  468.   dc.w    4,28*256
  469.   dc.w    28*256,28*256
  470.   dc.w    -28*256,28*256
  471.   dc.w    -28*256,-28*256
  472.   dc.w    28*256,-28*256
  473.   dc.w    4,-28*256
  474.   dc.w    28*256,28*256
  475.   dc.w    -28*256,28*256
  476.   dc.w    -28*256,-28*256
  477.   dc.w    28*256,-28*256
  478.   dc.w    0
  479.  
  480. object_faces:
  481.   dc.w    6    ; 6 faces, Clockwise cycle.
  482.   dc.w    4,0*6,1*6,2*6,3*6
  483.   dc.w    4,0*6,3*6,7*6,4*6
  484.   dc.w    4,0*6,4*6,5*6,1*6
  485.   dc.w    4,6*6,7*6,3*6,2*6
  486.   dc.w    4,4*6,7*6,6*6,5*6
  487.   dc.w    4,1*6,5*6,6*6,2*6
  488.  
  489. y_table:        ; Convert y->y*160.
  490. N set 0
  491.  rept    200
  492.   dc.w    N
  493. N set N+160
  494.  endr
  495.  
  496. inverses:
  497.   incbin    'a:\shading\inverses.xxx'
  498.  
  499. colors:
  500.   dc.w    $000,$d00,$e00,$e88
  501.   dc.w    $e11,$e99,$e22,$eaa
  502.   dc.w    $e33,$ebb,$e44,$ecc
  503.   dc.w    $e55,$edd,$e66,$eee
  504.   
  505.   
  506.   dc.w    $000,$eee,$e66,$edd
  507.   dc.w    $e55,$ecc,$e44,$ebb
  508.   dc.w    $e33,$eaa,$e22,$e99
  509.   dc.w    $e11,$e88,$e00,$d00
  510.  
  511. y_pos:
  512.   dc.w    250
  513.     
  514. ; *************************************************************************
  515.   Section BSS
  516.  
  517. angle1:        ; Well...
  518.   ds.w    1
  519. angle2:
  520.   ds.w    1  
  521.  
  522. screen1:
  523.   ds.b    32000
  524. screen2:
  525.   ds.b    32000
  526.  
  527. new_coords:        ; Coords after rotation.
  528.   ds.w    21*3
  529. face_coords:
  530.   ds.w    21*3
  531.   ds.w    21*3
  532.   ds.w    21*3
  533.   
  534. old_box1:        ; Coords of the box which contain the cube.
  535.   ds.w    4
  536. old_box2:        ; The same for vbl2.
  537.   ds.w    4
  538.  
  539. old_vbl:        ; All the parameters for screen,
  540.   ds.l    1    ; and interrupts...
  541. old_timerc:
  542.   ds.l    1
  543. old_conterm:
  544.   ds.w    1 
  545. old_rez:
  546.   ds.w    1
  547. old_screen:
  548.   ds.l    1
  549.