home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / programming / other / cantstop_src / thelot.s < prev   
Encoding:
Text File  |  1998-05-09  |  84.8 KB  |  4,233 lines

  1.  
  2.  
  3.     ; ***************************************************************
  4.     ; ***                                                         ***
  5.     ; ***  SOURCEFILE CONTAINING ALL STUFF NEEDED FOR MY EFFECTS  ***
  6.     ; ***                                                         ***
  7.     ; ***************************************************************
  8.  
  9.  
  10.     ; Assembled with PhxAss V4.36 (C)1991-1997 Frank Wille
  11.  
  12.  
  13.  
  14.     ; New Stuff (6.4.98)
  15.     ;
  16.     ;
  17.     ;  * Added a background to the textured scene.
  18.     ;
  19.     ;  * Made the little pyramids rotate some more in the scene.
  20.     ;
  21.     ;  * Modified the shape of the 'N' in the scene to what Raven suggested.
  22.     ;
  23.     ;  * Added code to flash the screen between effects. You can change
  24.     ;    the colour of the flash using the 'BLANK_COLOUR' equate (below).
  25.     ;    Also fixed the annoying bug where the previous effect's display
  26.     ;    was shown on the next effect.
  27.     ;
  28.     ;  * Modified the 'CantStop.CNK' file to make the logo a bit more readable
  29.     ;    on darker screens.
  30.     ;
  31.     ;  That should be most of the major changes for now! ;)
  32.     ;
  33.  
  34.  
  35.  
  36.     ; What's changed:
  37.     ;
  38.     ; Everything needed to assemble my effects is contained in this file,
  39.     ; except the binary files. All three effects share the same ChipRAM
  40.     ; for their planar display, but chew up a fair bit of FastRAM
  41.     ; (around 400K in total I think).
  42.     ;
  43.     ; 'Driver0' shows how to init and run all the effects together.
  44.     ;
  45.     ; Effects now run for a specified time, and then exit automatically.
  46.     ; Since I don't know how you do music synchronisation, I've done it
  47.     ; this way to at least give you some control over timing of the
  48.     ; effects.
  49.     ;
  50.     ;
  51.     ; Usage:
  52.     ;
  53.     ;  * Do a Jsr to 'LINE_INIT', 'BUMP_INIT', and 'SCENE_INIT' as part of
  54.     ;    your precalculation stuff.
  55.     ;
  56.     ;  * Call 'LINE_SHOW', 'BUMP_SHOW', and 'SCENE_SHOW' when you want the
  57.     ;    specific effect to be shown on screen. It will then run for the
  58.     ;    time specified below, and then return.
  59.     ;
  60.     ; The 'LINE_END', 'BUMP_END', and 'SCENE_END' did nothing, so they're
  61.     ; gone now! ;)
  62.     ;
  63.  
  64.  
  65.  
  66.     ; ** THIS DEFINES THE LENGTH (IN FRAMES) FOR EACH EFFECT TO RUN) **
  67.  
  68. L_FRAMES    = 800        ; 16 seconds
  69. B_FRAMES    = 800
  70. S_FRAMES    = 800
  71.  
  72.  
  73. BLANK_COLOUR    = $888        ; Colour that screen changes to between effects
  74.  
  75.  
  76.  
  77.  
  78.     
  79.     MACHINE    68020            ; Gimme those all important opcodes ;)
  80.  
  81.  
  82.  
  83.     ; ***************************************************************
  84.     ; ***                                                         ***
  85.     ; ***  DEMO EFFECTS LIBRARY: C2P, 3D ENGINE, GENERAL STUFF    ***
  86.     ; ***                                                         ***
  87.     ; ***************************************************************
  88.  
  89.  
  90.  
  91.     ; ** This chunky-to-planar code is not mine! It was ripped from
  92.     ; ** an archive on Aminet, and to the best of my knowledge is
  93.     ; ** freely distributable. If this is not the case, then please
  94.     ; ** contact me, and it will be removed.
  95.  
  96.     ; ** It has also been modified somewhat to allow different sized
  97.     ; ** C2P areas using the same piece of code.
  98.  
  99.     ; ** Original archive was called 'FastC2P.LHA', and chunky routine
  100.     ; ** was called 'c2p_020.s'.
  101.  
  102.  
  103. ; Chunky2Planar algorithm. [writes pipelined a little]
  104. ;
  105. ;     Cpu only solution
  106. ;    Optimised for 020+fastram
  107. ;    Aim for less than 90ms for 320x200x256 on 14MHz 020
  108. ;
  109. ;
  110. ; NOTE: uses hardcoded values for screen size
  111. ;     assumes planes are allocated contiguously
  112. ;
  113. ; NOTE2:    Hacked a little bit to allow variable sized C2P coversion
  114. ;        Planar screensize remains at 320x200, but C2P can work
  115. ;        on any size (specified in d0)
  116. ;
  117. ; -------------------------------------------------------------------
  118. ;
  119. ; void __asm c2p_020(    register __d0 ULONG c2p_size,
  120. ;            register __a0 UBYTE *chunky,
  121. ;            register __a1 PLANEPTR raster );
  122. ;
  123. ; -------------------------------------------------------------------
  124. ;
  125. ; see c2p_020_test.c for example of usage
  126.  
  127.  
  128. ;    opt    o-,l+,d+
  129.     
  130. WIDTH        equ    320        ; MUST be multiple of 32
  131. HEIGHT        equ    200
  132. plsiz        equ    (WIDTH/8)*HEIGHT
  133.  
  134.  
  135.         cnop    0,4
  136.  
  137. _c2p_020
  138.  
  139.     movem.l    d2-d7/a2-a6,-(sp)
  140.  
  141. ;    move.l    a0,a2
  142. ;    add.l    #plsiz*8,a2    ;a2 = end of chunky buffer
  143.  
  144.     Move.l    d0,.c2psize
  145.     Move.l    a0,a2
  146.     Add.l    d0,a2        ; a2 = end of chunky buffer
  147.  
  148.  
  149.     
  150.     ;; Sweep thru the whole chunky data once,
  151.     ;; Performing 3 merge operations on it.
  152.     
  153.     move.l    #$00ff00ff,a3    ; load byte merge mask
  154.     move.l    #$0f0f0f0f,a4    ; load nibble merge mask
  155.     
  156. .firstsweep
  157.     movem.l (a0),d0-d7      ;8+4n   40      cycles
  158.     move.l    d4,a6           ;a6 = CD
  159.     move.w    d0,d4           ;d4 = CB
  160.     swap    d4              ;d4 = BC
  161.     move.w    d4,d0           ;d0 = AC
  162.     move.w    a6,d4           ;d4 = BD
  163.     move.l    d5,a6           ;a6 = CD
  164.     move.w    d1,d5           ;d5 = CB
  165.     swap    d5              ;d5 = BC
  166.     move.w    d5,d1           ;d1 = AC
  167.     move.w    a6,d5           ;d5 = BD
  168.     move.l    d6,a6           ;a6 = CD
  169.     move.w    d2,d6           ;d6 = CB
  170.     swap    d6              ;d6 = BC
  171.     move.w    d6,d2           ;d2 = AC
  172.     move.w    a6,d6           ;d6 = BD
  173.     move.l    d7,a6           ;a6 = CD
  174.     move.w    d3,d7           ;d7 = CB
  175.     swap    d7              ;d7 = BC
  176.     move.w    d7,d3           ;d3 = AC
  177.     move.w    a6,d7           ;d7 = BD
  178.     move.l    d7,a6
  179.     move.l    d6,a5
  180.     move.l    a3,d6   ; d6 = 0x0x
  181.     move.l    a3,d7   ; d7 = 0x0x
  182.     and.l    d0,d6   ; d6 = 0b0r
  183.     and.l    d2,d7   ; d7 = 0j0z
  184.     eor.l    d6,d0   ; d0 = a0q0
  185.     eor.l    d7,d2   ; d2 = i0y0
  186.     lsl.l    #8,d6   ; d6 = b0r0
  187.     lsr.l    #8,d2   ; d2 = 0i0y
  188.     or.l    d2,d0           ; d0 = aiqy
  189.     or.l    d7,d6           ; d2 = bjrz
  190.     move.l    a3,d7   ; d7 = 0x0x
  191.     move.l    a3,d2   ; d2 = 0x0x
  192.     and.l    d1,d7   ; d7 = 0b0r
  193.     and.l    d3,d2   ; d2 = 0j0z
  194.     eor.l    d7,d1   ; d1 = a0q0
  195.     eor.l    d2,d3   ; d3 = i0y0
  196.     lsl.l    #8,d7   ; d7 = b0r0
  197.     lsr.l    #8,d3   ; d3 = 0i0y
  198.     or.l    d3,d1           ; d1 = aiqy
  199.     or.l    d2,d7           ; d3 = bjrz
  200.  
  201.     move.l  a4,d2   ; d2 = 0x0x
  202.     move.l  a4,d3   ; d3 = 0x0x
  203.     and.l   d0,d2   ; d2 = 0b0r
  204.     and.l   d1,d3   ; d3 = 0j0z
  205.     eor.l   d2,d0   ; d0 = a0q0
  206.     eor.l   d3,d1   ; d1 = i0y0
  207.     lsr.l   #4,d1   ; d1 = 0i0y
  208.     or.l    d1,d0           ; d0 = aiqy
  209.     move.l  d0,(a0)+
  210.     lsl.l    #4,d2
  211.     or.l    d3,d2           ; d1 = bjrz
  212.     move.l    d2,(a0)+
  213.  
  214.     move.l  a4,d3   ; d3 = 0x0x
  215.     move.l  a4,d1   ; d1 = 0x0x
  216.     and.l   d6,d3   ; d3 = 0b0r
  217.     and.l   d7,d1   ; d1 = 0j0z
  218.     eor.l   d3,d6   ; d6 = a0q0
  219.     eor.l   d1,d7   ; d7 = i0y0
  220.     lsr.l   #4,d7   ; d7 = 0i0y
  221.     or.l    d7,d6           ; d6 = aiqy
  222.     move.l    d6,(a0)+
  223.     lsl.l    #4,d3
  224.     or.l    d1,d3           ; d7 = bjrz
  225.     move.l    d3,(a0)+
  226.  
  227.     ; move.l    d0,(a0)+
  228.     ; move.l    d2,(a0)+
  229.     ; move.l    d6,(a0)+
  230.     ; move.l    d3,(a0)+
  231.     move.l    a6,d7
  232.     move.l  a5,d6
  233.     move.l  a3,d0   ; d0 = 0x0x
  234.     move.l  a3,d1   ; d1 = 0x0x
  235.     and.l   d4,d0   ; d0 = 0b0r
  236.     and.l   d6,d1   ; d1 = 0j0z
  237.     eor.l   d0,d4   ; d4 = a0q0
  238.     eor.l   d1,d6   ; d6 = i0y0
  239.     lsl.l   #8,d0   ; d0 = b0r0
  240.     lsr.l   #8,d6   ; d6 = 0i0y
  241.     or.l    d6,d4           ; d4 = aiqy
  242.     or.l    d1,d0           ; d6 = bjrz
  243.     move.l  a3,d1   ; d1 = 0x0x
  244.     move.l  a3,d6   ; d6 = 0x0x
  245.     and.l   d5,d1   ; d1 = 0b0r
  246.     and.l   d7,d6   ; d6 = 0j0z
  247.     eor.l   d1,d5   ; d5 = a0q0
  248.     eor.l   d6,d7   ; d7 = i0y0
  249.     lsl.l   #8,d1   ; d1 = b0r0
  250.     lsr.l   #8,d7   ; d7 = 0i0y
  251.     or.l    d7,d5           ; d5 = aiqy
  252.     or.l    d6,d1           ; d7 = bjrz
  253.     move.l  a4,d6   ; d6 = 0x0x
  254.     move.l  a4,d7   ; d7 = 0x0x
  255.     and.l   d4,d6   ; d6 = 0b0r
  256.     and.l   d5,d7   ; d7 = 0j0z
  257.     eor.l   d6,d4   ; d4 = a0q0
  258.     eor.l   d7,d5   ; d5 = i0y0
  259.     lsr.l   #4,d5   ; d5 = 0i0y
  260.     or.l    d5,d4           ; d4 = aiqy
  261.     move.l  d4,(a0)+
  262.     lsl.l   #4,d6   ; d6 = b0r0
  263.     or.l    d7,d6           ; d5 = bjrz
  264.     move.l  d6,(a0)+
  265.  
  266.     move.l  a4,d7   ; d7 = 0x0x
  267.     move.l  a4,d5   ; d5 = 0x0x
  268.     and.l   d0,d7   ; d7 = 0b0r
  269.     and.l   d1,d5   ; d5 = 0j0z
  270.     eor.l   d7,d0   ; d0 = a0q0
  271.     eor.l   d5,d1   ; d1 = i0y0
  272.     lsr.l   #4,d1   ; d1 = 0i0y
  273.     or.l    d1,d0           ; d0 = aiqy
  274.     move.l  d0,(a0)+
  275.     lsl.l   #4,d7   ; d7 = b0r0
  276.     or.l    d5,d7           ; d1 = bjrz
  277.     move.l  d7,(a0)+
  278.     cmp.l   a0,a2           ;; 4c
  279.     bne.w   .firstsweep      ;; 6c
  280.  
  281. ;    sub.l   #plsiz*8,a0
  282.     sub.l   .c2psize,a0
  283.     move.l  #$33333333,a5
  284.     move.l  #$55555555,a6
  285.     lea     plsiz*4(a1),a1  ;a2 = plane4
  286.  
  287. .secondsweep
  288.     move.l  (a0),d0
  289.     move.l  8(a0),d1
  290.     move.l  16(a0),d2
  291.     move.l  24(a0),d3
  292.  
  293.     move.l  a5,d6   ; d6 = 0x0x
  294.     move.l  a5,d7   ; d7 = 0x0x
  295.     and.l   d0,d6   ; d6 = 0b0r
  296.     and.l   d2,d7   ; d7 = 0j0z
  297.     eor.l   d6,d0   ; d0 = a0q0
  298.     eor.l   d7,d2   ; d2 = i0y0
  299.     lsl.l   #2,d6   ; d6 = b0r0
  300.     lsr.l   #2,d2   ; d2 = 0i0y
  301.     or.l    d2,d0           ; d0 = aiqy
  302.     or.l    d7,d6           ; d2 = bjrz
  303.     move.l  a5,d7   ; d7 = 0x0x
  304.     move.l  a5,d2   ; d2 = 0x0x
  305.     and.l   d1,d7   ; d7 = 0b0r
  306.     and.l   d3,d2   ; d2 = 0j0z
  307.     eor.l   d7,d1   ; d1 = a0q0
  308.     eor.l   d2,d3   ; d3 = i0y0
  309.     lsl.l   #2,d7   ; d7 = b0r0
  310.     lsr.l   #2,d3   ; d3 = 0i0y
  311.     or.l    d3,d1           ; d1 = aiqy
  312.     or.l    d2,d7           ; d3 = bjrz
  313.     move.l  a6,d2   ; d2 = 0x0x
  314.     move.l  a6,d3   ; d3 = 0x0x
  315.     and.l   d0,d2   ; d2 = 0b0r
  316.     and.l   d1,d3   ; d3 = 0j0z
  317.     eor.l   d2,d0   ; d0 = a0q0
  318.     eor.l   d3,d1   ; d1 = i0y0
  319.     lsr.l   #1,d1   ; d1 = 0i0y
  320.     or.l    d1,d0           ; d0 = aiqy
  321.     move.l  d0,plsiz*3(a1)
  322.     add.l   d2,d2
  323.     or.l    d3,d2           ; d1 = bjrz
  324.     move.l  d2,plsiz*2(a1)
  325.  
  326.     move.l  a6,d3   ; d3 = 0x0x
  327.     move.l  a6,d1   ; d1 = 0x0x
  328.     and.l   d6,d3   ; d3 = 0b0r
  329.     and.l   d7,d1   ; d1 = 0j0z
  330.     eor.l   d3,d6   ; d6 = a0q0
  331.     eor.l   d1,d7   ; d7 = i0y0
  332.     lsr.l   #1,d7   ; d7 = 0i0y
  333.     or.l    d7,d6           ; d6 = aiqy
  334.     move.l  d6,plsiz*1(a1)
  335.     add.l   d3,d3
  336.     or.l    d1,d3           ; d7 = bjrz
  337.     move.l  d3,(a1)+
  338.  
  339.     move.l  4(a0),d0
  340.     move.l  12(a0),d1
  341.     move.l  20(a0),d2
  342.     move.l  28(a0),d3
  343.  
  344.     move.l  a5,d6   ; d6 = 0x0x
  345.     move.l  a5,d7   ; d7 = 0x0x
  346.     and.l   d0,d6   ; d6 = 0b0r
  347.     and.l   d2,d7   ; d7 = 0j0z
  348.     eor.l   d6,d0   ; d0 = a0q0
  349.     eor.l   d7,d2   ; d2 = i0y0
  350.     lsl.l   #2,d6   ; d6 = b0r0
  351.     lsr.l   #2,d2   ; d2 = 0i0y
  352.     or.l    d2,d0           ; d0 = aiqy
  353.     or.l    d7,d6           ; d2 = bjrz
  354.     move.l  a5,d7   ; d7 = 0x0x
  355.     move.l  a5,d2   ; d2 = 0x0x
  356.     and.l   d1,d7   ; d7 = 0b0r
  357.     and.l   d3,d2   ; d2 = 0j0z
  358.     eor.l   d7,d1   ; d1 = a0q0
  359.     eor.l   d2,d3   ; d3 = i0y0
  360.     lsl.l   #2,d7   ; d7 = b0r0
  361.     lsr.l   #2,d3   ; d3 = 0i0y
  362.     or.l    d3,d1           ; d1 = aiqy
  363.     or.l    d2,d7           ; d3 = bjrz
  364.     move.l  a6,d2   ; d2 = 0x0x
  365.     move.l  a6,d3   ; d3 = 0x0x
  366.     and.l   d0,d2   ; d2 = 0b0r
  367.     and.l   d1,d3   ; d3 = 0j0z
  368.     eor.l   d2,d0   ; d0 = a0q0
  369.     eor.l   d3,d1   ; d1 = i0y0
  370.     lsr.l   #1,d1   ; d1 = 0i0y
  371.     or.l    d1,d0           ; d0 = aiqy
  372.     move.l  d0,-4-plsiz*1(a1)
  373.     add.l   d2,d2
  374.     or.l    d3,d2           ; d1 = bjrz
  375.     move.l  d2,-4-plsiz*2(a1)
  376.  
  377.     move.l  a6,d3   ; d3 = 0x0x
  378.     move.l  a6,d1   ; d1 = 0x0x
  379.     and.l   d6,d3   ; d3 = 0b0r
  380.     and.l   d7,d1   ; d1 = 0j0z
  381.     eor.l   d3,d6   ; d6 = a0q0
  382.     eor.l   d1,d7   ; d7 = i0y0
  383.     lsr.l   #1,d7   ; d7 = 0i0y
  384.     or.l    d7,d6           ; d6 = aiqy
  385.     move.l  d6,-4-plsiz*3(a1)
  386.     add.l   d3,d3
  387.     or.l    d1,d3           ; d7 = bjrz
  388.     move.l  d3,-4-plsiz*4(a1)
  389.     add.w   #32,a0  ;;4c
  390.     cmp.l   a0,a2   ;;4c
  391.     bne.w   .secondsweep     ;;6c
  392.  
  393.     ;300
  394.  
  395. .exit    movem.l    (sp)+,d2-d7/a2-a6
  396.     rts
  397.  
  398. .c2psize    Dc.l    320*200
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.     ; ----------------------------------------
  406.     ; --                                    --
  407.     ; --  All Macros for Demo Include File  --
  408.     ; --                                    --
  409.     ; ----------------------------------------
  410.  
  411.  
  412.  
  413.  
  414.     ; -------------
  415.     ; -- OFFSETS --
  416.     ; -------------
  417.  
  418.  
  419. VPOSR    = $004
  420. VHPOSR    = $006
  421.  
  422. JOY0DAT    = $00A
  423. JOY1DAT    = $00C
  424.  
  425. COP1LCH    = $080
  426. COP1LCL = $082
  427. COPJMP1    = $088
  428.  
  429. DIWSTRT    = $08E
  430. DIWSTOP    = $090
  431. DDFSTRT    = $092
  432. DDFSTOP    = $094
  433.  
  434. DMACON    = $096
  435.  
  436. BPL0PTH    = $0E0
  437. BPL0PTL = $0E2
  438. BPL1PTH    = $0E4
  439. BPL1PTL = $0E6
  440. BPL2PTH    = $0E8
  441. BPL2PTL = $0EA
  442. BPL3PTH    = $0EC
  443. BPL3PTL = $0EE
  444. BPL4PTH    = $0F0
  445. BPL4PTL = $0F2
  446. BPL5PTH    = $0F4
  447. BPL5PTL = $0F6
  448. BPL6PTH    = $0F8
  449. BPL6PTL = $0FA
  450. BPL7PTH    = $0FC
  451. BPL7PTL = $0FE
  452. BPLCON0    = $100
  453. BPLCON1    = $102
  454. BPLCON2    = $104
  455. BPLCON3    = $106
  456. BPL1MOD    = $108
  457. BPL2MOD    = $10A
  458. BPLCON4    = $10C
  459.  
  460. FMODE    = $1FC
  461.  
  462.  
  463.  
  464.     ; ------------------------
  465.     ; -- GRAPHICS FUNCTIONS --
  466.     ; ------------------------
  467.  
  468. _WaitVBL    MACRO
  469.     IFEQ    NARG-1
  470.       Move.w    d0,-(sp)
  471.       Move.w    #\1 - 1,d0
  472. .\@      Jsr    __WaitVBL
  473.       Dbra    d0,.\@
  474.       Move.w    (sp)+,d0
  475.     ELSE
  476.       Jsr    __WaitVBL
  477.     ENDC
  478.  
  479.     ENDM
  480.  
  481.  
  482. __WaitVBL
  483.     Move.l    d0,-(sp)
  484. .lp    Move.l    $DFF004,d0
  485.     Lsr.l    #8,d0            ; Just Vertical
  486.     And.w    #$01FF,d0
  487.     Cmp.w    #$0010,d0        ; Wait for line 16 (gives copper a
  488.     Bne.s    .lp            ;  chance to update!)
  489.     Move.l    (sp)+,d0
  490.  
  491. __WaitLine
  492.     Move.w    d0,-(sp)
  493.     Move.b    $DFF006,d0
  494.     Addq.b    #2,d0                ; Waits at least 1 scanline (no more than 2)
  495. .1    Cmp.b    $DFF006,d0
  496.     Bge.s    .1
  497.     Move.w    (sp)+,d0
  498.     Rts
  499.  
  500.  
  501.  
  502.  
  503. _LoadPalette24    MACRO
  504.     Movem.l    d0-4/a0-1,-(sp)
  505.     Lea    \1,a0
  506.     Lea    \2,a1
  507.     Move.w    #\3,d0
  508.     Subq.w    #1,d0
  509.     Jsr    __LoadPalette24
  510.     Movem.l    (sp)+,d0-4/a0-1
  511.     ENDM
  512.  
  513.  
  514. ColBank    MACRO
  515.     Ds.b    264*\1        ; Space for x ColourBanks
  516.     ENDM
  517.  
  518.  
  519. _LoadCList    MACRO
  520.     Move.l    #\1,$DFF080            ; Our Copperlist
  521.     Move.w    #$FFFF,$DFF088            ; Copper Strobe - Activate CLIST #1
  522.     ENDM
  523.  
  524.  
  525. _LoadPlanes    MACRO
  526.     Movem.l    d0-2/a0,-(sp)
  527.     Move.l    \1,d0            ; 1st Plane
  528.     Lea    \2,a0            ; CopperPlanePtr
  529.     Move.w    #\3,d1            ; Planes
  530.     Move.l    #\4,d2            ; Bitplane Modulo (gap between)
  531.     Jsr    __LoadPlanes
  532.     Movem.l    (sp)+,d0-2/a0
  533.     ENDM
  534.  
  535.  
  536. __LoadPlanes
  537.     Subq.w    #1,d1
  538. .1    Move.w    d0,6(a0)
  539.     Swap    d0
  540.     Move.w    d0,2(a0)
  541.     Swap    d0
  542.     Add.l    d2,d0
  543.     Lea    8(a0),a0
  544.     Dbra    d1,.1
  545.     Rts
  546.  
  547.  
  548.  
  549.     ; -----------------------
  550.     ; -- And Now Some Code --
  551.     ; -----------------------
  552.  
  553.  
  554.     ;
  555.     ;  PALETTE FUNCTIONS
  556.     ;
  557.  
  558.  
  559. __LoadPalette24
  560. ;    Move.l    #$01060020,d2        ; The Longword for BPLCON3  ** BorderBlank ON  **
  561.     Move.l    #$01060000,d2        ;                           ** Borderblank OFF **
  562.  
  563. .1    Move.l    d2,000(a1)        ; BPLCON3 HiColour Write
  564.     Bchg    #09,d2            ; Write Colour Low next time
  565.     Move.l    d2,132(a1)        ; BPLCON3 LoColour Write
  566.     Bchg    #09,d2            ; Write Colour Hi next time
  567.     Move.w    #$0180,d3        ; COL00
  568.     Moveq    #31,d4
  569.  
  570. .2    Move.l    (a0)+,d1
  571.     Ror.l    #4,d1
  572.     Ror.w    #4,d1
  573.     Ror.l    #4,d1
  574.     Ror.w    #4,d1
  575.     Ror.l    #4,d1
  576.     Ror.w    #4,d1
  577.     Ror.b    #4,d1
  578.     Rol.w    #4,d1
  579.     Swap    d1
  580.     Ror.w    #4,d1
  581.  
  582.     Move.w    d3,136(a1)
  583.     Move.w    d1,138(a1)        ; Low word
  584.     Swap    d1
  585.     Move.w    d3,004(a1)
  586.     Move.w    d1,006(a1)        ; High word
  587.     Add.l    #4,a1
  588.     Addq.w    #2,d3            ; Next Colour Palette Entry
  589.     Dbra    d4,.2
  590.  
  591.     Lea    136(a1),a1        ; Align for next row of 32 colours
  592.     Add.w    #$2000,d2        ; Next ColourBank In BPLCON3
  593.     Dbra    d0,.1            ; Next ColourBank
  594.  
  595.     Rts
  596.  
  597.  
  598.  
  599.  
  600.     ;
  601.     ; 3D LIBRARY VERSION 2.0 (16.12.97)
  602.     ;
  603.  
  604.  
  605.     ; OFFSETS:
  606.     ; --------
  607.  
  608. TD_POINTS    = $00        ; UWORD        # Points - 1
  609. TD_FACES    = $02        ; UWORD        # Faces - 1
  610. TD_PT_TABLE    = $04        ; APTR        Original Point-List
  611. TD_PT_BUFFER    = $08        ; APTR        Rotated Point-List
  612. TD_PT_PERSP    = $0C        ; APTR        3d->2d Persp. Point-List
  613. TD_XPOS        = $10        ; WORD
  614. TD_YPOS        = $12        ; WORD
  615. TD_ZPOS        = $14        ; WORD
  616. TD_XROT        = $16        ; UWORD        $000 - $1FF
  617. TD_YROT        = $18        ; UWORD
  618. TD_ZROT        = $1A        ; UWORD
  619. TD_LINESEGS    = $1C        ; APTR        Pointer To Line Segments
  620. TD_FACELIST    = $20        ; APTR        Pointer To FaceList
  621. TD_GORAUD    = $24        ; APTR        Pointer to goraud table
  622. TD_TEXELS    = $28        ; APTR        Pointer to texel coord list
  623. TD_DEPTHSORT    = $2C        ; APTR        Pointer to depth-sort array
  624.  
  625.  
  626.  
  627.     ; For Planar Polygons
  628.  
  629. TD_FACE_POINTS    = $00        ; UWORD        # LineSegs in Face - 1
  630. TD_FACE_COL0    = $02        ; UBYTE        Colour Of Face (in filled-mode)
  631. TD_FACE_COL1    = $03        ; UBYTE        <unimplemented>
  632. TD_FACE_PT1    = $04        ; UWORD        \  Clockwise ordering of 3
  633. TD_FACE_PT2    = $06        ; UWORD         > points in the plane (used 4
  634. TD_FACE_PT3    = $08        ; UWORD        /  back-surface elimination)
  635. TD_FACE_LINE    = $0A        ; UWORD        First LineSeg, Next Lineseg, ..
  636.  
  637.  
  638.     ; For Chunky GoraudShaded Polygons
  639.  
  640. TD_FACE_GS_PT1    = $00
  641.  
  642.  
  643.  
  644.     ; For Chunky Texturemapped Polygons
  645.  
  646. TD_FACE_TM_TXR    = $00        ; APTR        Base of the texture to use
  647. TD_FACE_TM_PT1    = $04        ; UWORD        First point in face
  648. TD_FACE_TM_TX1    = $06        ; UWORD        First texel lookup in face
  649.  
  650.  
  651.  
  652.     ; DATA SECTION:
  653.     ; -------------
  654.  
  655. DEF_SCRW    = 320        ; Default width
  656. DEF_SCRH    = 256        ; Default height
  657.  
  658. TD_ScrWidth    Dc.w    DEF_SCRW
  659. TD_ScrHeight    Dc.w    DEF_SCRH
  660. TD_Scr_MidX    Dc.w    DEF_SCRW/2
  661. TD_Scr_MidY    Dc.w    DEF_SCRH/2
  662. TD_ScrByteWidth    Dc.w    DEF_SCRW/8    ; For Planar Displays
  663.  
  664. TD_ClipX1    Dc.w    0
  665. TD_ClipY1    Dc.w    0
  666. TD_ClipX2    Dc.w    DEF_SCRW-1
  667. TD_ClipY2    Dc.w    DEF_SCRH-1
  668.  
  669. TD_TxrSize    Dc.w    0        ; Textuer Size: 0 - 32x32, 1 - 64x64, 2 - 128x128, 3 - 256,256
  670. TD_PixSize    Dc.w    0        ; Resolution  : 0 - 1x1 (or 2x2), 1 - 1x2, 2 - 2x1
  671.  
  672. TD_maxmin    Dc.l    0
  673. TD_edgebuffer    Ds.w    4*256        ; Max ScreenHeight = 255
  674. TD_txrbuffer    Ds.l    4*256
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.     ;
  684.     ; CHANGE SCREEN + CLIP REGIONS V1.0 (17.12.97)
  685.     ;                - Adjust the internal parameters for
  686.     ;                   screen size and clip region
  687.     ;
  688.     ; DEPENDENCIES:    'TD_Main.i'
  689.  
  690.  
  691.  
  692.     ; ---------------------
  693.     ; -- FUNCTION MACROS --
  694.     ; ---------------------
  695.  
  696. _TD_ChangeScreenSize    MACRO
  697.     Movem.l    d0-3,-(sp)
  698.     Move.w    #\1,d0
  699.     Move.w    #\2,d1
  700.     Jsr    TD_ChangeScreenSize
  701.     Movem.l    (sp)+,d0-3
  702.     ENDM
  703.  
  704. _TD_ChangeClipRegion    MACRO
  705.     Movem.l    d0-3,-(sp)
  706.     Move.w    #\1,d0
  707.     Move.w    #\2,d1
  708.     Move.w    #\3,d2
  709.     Move.w    #\4,d3
  710.     Jsr    TD_ChangeClipRegion
  711.     Movem.l    (sp)+,d0-3
  712.     ENDM
  713.  
  714. _TD_ChangeTxlSize    MACRO
  715.     Move.w    #\1,TD_TxrSize
  716.     ENDM
  717.  
  718. _TD_ChangePixSize    MACRO
  719.     Move.w    #\1,TD_PixSize
  720.     ENDM
  721.  
  722.  
  723.  
  724.  
  725.     ; -------------------
  726.     ; -- FUNCTION CODE --
  727.     ; -------------------
  728.  
  729.  
  730.     ;
  731.     ; TD_ChangeScreenSize
  732.     ;
  733.     ; PARAMETERS:    d0.w - ScreenWidth
  734.     ;        d1.w - ScreenHeight
  735.     ;
  736.     ; TRASHED REGS:    d0-d3
  737.     ;
  738.  
  739.  
  740. TD_ChangeScreenSize
  741.     Move.w    d0,TD_ScrWidth
  742.     Move.w    d1,TD_ScrHeight
  743.     Lsr.w    #1,d0
  744.     Lsr.w    #1,d1
  745.     Move.w    d0,TD_Scr_MidX
  746.     Move.w    d1,TD_Scr_MidY
  747.     Lsr.w    #2,d0                ; now /8
  748.     Move.w    d0,TD_ScrByteWidth
  749.     Rts
  750.  
  751.  
  752.  
  753.     ;
  754.     ; TD_ChangeClipRegion
  755.     ;
  756.     ; PARAMETERS:    d0-3 - x1,y1, x2,y2
  757.     ;
  758.     ; TRASHED REGS:    None
  759.     ;
  760.  
  761. TD_ChangeClipRegion
  762.     Move.w    d0,TD_ClipX1
  763.     Move.w    d1,TD_ClipY1
  764.     Move.w    d2,TD_ClipX2
  765.     Move.w    d3,TD_ClipY2
  766.     Rts
  767.  
  768.  
  769.  
  770.     ;
  771.     ; TD_ChangeTxlMask    - Change the texture size
  772.     ;
  773.     ; PARAMETERS:    d0.w    - New Texture Size
  774.     ;            - 0 - 32x32, 1 - 64x64, 2 - 128x128, 3 - 256x256
  775.     ; TRASHED REGS:    None
  776.     ;
  777.  
  778. TD_ChangeTxlSize
  779.     Move.w    d0,TD_TxrSize
  780.     Rts
  781.  
  782.  
  783.  
  784.  
  785.     ;
  786.     ; TD_ChangePixSize    - Change screen's pixel sizes
  787.     ;
  788.     ; PARAMETERS:    d0.w    - 0 = square pixels (1x1, 2x2), 1 = 1x2, 2 = 2x1
  789.     ;
  790.  
  791. TD_ChangePixSize
  792.     Move.w    d0,TD_PixSize
  793.     Rts
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.     ;
  802.     ; ROTATE POINTS V1.0 (16.12.97)
  803.     ;            - Rotate a set of points about axes
  804.     ;              in 3 dimensions
  805.     ;
  806.     ; PARAMETERS:    A0.l - Object Structure
  807.     ;
  808.     ; DEPENDENCIES:    TD_Sine.i
  809.     ;        TD_Main.i
  810.     ;
  811.     ; TRASHED REGS:    None
  812.     ;
  813.  
  814.  
  815.     ; MACRO DEFINITIONS:
  816.     ; ------------------
  817.  
  818. _TD_RotAbs    MACRO
  819.         Lea    \1,a0
  820.         Move.w    #\2,d0    
  821.         Move.w    #\3,d1
  822.         Move.w    #\4,d2
  823.         Jsr    TD_RotAbs
  824.         ENDM
  825.  
  826. _TD_RotRel    MACRO
  827.         Lea    \1,a0
  828.         Move.w    #\2,d0    
  829.         Move.w    #\3,d1
  830.         Move.w    #\4,d2
  831.         Jsr    TD_RotRel
  832.         ENDM
  833.  
  834. _TD_MovAbs    MACRO
  835.         Lea    \1,a0
  836.         Move.w    #\2,d0    
  837.         Move.w    #\3,d1
  838.         Move.w    #\4,d2
  839.         Jsr    TD_MovAbs
  840.         ENDM
  841.  
  842. _TD_MovRel    MACRO
  843.         Lea    \1,a0
  844.         Move.w    #\2,d0    
  845.         Move.w    #\3,d1
  846.         Move.w    #\4,d2
  847.         Jsr    TD_MovRel
  848.         ENDM
  849.  
  850.  
  851. _TD_Rot        MACRO
  852.         Lea    \1,a0
  853.         Jsr    TD_Rot
  854.         ENDM
  855.  
  856.  
  857.  
  858.     ; CODE TO DO IT:
  859.     ; --------------
  860.  
  861. TD_RotRel
  862.     Add.w    TD_XROT(a0),d0
  863.     And.w    #$01FF,d0
  864.     Move.w    d0,TD_XROT(a0)
  865.     Add.w    TD_YROT(a0),d1
  866.     And.w    #$01FF,d1
  867.     Move.w    d1,TD_YROT(a0)
  868.     Add.w    TD_ZROT(a0),d2
  869.     And.w    #$01FF,d2
  870.     Move.w    d2,TD_ZROT(a0)
  871.     Rts
  872.  
  873. TD_RotAbs
  874.     And.w    #$01FF,d0
  875.     Move.w    d0,TD_XROT(a0)
  876.     And.w    #$01FF,d1
  877.     Move.w    d1,TD_YROT(a0)
  878.     And.w    #$01FF,d2
  879.     Move.w    d2,TD_ZROT(a0)
  880.     Rts
  881.  
  882.  
  883. TD_MovRel
  884.     Add.w    d0,TD_XPOS(a0)
  885.     Add.w    d1,TD_YPOS(a0)
  886.     Add.w    d2,TD_ZPOS(a0)
  887.     Rts
  888.  
  889. TD_MovAbs
  890.     Move.w    d0,TD_XPOS(a0)
  891.     Move.w    d1,TD_YPOS(a0)
  892.     Move.w    d2,TD_ZPOS(a0)
  893.     Rts
  894.  
  895.  
  896.  
  897.  
  898. TD_Rot    Movem.l    d0-7/a1-4,-(sp)
  899.  
  900.     Lea    TD_Sine,a1        ; Sine Table
  901.     Lea    TD_Cosine,a2        ; Cosine Tble
  902.  
  903.     Move.l    TD_PT_TABLE(a0),a3    ; Source Point Table
  904.     Move.l    TD_PT_BUFFER(a0),a4    ; Dest Rotated Points
  905.  
  906.     Move.w    TD_POINTS(a0),d7    ; # Points to rotate - 1
  907.  
  908. .rotlp                    ; ZXY Rotation
  909.     ;-- Z Rotation --
  910.  
  911.     Move.w    TD_ZROT(a0),d0
  912.     Move.w    0(a2,d0.w*2),d1        ; Cos(ZAngle)
  913.     Move.w    0(a1,d0.w*2),d0        ; Sin(ZAngle)
  914.  
  915.     Move.w    (a3)+,d2        ; D2.w - X
  916.     Asl.w    #4,d2
  917.     Move.w    (a3)+,d3        ; D3.w - Y
  918.     Asl.w    #4,d3
  919.     Move.w    d3,d5
  920.     Move.w    d2,d4
  921.  
  922.     Muls    d1,d2            ; D2.l - 4096.X.Cos(ZAngle)
  923.     Muls    d0,d5            ; D5.l - 4096.Y.Sin(ZAngle)
  924.  
  925.     Sub.l    d5,d2        ; D2.l - 4096.X' = 4096.[X.Cos(ZA) - Y.Sin(ZA)]
  926.     Asr.l    #8,d2        ; D2.w - 256.X'
  927.  
  928.     Muls    d0,d4            ; D4.l - 4096.X.Sin(ZAngle)
  929.     Muls    d1,d3            ; D3.l - 4096.Y.Cos(ZAngle)
  930.  
  931.     Add.l    d4,d3        ; D3.l - 4096.Y' = 4096.[X.Sin(ZA) + Y.Cos(ZA)]
  932.     Asr.l    #8,d3        ; D3.w - 16.Y'
  933.  
  934.     ;-- Y Rotation --
  935.  
  936.     Move.w    TD_YROT(a0),d0
  937.     Move.w    0(a2,d0.w*2),d1        ; Cos(YAngle)
  938.     Move.w    0(a1,d0.w*2),d0        ; Sin(YAngle)
  939.  
  940.     Move.w    (a3)+,d4
  941.     Asl.w    #4,d4            ; D4.w - 16.Z
  942.     Move.w    d4,d6
  943.     Move.w    d2,d5
  944.  
  945.     Muls    d1,d4            ; D4.l - 4096.Z .Cos(YAngle)
  946.     Muls    d0,d5            ; D5.l - 4096.X'.Sin(YAngle)
  947.  
  948.     Sub.l    d5,d4        ; D4.l - 4096.[Z.Cos(YA) - X'.Sin(YA)]
  949.     Asr.l    #8,d4        ; D4.w - 16.Z'
  950.  
  951.     Muls    d0,d6            ; D6.l - 4096.Z .Sin(YAngle)
  952.     Muls    d1,d2            ; D2.l - 4096.X'.Cos(YAngle)
  953.  
  954.     Add.l    d6,d2        ; D2.l - 4096.[Z.Sin(YA) + X'.Cos(YA)]
  955.     Asr.l    #8,d2        ; D2.w - 16.X''
  956.  
  957.     Move.w    d2,(a4)+        ; X'' -> Rotated_Point-Buffer
  958.  
  959.     ;-- X Rotation --
  960.  
  961.     Move.w    TD_XROT(a0),d0
  962.     Move.w    0(a2,d0.w*2),d1
  963.     Move.w    0(a1,d0.w*2),d0
  964.  
  965.     Move.w    d3,d2            ; D3.w=D2.w - 16.Y'
  966.     Move.w    d4,d5            ; D4.w=d5.w - 16.Z'
  967.  
  968.     Muls    d1,d3            ; D3.l - 4096.Y'.Cos(XAngle)
  969.     Muls    d0,d5            ; D5.l - 4096.Z'.Sin(XAngle)
  970.  
  971.     Sub.l    d5,d3        ; D3.l - 4096.[Y'.Cos(XA) - Z'.Sin(XA)]
  972.     Asr.l    #8,d3        ; D3.w - 16.Y''
  973.  
  974.     Move.w    d3,(a4)+        ; Y'' -> Rotated_Point-Buffer
  975.  
  976.     Muls    d0,d2            ; D2.l - 4096.Y'.Sin(XAngle)
  977.     Muls    d1,d4            ; D4.l - 4096.Z'.Cos(XAngle)
  978.         
  979.     Add.l    d2,d4        ; D3.l - 4096.[Y'.Sin(XA) + Z'.Cos(XA)]
  980.     Asr.l    #8,d4        ; D3.w - 16.Z''
  981.  
  982.     Asr.l    #4,d4
  983.     Move.w    d4,(a4)+        ; Z'' -> Rotated_Point-Buffer
  984.  
  985.     ;-- Done Rotations --
  986.  
  987.     Dbra    d7,.rotlp            ; And Loop It For All Points
  988.  
  989.     Movem.l    (sp)+,d0-7/a1-4
  990.  
  991.  
  992.     ; ----------------------------------
  993.     ; -- Calculate Perspective Points --    ; ** Actually no perspective now ;) **
  994.     ; ----------------------------------
  995.  
  996.     Movem.l    d0-4/a0-2,-(sp)
  997.     Move.w    TD_POINTS(a0),d3
  998.     Move.l    TD_PT_PERSP(a0),a1
  999.     Move.l    TD_PT_BUFFER(a0),a2
  1000. .1    Movem.w    (a2)+,d0-2
  1001.  
  1002.     Move.w    TD_XPOS(a0),d4
  1003.     Add.w    d4,d0
  1004.     Move.w    TD_YPOS(a0),d4
  1005.     Add.w    d4,d1
  1006.  
  1007.     Add.w    TD_Scr_MidX,d0        ; Centre X Coord
  1008.     Move.w    d0,(a1)+
  1009.     Add.w    TD_Scr_MidY,d1        ; Centre Y Coord
  1010.     Move.w    d1,(a1)+
  1011. .endl    Dbra    d3,.1
  1012.  
  1013.     Movem.l    (sp)+,d0-4/a0-2
  1014.     Rts                    ; -> RETURN <-
  1015.  
  1016.  
  1017.  
  1018.     ;
  1019.     ; ROTATE POINTS V1.0 (16.12.97)
  1020.     ;            - Rotate a set of points about axes
  1021.     ;              in 3 dimensions
  1022.     ;
  1023.     ; PARAMETERS:    A0.l - Object Structure
  1024.     ;
  1025.     ; DEPENDENCIES:    TD_Sine.i
  1026.     ;        TD_Main.i
  1027.     ;
  1028.     ; TRASHED REGS:    None
  1029.     ;
  1030.  
  1031. _TD_Rot2    MACRO
  1032.         Lea    \1,a0
  1033.         Jsr    TD_Rot2
  1034.         ENDM
  1035.  
  1036.  
  1037.  
  1038. TD_Rot2    Movem.l    d0-7/a1-4,-(sp)
  1039.  
  1040.     Lea    TD_Sine,a1        ; Sine Table
  1041.     Lea    TD_Cosine,a2        ; Cosine Tble
  1042.  
  1043.     Move.l    TD_PT_TABLE(a0),a3    ; Source Point Table
  1044.     Move.l    TD_PT_BUFFER(a0),a4    ; Dest Rotated Points
  1045.  
  1046.     Move.w    TD_POINTS(a0),d7    ; # Points to rotate - 1
  1047.  
  1048. .rotlp                    ; ZXY Rotation
  1049.     ;-- Z Rotation --
  1050.  
  1051.     Move.w    TD_ZROT(a0),d0
  1052.     Move.w    0(a2,d0.w*2),d1        ; Cos(ZAngle)
  1053.     Move.w    0(a1,d0.w*2),d0        ; Sin(ZAngle)
  1054.  
  1055.     Move.w    (a3)+,d2        ; D2.w - X
  1056.     Asl.w    #4,d2
  1057.     Move.w    (a3)+,d3        ; D3.w - Y
  1058.     Asl.w    #4,d3
  1059.     Move.w    d3,d5
  1060.     Move.w    d2,d4
  1061.  
  1062.     Muls    d1,d2            ; D2.l - 4096.X.Cos(ZAngle)
  1063.     Muls    d0,d5            ; D5.l - 4096.Y.Sin(ZAngle)
  1064.  
  1065.     Sub.l    d5,d2        ; D2.l - 4096.X' = 4096.[X.Cos(ZA) - Y.Sin(ZA)]
  1066.     Asr.l    #8,d2        ; D2.w - 256.X'
  1067.  
  1068.     Muls    d0,d4            ; D4.l - 4096.X.Sin(ZAngle)
  1069.     Muls    d1,d3            ; D3.l - 4096.Y.Cos(ZAngle)
  1070.  
  1071.     Add.l    d4,d3        ; D3.l - 4096.Y' = 4096.[X.Sin(ZA) + Y.Cos(ZA)]
  1072.     Asr.l    #8,d3        ; D3.w - 16.Y'
  1073.  
  1074.     ;-- Y Rotation --
  1075.  
  1076.     Move.w    TD_YROT(a0),d0
  1077.     Move.w    0(a2,d0.w*2),d1        ; Cos(YAngle)
  1078.     Move.w    0(a1,d0.w*2),d0        ; Sin(YAngle)
  1079.  
  1080.     Move.w    (a3)+,d4
  1081.     Asl.w    #4,d4            ; D4.w - 16.Z
  1082.     Move.w    d4,d6
  1083.     Move.w    d2,d5
  1084.  
  1085.     Muls    d1,d4            ; D4.l - 4096.Z .Cos(YAngle)
  1086.     Muls    d0,d5            ; D5.l - 4096.X'.Sin(YAngle)
  1087.  
  1088.     Sub.l    d5,d4        ; D4.l - 4096.[Z.Cos(YA) - X'.Sin(YA)]
  1089.     Asr.l    #8,d4        ; D4.w - 16.Z'
  1090.  
  1091.     Muls    d0,d6            ; D6.l - 4096.Z .Sin(YAngle)
  1092.     Muls    d1,d2            ; D2.l - 4096.X'.Cos(YAngle)
  1093.  
  1094.     Add.l    d6,d2        ; D2.l - 4096.[Z.Sin(YA) + X'.Cos(YA)]
  1095.     Asr.l    #8,d2        ; D2.w - 16.X''
  1096.  
  1097.     Move.w    d2,(a4)+        ; X'' -> Rotated_Point-Buffer
  1098.  
  1099.     ;-- X Rotation --
  1100.  
  1101.     Move.w    TD_XROT(a0),d0
  1102.     Move.w    0(a2,d0.w*2),d1
  1103.     Move.w    0(a1,d0.w*2),d0
  1104.  
  1105.     Move.w    d3,d2            ; D3.w=D2.w - 16.Y'
  1106.     Move.w    d4,d5            ; D4.w=d5.w - 16.Z'
  1107.  
  1108.     Muls    d1,d3            ; D3.l - 4096.Y'.Cos(XAngle)
  1109.     Muls    d0,d5            ; D5.l - 4096.Z'.Sin(XAngle)
  1110.  
  1111.     Sub.l    d5,d3        ; D3.l - 4096.[Y'.Cos(XA) - Z'.Sin(XA)]
  1112.     Asr.l    #8,d3        ; D3.w - 16.Y''
  1113.  
  1114.     Move.w    d3,(a4)+        ; Y'' -> Rotated_Point-Buffer
  1115.  
  1116.     Muls    d0,d2            ; D2.l - 4096.Y'.Sin(XAngle)
  1117.     Muls    d1,d4            ; D4.l - 4096.Z'.Cos(XAngle)
  1118.         
  1119.     Add.l    d2,d4        ; D3.l - 4096.[Y'.Sin(XA) + Z'.Cos(XA)]
  1120.     Asr.l    #8,d4        ; D3.w - 16.Z''
  1121.  
  1122.     Asr.l    #4,d4
  1123.     Move.w    d4,(a4)+        ; Z'' -> Rotated_Point-Buffer
  1124.  
  1125.     ;-- Done Rotations --
  1126.  
  1127.     Dbra    d7,.rotlp            ; And Loop It For All Points
  1128.  
  1129.     Movem.l    (sp)+,d0-7/a1-4
  1130.  
  1131.  
  1132.     ; ----------------------------------
  1133.     ; -- Calculate Perspective Points --
  1134.     ; ----------------------------------
  1135.  
  1136.     Movem.l    d0-4/a0-2,-(sp)
  1137.     Move.w    TD_POINTS(a0),d3
  1138.     Move.l    TD_PT_PERSP(a0),a1
  1139.     Move.l    TD_PT_BUFFER(a0),a2
  1140. .1    Movem.w    (a2)+,d0-2
  1141.  
  1142.     Move.w    TD_XPOS(a0),d4
  1143.     Asl.w    #4,d4
  1144.     Add.w    d4,d0
  1145.     Ext.l    d0
  1146.     Asl.l    #4,d0
  1147.  
  1148.     Move.w    TD_YPOS(a0),d4
  1149.     Asl.w    #4,d4
  1150.     Add.w    d4,d1
  1151.     Ext.l    d1
  1152.     Asl.l    #4,d1
  1153.  
  1154.     Add.w    TD_ZPOS(a0),d2
  1155.     Add.w    #256,d2                ; Mystery Add Factor (!)
  1156.     Cmp.w    #50,d2                ; Check for safe Z values
  1157.     Ble.s    .emerg                ;  -> Close to Zero !!
  1158.  
  1159.     Divs    d2,d0
  1160.     Add.w    TD_Scr_MidX,d0        ; Centre X Coord
  1161.     Move.w    d0,(a1)+
  1162.     Divs    d2,d1
  1163.     Add.w    TD_Scr_MidY,d1        ; Centre Y Coord
  1164.     Move.w    d1,(a1)+
  1165. .endl    Dbra    d3,.1
  1166.  
  1167.     Movem.l    (sp)+,d0-4/a0-2
  1168.     Rts                    ; -> RETURN <-
  1169.  
  1170.  
  1171. .emerg    Move.w    #0,(a1)+            ; Emergency Error (Close to DivZero)
  1172.     Move.w    #0,(a1)+
  1173.     Bra.s    .endl
  1174.  
  1175.  
  1176.  
  1177.  
  1178.     ;
  1179.     ; TD_InsertSort - Perform depth-sorting on an array
  1180.     ;
  1181.     ;
  1182.     ; PARAMETERS:    d0.w - Number of elements to process
  1183.     ;        a0.l - Array of values to sort
  1184.     ;
  1185.     ; NOTES:    The array contains (value.w, depth.w) pairs. Sorting is done
  1186.     ;        on the 'depth' key, and is from largest depth to smallest.
  1187.     ;        Depth is in the range -32768..32767
  1188.     ;
  1189.  
  1190.  
  1191. TD_InsertSort
  1192.  
  1193. .3    Move.w    #$7FFF,d2            ; d2.w - MaxVal
  1194.     Move.w    d0,d1                ; Start Of Scan
  1195. .2    Cmp.w    2(a0,d1.w*4),d2
  1196.     Ble.s    .1
  1197.     Move.w    d1,d3                ; New Min -> Save Position
  1198.     Move.l    0(a0,d1.w*4),d2            ;         -> New Min Value
  1199. .1    Dbra    d1,.2
  1200.     Move.l    0(a0,d0.w*4),0(a0,d3.w*4)
  1201.     Move.l    d2,0(a0,d0.w*4)            ; Put next smallest Z-val at END of array!
  1202.     Dbra    d0,.3
  1203.     Rts
  1204.  
  1205.  
  1206.  
  1207.     ;
  1208.     ; TEXTUREMAPPING CODE V1.2 (07.04.98)
  1209.     ;
  1210.     ;
  1211.     ; NOTES:    This code is really very ugly. Hopefully I'll do a rewrite soon,
  1212.     ;        but for now this is it!! Damn, I need some more sleep ;)
  1213.     ;        As always, it's really badly optimised. Oh well, I tried... ;)
  1214.     ;
  1215.     ;        060 sore-points are noted. I can't see a neat way of getting around
  1216.     ;        these yet, so they are staying. At least the 2 Divs.l per scanline
  1217.     ;        were replaced by Divs (lose a bit of resolution, but works OK!!)
  1218.     ;
  1219.     ;        Finally tracked down the Z-sorting bug in both this and the goraud
  1220.     ;        engine! :)  I feel better now!
  1221.     ;
  1222.     ; TO DO:    Hopefully fixed the weird bug where objects were not back-surface
  1223.     ;        eliminated properly (it was a stupid mixup in which registers were
  1224.     ;        used as aprameters for the TD_ChkNorm function).
  1225.     ;
  1226.     ;        Also found a bug in the TD_ChkNorm function itself. Had the wrong
  1227.     ;        offsets for reading the points out of the face structure. Now fixed.
  1228.     ;        Mystery back-surface problems gone forever!!! :)
  1229.     ;
  1230.     ;        Also, don't add all the bloody faces in to the sort. Even insertion
  1231.     ;        sort is not incredibly fast for > 20 faces, so I should be back-surface
  1232.     ;        eliminating _before_ inserting them into the array, eliminating ~1/2
  1233.     ;        of the faces right there (= big speed increase!)
  1234.     ;
  1235.  
  1236.  
  1237.  
  1238.     ; --+---------------+--
  1239.     ; --| TD_Ck_TmapObj |--
  1240.     ; --+---------------+--
  1241.  
  1242. TD_Ck_TmapObj
  1243.  
  1244.     ; A0.l - Object Structure
  1245.     ; A1.l - Chunky Buffer
  1246.  
  1247.     Movem.l    d0/a2-3,-(sp)
  1248.     Move.w    TD_FACES(a0),d0        ; # of faces to draw
  1249.     Move.l    TD_FACELIST(a0),a3    ; Address of FaceList
  1250. .tmplp    Move.l    (a3)+,a2        ; Address of face
  1251.     Movem.l    d0/a0-3,-(sp)
  1252.     Bsr.s    TD_ChkNorm            ; Do we need to draw it?
  1253.     Bne.s    .skipdraw        ;  NUP -> Skip the rest
  1254.     Bsr.s    TD_Mapper
  1255. .skipdraw
  1256.     Movem.l    (sp)+,d0/a0-3
  1257.     Dbra    d0,.tmplp
  1258.  
  1259.     Movem.l    (sp)+,d0/a2-3
  1260.     Rts
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.     ; --+-------------------------+--
  1267.     ; --| TD_Ck_DepthSort_TmapObj |--
  1268.     ; --+-------------------------+--
  1269.  
  1270. TD_Ck_DepthSort_TmapObj
  1271.  
  1272.     ; A0.l - Object Structure
  1273.     ; A1.l - Chunky Buffer
  1274.  
  1275.     Movem.l    d0-7/a0-6,-(sp)
  1276.  
  1277.  
  1278.     ;-- UPDATE DEPTHSORTARRAY --
  1279.     Move.l    a5,-(sp)
  1280.     Move.w    TD_FACES(a0),d0            ; # Faces-1 to process
  1281.     Move.l    TD_FACELIST(a0),a3        ; Ptr to faces
  1282.     Move.l    TD_DEPTHSORT(a0),a4        ; Ptr to DS-Array
  1283.     Move.l    TD_PT_BUFFER(a0),a5        ; Ptr to 3D Rotated Pts
  1284. .flp    Move.l    0(a3,d0.w*4),a2            ; Current Face
  1285.     Lea    4(a2),a2
  1286.     Move.w    d0,(a4)+        ; Face #
  1287.     ;----------------------
  1288.     Moveq    #0,d2
  1289.     Move.w    d2,d3
  1290. .zlp    Move.w    (a2),d1                ; Point Offset
  1291.     Blt.s    .zdone
  1292.     Addq.w    #1,d3
  1293.     Lea    4(a2),a2            ; Next Point
  1294.     Mulu    #6,d1
  1295.     Add.w    4(a5,d1),d2            ; Add to total
  1296.     Bra.s    .zlp
  1297. .zdone    Ext.l    d2
  1298.     Divs    d3,d2                ; D2.w = Middle Z Coord
  1299.     ;----------------------
  1300.     Move.w    d2,(a4)+        ; Z Coord (minimum for face)
  1301.     Dbra    d0,.flp
  1302.     Move.l    (sp)+,a5
  1303.  
  1304.  
  1305.     ;-- Depth-Sort the FaceList --
  1306.     Move.l    a0,-(sp)
  1307.     Move.w    TD_FACES(a0),d0            ; # Faces-1 to process
  1308.     Move.l    TD_DEPTHSORT(a0),a0        ; Ptr to DS-Array
  1309.     Bsr    TD_InsertSort            ; d0.w - entries, a0.l - array base
  1310.     Move.l    (sp)+,a0
  1311.  
  1312.  
  1313.     ;-- DRAW FACES --
  1314.     Move.w    TD_FACES(a0),d0        ; # of faces to draw
  1315.     Move.l    TD_FACELIST(a0),a3    ; Address of FaceList
  1316.     Move.l    TD_DEPTHSORT(a0),a4    ; -> DepthSortArray
  1317. .tmplp    Move.w    (a4),d1            ; Face #
  1318.     Lea    4(a4),a4        ; Next Face# In List
  1319.     Move.l    (a3,d1.w*4),a2        ; Address of face
  1320.     Movem.l    d0/a0-4,-(sp)
  1321.     Bsr.s    TD_ChkNorm            ; Do we need to draw it?
  1322.     Bne.s    .skipdraw        ;  NUP -> Skip the rest
  1323.     Bsr.s    TD_Mapper
  1324. .skipdraw
  1325.     Movem.l    (sp)+,d0/a0-4
  1326.     Dbra    d0,.tmplp
  1327.  
  1328.  
  1329.     Movem.l    (sp)+,d0-7/a0-6
  1330.     Rts
  1331.  
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338.     ; --+----------------------------+--
  1339.     ; --| Check Face's Normal Vector |--
  1340.     ; --+----------------------------+--
  1341.  
  1342. TD_ChkNorm
  1343.  
  1344.     ; CHECK NORMAL OF A FACE V1.0 (16.01.97)
  1345.     ;        - This version for tmapped polys
  1346.     ;
  1347.     ;
  1348.     ; PARAMETERS:    a0.l    - Object Base Address
  1349.     ;        a2.l    - Face Structure
  1350.     ;
  1351.     ; RETURNS:    d0.w    - 0 = Invisible, 1 = Visible
  1352.     ;
  1353.     ; NOTES:    Points order should be clockwise, or the values
  1354.     ;         returned will be opposite to what you expect!!
  1355.     ;
  1356.  
  1357.     Movem.l    d1-5/a3,-(sp)
  1358.  
  1359.     Move.l    TD_PT_PERSP(a0),a3    ; A3.l - 2D Points List
  1360.     Move.w    4(a2),d1
  1361.     Move.w    0(a3,d1.w*4),d0        ; X1
  1362.     Move.w    2(a3,d1.w*4),d1        ; Y1
  1363.     Move.w    8(a2),d3
  1364.     Move.w    0(a3,d3.w*4),d2        ; X2
  1365.     Move.w    2(a3,d3.w*4),d3        ; Y2
  1366.     Move.w    12(a2),d5
  1367.     Move.w    0(a3,d5.w*4),d4        ; X3
  1368.     Move.w    2(a3,d5.w*4),d5        ; Y3
  1369.     ;-- NOW CHECK THE NORMAL --
  1370.     Sub.w    d0,d4        ; d4.w = (x3-x1)
  1371.     Sub.w    d1,d3        ; d3.w = (y2-y1)
  1372.     Sub.w    d0,d2        ; d2.w = (x2-x1)
  1373.     Sub.w    d1,d5        ; d5.w = (y3-y1)
  1374.     Muls    d4,d3        ; (x3-x1)*(y2-y1)
  1375.     Muls    d2,d5        ; (x2-x1)*(y3-y1)
  1376.     Sub.l    d5,d3        ; c =  [(x3-x1)*(y2-y1)] - [(x2-x1)*(y3-y1)]
  1377.     Ble.s    .noset        ; < 0 so can't be seen
  1378.  
  1379. .set    Movem.l    (sp)+,d1-5/a3
  1380.     Moveq    #1,d0
  1381.     Rts
  1382. .noset    Movem.l    (sp)+,d1-5/a3
  1383.     Moveq    #0,d0
  1384.     Rts
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.     ; --+---------------------+--
  1391.     ; --| Texturemap One Face |--
  1392.     ; --+---------------------+--
  1393.  
  1394. TD_Mapper
  1395.  
  1396.     ; A0.l - Object Structure
  1397.     ; A1.l - Chunky Buffer
  1398.     ; A2.l - Face Structure Pointer
  1399.  
  1400.  
  1401.  
  1402.  
  1403.     ;-- Draw line to edge-buffer --
  1404.  
  1405.     Movem.l    d0-7/a0-6,-(sp)
  1406.  
  1407.     Lea    TD_FACE_TM_PT1(a2),a3        ; Start of point/texel pairs
  1408.     Move.l    TD_PT_PERSP(a0),a4
  1409.     Move.l    TD_TEXELS(a0),a5
  1410.  
  1411.     Moveq    #0,d0
  1412.     Move.w    TD_ScrHeight,d0
  1413.     Subq.w    #1,d0
  1414.     Swap    d0                ; d0.l = [ ScrHeight-1.w | 0.w ]
  1415.     Move.l    d0,TD_maxmin
  1416. ;    Move.l    #(200<<16),TD_maxmin
  1417.  
  1418.  
  1419.  
  1420. .linelp    Move.w    (a3)+,d0        ; pt_1
  1421.     Move.w    (a3)+,d1        ; tx_1
  1422.     Move.w    0(a5,d1.w*4),d4        ; u1
  1423.     Move.w    2(a5,d1.w*4),d5        ; v1
  1424.     Move.w    2(a4,d0.w*4),d1        ; y1
  1425.     Move.w    0(a4,d0.w*4),d0        ; x1
  1426.  
  1427.  
  1428.     Move.w    0(a3),d2        ; pt_2
  1429.     Bmi.s    .drawit            ; GOT A '-1' (END)
  1430.     Move.w    2(a3),d3        ; tx_2
  1431.     Move.w    0(a5,d3.w*4),d6        ; u2
  1432.     Move.w    2(a5,d3.w*4),d7        ; v2
  1433.     Move.w    2(a4,d2.w*4),d3        ; y2
  1434.     Move.w    0(a4,d2.w*4),d2        ; x2
  1435.  
  1436.     Bsr    .DrawLine        ; Draw to edge buffer
  1437.     Bra.s    .linelp
  1438.  
  1439.     ;-- Now draw it properly --
  1440.  
  1441. .drawit
  1442.  
  1443.     Lea    TD_edgebuffer,a3
  1444.     Move.l    TD_FACE_TM_TXR(a2),a4    ; The texture map to use (64x64)
  1445.     Lea    TD_txrbuffer,a5
  1446.  
  1447.  
  1448.     Move.l    TD_maxmin,d0
  1449.     Move.w    d0,d1
  1450.     Swap    d0
  1451.     Sub.w    d0,d1
  1452.     Lea    0(a3,d0.w*4),a3        ; A3.l - Start of edges coords
  1453.     Lsl.w    #4,d0
  1454.     Lea    0(a5,d0.w),a5        ; A5.l - Start of tmap coords [left x.y | right x.y]
  1455.     Lsr.w    #4,d0
  1456.     Mulu    TD_ScrWidth,d0
  1457.     Lea    0(a1,d0.l),a1        ; A1.l - Start of screen to draw
  1458.     Move.w    d1,d0            ; D0.w - # of lines to draw
  1459.  
  1460.     Subq    #1,d0
  1461.     Bmi.s    .end            ; DON'T DRAW IF NEGATIVE!!
  1462.  
  1463.     
  1464.  
  1465.     ; -- Check For Texture Size --
  1466.     Move.w    TD_TxrSize,d7
  1467.     Bne.s    .3f
  1468.     Move.w    #$1F1F,d7        ; 32x32 texture
  1469.     Bra.s    .drawlp
  1470. .3f    Cmp.w    #$01,d7
  1471.     Bne.s    .7f
  1472.     Move.w    #$3F3F,d7        ; 64x64
  1473.     Bra.s    .drawlp
  1474. .7f    Cmp.w    #$02,d7
  1475.     Bne.s    .ff
  1476.     Move.w    #$7F7F,d7        ; 128x128
  1477.     Bra.s    .drawlp
  1478. .ff    Move.w    #$FFFF,d7        ; 256x256
  1479.  
  1480.  
  1481.  
  1482.     ; --+-- SCANLINE LOOP --+--
  1483.  
  1484. .drawlp    Movem.w    (a3)+,d1-2        ; d1.w - Start x pixel
  1485.     Sub.w    d1,d2            ; d2.w - x delta
  1486.     Ble.s    .nodraw            ;      - Was neg or zero, don't draw!!
  1487.     Movem.l    (a5)+,d3-6        ; u1,v1, u2,v2 coords [24.8]
  1488.     Sub.l    d3,d5            ; d5.l - u delta (total)
  1489.     Sub.l    d4,d6            ; d6.l - v delta (total)
  1490.  
  1491.     Divs    d2,d5            ; d5.l - [-.-.8.8] U delta
  1492.     Divs    d2,d6            ; d6.l - [-.-.8.8] V Delta
  1493.     And.l    #$FFFF,d5        ; * We lose some accuracy by not using Divs.l
  1494.     And.l    #$FFFF,d6        ;   but 060 owners should thank me for it! ;)
  1495.  
  1496.     And.l    #$FFFF,d1
  1497.     Ror.l    #8,d3            ; Now [8.-.-.8] as [frac.-.-.int]
  1498.     Ror.l    #8,d5            ; Now [8.-.-.8] as [frac.-.-.int]
  1499.     Subq.w    #1,d2            ; Compensate for Dbra's extra loop
  1500.  
  1501.  
  1502.     Movem.l    d0/d7/a1,-(sp)
  1503.     Lea    0(a1,d1.l),a1        ; Add Start X to write offset
  1504.  
  1505.     Move.w    d7,d1            ; d1.w - Texture Mask
  1506.     Moveq    #0,d7            ; d7.l - Always Zero (used for Addx later!)
  1507.     Move.l    d7,d0            ; d0.l - 0
  1508.  
  1509.  
  1510.     ; --+-- INNER LOOP --+--
  1511.  
  1512.     ; d0.w - * Texel Address Offset (calcuated)
  1513.     ; d1.w -   Texture Mask
  1514.     ; d2.w -   Loop Counter
  1515.     ; d3.l -   U (x) [8.24]
  1516.     ; d4.l -   V (y) [24.8]
  1517.     ; d5.l -   U Delta [8.24]
  1518.     ; d6.l -   V Delta [24.8]
  1519.     ; d7.l -   0
  1520.  
  1521.     ; a1.l - Chunky Buffer
  1522.     ; a4.l - Texture Base
  1523.  
  1524.  
  1525. .inner    Move.w    d4,d0
  1526.     Add.l    d6,d4        ;   V Delta Add
  1527.     Move.b    d3,d0
  1528.     Add.l    d5,d3        ; \ U Delta Add
  1529.     Addx.l    d7,d3        ; /
  1530.     And.w    d1,d0        ; Mask the texture (may not be needed!!)
  1531.     Move.b    0(a4,d0.l),d0    ; Texel
  1532.     Move.b    d0,(a1)+
  1533.     Dbra    d2,.inner
  1534.     ;--+-- END INNER LOOP --+--
  1535.  
  1536.     Movem.l    (sp)+,d0/d7/a1
  1537. .nodraw    Add.w    TD_ScrWidth,a1
  1538.     Dbra    d0,.drawlp
  1539.     ; --+-- END SCANLINE LOOP --+--
  1540.  
  1541. .end    Movem.l    (sp)+,d0-7/a0-6
  1542.     Rts
  1543.  
  1544.  
  1545.  
  1546.  
  1547. ; --+---------------------+--
  1548. ; --| Draw to Edge Buffer |--
  1549. ; --+---------------------+--
  1550.  
  1551.  
  1552. .DrawLine
  1553.  
  1554.     ; D0-3.w - x1,y1, x2,y2
  1555.     ; D4-7.w - u1,v1, u2,v2
  1556.  
  1557.     Movem.l    a2-3,-(sp)
  1558.  
  1559.  
  1560.     Lea    TD_edgebuffer+2,a2
  1561.     Lea    TD_txrbuffer+8,a3
  1562.  
  1563.  
  1564.     ; --+-- MaxMin Y --+--
  1565.  
  1566.     Move.l    d4,-(sp)
  1567.     Move.l    TD_maxmin,d4
  1568.  
  1569.     Swap    d4
  1570.     Cmp.w    d1,d4
  1571.     Ble.s    .nmin
  1572.     Move.w    d1,d4
  1573. .nmin    Swap    d4
  1574.     Cmp.w    d3,d4
  1575.     Bge.s    .nmax
  1576.     Move.w    d3,d4
  1577. .nmax
  1578.     Move.l    d4,TD_maxmin
  1579.     Move.l    (sp)+,d4
  1580.  
  1581.     ; --+---------------+--
  1582.  
  1583.     Cmp.w    d1,d3
  1584.     Beq.s    .nodrw
  1585.     Bgt.s    .noswap
  1586.  
  1587.     Exg.w    d1,d3
  1588.     Exg.w    d0,d2
  1589.     Exg.w    d4,d6
  1590.     Exg.w    d5,d7
  1591.  
  1592.     Lea    -2(a2),a2        ; Left column of each
  1593.     Lea    -8(a3),a3        ;  of the edge buffers
  1594. .noswap
  1595.  
  1596.     ;-- Y Delta --
  1597.     Sub.w    d1,d3            ; D3.w - # of scanlines (Y)
  1598.     Ext.l    d1
  1599.     Lea    0(a2,d1.l*4),a2        ; Start addr for x  possie  (2x word)
  1600.     Lsl.l    #4,d1
  1601.     Lea    0(a3,d1.l),a3        ; Start addr for uv possies (4x long)
  1602.  
  1603.     Ext.l    d0
  1604.     Ext.l    d4
  1605.     Ext.l    d5
  1606.  
  1607.     Ext.l    d3
  1608.  
  1609.  
  1610.     ;-- X Delta --
  1611.     Sub.w    d0,d2
  1612.     Ext.l    d2
  1613.     Lsl.l    #8,d2
  1614.     Divs.l    d3,d2            ; d2.l - (24.8) x delta            ** 060!! **
  1615.  
  1616.     Ror.l    #1,d2        ; Gives better accuracy ( add 1/2 * delta to start value )
  1617.     Rol.l    #8,d0
  1618.     Add.l    d2,d0
  1619.     Ror.l    #8,d0
  1620.     Ror.l    #7,d2        ; d2.l (8.24)  [dec|int]    (was #8,d2)
  1621.  
  1622.  
  1623.     ;-- U Delta --
  1624.     Sub.w    d4,d6
  1625.     Ext.l    d6
  1626.     Lsl.l    #8,d4
  1627.     Lsl.l    #8,d6
  1628.     Divs.l    d3,d6            ; d6.l - (24.8) u delta            ** 060!! **
  1629.  
  1630.     Asr.l    #1,d6        ; Gives better accuracy ( add 1/2 * delta to start value )
  1631.     Add.l    d6,d4
  1632.     Asl.l    #1,d6
  1633.  
  1634.  
  1635.     ;-- V Delta --
  1636.     Sub.w    d5,d7
  1637.     Ext.l    d7
  1638.     Lsl.l    #8,d5
  1639.     Lsl.l    #8,d7
  1640.     Divs.l    d3,d7            ; d7.l - (24.8) v delta            ** 060!! **
  1641.  
  1642.     Asr.l    #1,d7
  1643.     Add.l    d7,d5
  1644.     Asl.l    #1,d7
  1645.  
  1646.     ; ------------------------
  1647.     ; -- Write To EdgeBufer --
  1648.     ; ------------------------
  1649.  
  1650.     Moveq    #0,d1            ; Clear it for Addx usage!
  1651.  
  1652.     Subq    #1,d3
  1653.     Beq.s    .lastadd
  1654.  
  1655. .lp    Move.w    d0,(a2)            ; x pos (16.0)
  1656.     Move.l    d4,00(a3)        ; u pos (24.8)
  1657.     Move.l    d5,04(a3)        ; v pos (24.8)
  1658.  
  1659.     Add.l    d2,d0            ; Add the x delta
  1660.     Addx.l    d1,d0
  1661.     Add.l    d6,d4            ; Add u delta
  1662.     Add.l    d7,d5            ; Add v delta
  1663.  
  1664.  
  1665.     Lea    04(a2),a2
  1666.     Lea    16(a3),a3
  1667.     Dbra    d3,.lp
  1668.  
  1669. .lastadd
  1670.     Asr.l    #1,d2
  1671.     Asr.l    #1,d6
  1672.     Asr.l    #1,d7
  1673.  
  1674.     Sub.l    d2,d0
  1675.     Subx.l    d1,d0
  1676.     Sub.l    d6,d4
  1677.     Sub.l    d7,d5
  1678.  
  1679.     Move.w    d0,(a2)
  1680.     Move.l    d4,00(a3)
  1681.     Move.l    d5,04(a3)
  1682.  
  1683.  
  1684. .nodrw    Movem.l    (sp)+,a2-3
  1685.     Rts
  1686.  
  1687.  
  1688.  
  1689.  
  1690.  
  1691.  
  1692.     ;
  1693.     ; SINE TABLE V1.0 (16.12.97)
  1694.     ;            - 1024 Entries + cosine extra
  1695.     ;            - Sin(Angle)*1024
  1696.     ;
  1697.     ; PARAMETERS:    None
  1698.     ;
  1699.     ; DEPENDENCIES: None
  1700.     ;
  1701.     ; TRASHED REGS:    None
  1702.     ;
  1703.  
  1704. TD_Sine
  1705.     Dc.w    $0000,$0003,$0006,$0009,$000C,$000F,$0012,$0015
  1706.     Dc.w    $0019,$001C,$001F,$0022,$0025,$0028,$002B,$002E
  1707.     Dc.w    $0031,$0035,$0038,$003B,$003E,$0041,$0044,$0047
  1708.     Dc.w    $004A,$004D,$0050,$0053,$0056,$0059,$005C,$005F
  1709.  
  1710.     Dc.w    $0061,$0064,$0067,$006A,$006D,$0070,$0073,$0075
  1711.     Dc.w    $0078,$007B,$007E,$0080,$0083,$0086,$0088,$008B
  1712.     Dc.w    $008E,$0090,$0093,$0095,$0098,$009B,$009D,$009F
  1713.     Dc.w    $00A2,$00A4,$00A7,$00A9,$00AB,$00AE,$00B0,$00B2
  1714.  
  1715.     Dc.w    $00B5,$00B7,$00B9,$00BB,$00BD,$00BF,$00C1,$00C3
  1716.     Dc.w    $00C5,$00C7,$00C9,$00CB,$00CD,$00CF,$00D1,$00D3
  1717.     Dc.w    $00D4,$00D6,$00D8,$00D9,$00DB,$00DD,$00DE,$00E0
  1718.     Dc.w    $00E1,$00E3,$00E4,$00E6,$00E7,$00E8,$00EA,$00EB
  1719.  
  1720.     Dc.w    $00EC,$00ED,$00EE,$00EF,$00F1,$00F2,$00F3,$00F4
  1721.     Dc.w    $00F4,$00F5,$00F6,$00F7,$00F8,$00F9,$00F9,$00FA
  1722.     Dc.w    $00FB,$00FB,$00FC,$00FC,$00FD,$00FD,$00FE,$00FE
  1723.     Dc.w    $00FE,$00FF,$00FF,$00FF,$00FF,$00FF,$00FF,$00FF
  1724.  
  1725.  
  1726. TD_Cosine
  1727.     Dc.w    $0100,$00FF,$00FF,$00FF,$00FF,$00FF,$00FF,$00FF
  1728.     Dc.w    $00FE,$00FE,$00FE,$00FD,$00FD,$00FC,$00FC,$00FB
  1729.     Dc.w    $00FB,$00FA,$00F9,$00F9,$00F8,$00F7,$00F6,$00F5
  1730.     Dc.w    $00F4,$00F4,$00F3,$00F2,$00F1,$00EF,$00EE,$00ED
  1731.  
  1732.     Dc.w    $00EC,$00EB,$00EA,$00E8,$00E7,$00E6,$00E4,$00E3
  1733.     Dc.w    $00E1,$00E0,$00DE,$00DD,$00DB,$00D9,$00D8,$00D6
  1734.     Dc.w    $00D4,$00D3,$00D1,$00CF,$00CD,$00CB,$00C9,$00C7
  1735.     Dc.w    $00C5,$00C3,$00C1,$00BF,$00BD,$00BB,$00B9,$00B7
  1736.  
  1737.     Dc.w    $00B5,$00B2,$00B0,$00AE,$00AB,$00A9,$00A7,$00A4
  1738.     Dc.w    $00A2,$009F,$009D,$009B,$0098,$0095,$0093,$0090
  1739.     Dc.w    $008E,$008B,$0088,$0086,$0083,$0080,$007E,$007B
  1740.     Dc.w    $0078,$0075,$0073,$0070,$006D,$006A,$0067,$0064
  1741.  
  1742.     Dc.w    $0061,$005F,$005C,$0059,$0056,$0053,$0050,$004D
  1743.     Dc.w    $004A,$0047,$0044,$0041,$003E,$003B,$0038,$0035
  1744.     Dc.w    $0031,$002E,$002B,$0028,$0025,$0022,$001F,$001C
  1745.     Dc.w    $0019,$0015,$0012,$000F,$000C,$0009,$0006,$0003
  1746.     Dc.w    $0000,$FFFD,$FFFA,$FFF7,$FFF4,$FFF1,$FFEE,$FFEB
  1747.  
  1748.  
  1749.     Dc.w    $FFE7,$FFE4,$FFE1,$FFDE,$FFDB,$FFD8,$FFD5,$FFD2
  1750.     Dc.w    $FFCF,$FFCB,$FFC8,$FFC5,$FFC2,$FFBF,$FFBC,$FFB9
  1751.     Dc.w    $FFB6,$FFB3,$FFB0,$FFAD,$FFAA,$FFA7,$FFA4,$FFA1
  1752.     Dc.w    $FF9F,$FF9C,$FF99,$FF96,$FF93,$FF90,$FF8D,$FF8B
  1753.  
  1754.     Dc.w    $FF88,$FF85,$FF82,$FF80,$FF7D,$FF7A,$FF78,$FF75
  1755.     Dc.w    $FF72,$FF70,$FF6D,$FF6B,$FF68,$FF65,$FF63,$FF61
  1756.     Dc.w    $FF5E,$FF5C,$FF59,$FF57,$FF55,$FF52,$FF50,$FF4E
  1757.     Dc.w    $FF4B,$FF49,$FF47,$FF45,$FF43,$FF41,$FF3F,$FF3D
  1758.  
  1759.     Dc.w    $FF3B,$FF39,$FF37,$FF35,$FF33,$FF31,$FF2F,$FF2D
  1760.     Dc.w    $FF2C,$FF2A,$FF28,$FF27,$FF25,$FF23,$FF22,$FF20
  1761.     Dc.w    $FF1F,$FF1D,$FF1C,$FF1A,$FF19,$FF18,$FF16,$FF15
  1762.     Dc.w    $FF14,$FF13,$FF12,$FF11,$FF0F,$FF0E,$FF0D,$FF0C
  1763.  
  1764.     Dc.w    $FF0C,$FF0B,$FF0A,$FF09,$FF08,$FF07,$FF07,$FF06
  1765.     Dc.w    $FF05,$FF05,$FF04,$FF04,$FF03,$FF03,$FF02,$FF02
  1766.     Dc.w    $FF02,$FF01,$FF01,$FF01,$FF01,$FF01,$FF01,$FF01
  1767.     Dc.w    $FF00,$FF01,$FF01,$FF01,$FF01,$FF01,$FF01,$FF01
  1768.  
  1769.  
  1770.     Dc.w    $FF02,$FF02,$FF02,$FF03,$FF03,$FF04,$FF04,$FF05
  1771.     Dc.w    $FF05,$FF06,$FF07,$FF07,$FF08,$FF09,$FF0A,$FF0B
  1772.     Dc.w    $FF0C,$FF0C,$FF0D,$FF0E,$FF0F,$FF11,$FF12,$FF13
  1773.     Dc.w    $FF14,$FF15,$FF16,$FF18,$FF19,$FF1A,$FF1C,$FF1D
  1774.  
  1775.     Dc.w    $FF1F,$FF20,$FF22,$FF23,$FF25,$FF27,$FF28,$FF2A
  1776.     Dc.w    $FF2C,$FF2D,$FF2F,$FF31,$FF33,$FF35,$FF37,$FF39
  1777.     Dc.w    $FF3B,$FF3D,$FF3F,$FF41,$FF43,$FF45,$FF47,$FF49
  1778.     Dc.w    $FF4B,$FF4E,$FF50,$FF52,$FF55,$FF57,$FF59,$FF5C
  1779.  
  1780.     Dc.w    $FF5E,$FF61,$FF63,$FF65,$FF68,$FF6B,$FF6D,$FF70
  1781.     Dc.w    $FF72,$FF75,$FF78,$FF7A,$FF7D,$FF80,$FF82,$FF85
  1782.     Dc.w    $FF88,$FF8B,$FF8D,$FF90,$FF93,$FF96,$FF99,$FF9C
  1783.     Dc.w    $FF9F,$FFA1,$FFA4,$FFA7,$FFAA,$FFAD,$FFB0,$FFB3
  1784.  
  1785.     Dc.w    $FFB6,$FFB9,$FFBC,$FFBF,$FFC2,$FFC5,$FFC8,$FFCB
  1786.     Dc.w    $FFCF,$FFD2,$FFD5,$FFD8,$FFDB,$FFDE,$FFE1,$FFE4
  1787.     Dc.w    $FFE7,$FFEB,$FFEE,$FFF1,$FFF4,$FFF7,$FFFA,$FFFD
  1788.  
  1789.  
  1790.  
  1791.     Dc.w    $0000,$0003,$0006,$0009,$000C,$000F,$0012,$0015
  1792.     Dc.w    $0019,$001C,$001F,$0022,$0025,$0028,$002B,$002E
  1793.     Dc.w    $0031,$0035,$0038,$003B,$003E,$0041,$0044,$0047
  1794.     Dc.w    $004A,$004D,$0050,$0053,$0056,$0059,$005C,$005F
  1795.  
  1796.     Dc.w    $0061,$0064,$0067,$006A,$006D,$0070,$0073,$0075
  1797.     Dc.w    $0078,$007B,$007E,$0080,$0083,$0086,$0088,$008B
  1798.     Dc.w    $008E,$0090,$0093,$0095,$0098,$009B,$009D,$009F
  1799.     Dc.w    $00A2,$00A4,$00A7,$00A9,$00AB,$00AE,$00B0,$00B2
  1800.  
  1801.     Dc.w    $00B5,$00B7,$00B9,$00BB,$00BD,$00BF,$00C1,$00C3
  1802.     Dc.w    $00C5,$00C7,$00C9,$00CB,$00CD,$00CF,$00D1,$00D3
  1803.     Dc.w    $00D4,$00D6,$00D8,$00D9,$00DB,$00DD,$00DE,$00E0
  1804.     Dc.w    $00E1,$00E3,$00E4,$00E6,$00E7,$00E8,$00EA,$00EB
  1805.  
  1806.     Dc.w    $00EC,$00ED,$00EE,$00EF,$00F1,$00F2,$00F3,$00F4
  1807.     Dc.w    $00F4,$00F5,$00F6,$00F7,$00F8,$00F9,$00F9,$00FA
  1808.     Dc.w    $00FB,$00FB,$00FC,$00FC,$00FD,$00FD,$00FE,$00FE
  1809.     Dc.w    $00FE,$00FF,$00FF,$00FF,$00FF,$00FF,$00FF,$00FF
  1810.  
  1811.  
  1812.  
  1813.  
  1814.     ;
  1815.     ; LINE CLIPPING + DRAWING ROUTINE V1.1 (09.02.98)
  1816.     ;            - Clips coordinates to within defined
  1817.     ;               boundaries and draws the line
  1818.     ;
  1819.     ; PARAMETERS:    D0-D3.w    - X1,Y1, X2,Y2 Coords
  1820.     ;        A0.l    - Address of Line-Drawing Routine
  1821.     ;        A1.l    - Bitplane Base Address
  1822.     ;        A5.l    - $DFF000    ** For Planar Lines
  1823.     ;        A6.l    - GraphicsBase  ** For Planar Lines
  1824.     ;
  1825.     ; TRASHED REGS:    d0-3
  1826.     ;
  1827.     ; NOTES:    Not Publicly Accessible!!
  1828.  
  1829.  
  1830. TD_ClipNDraw
  1831.  
  1832.     Movem.l    d4-6,-(sp)
  1833.     Moveq    #0,d6
  1834.  
  1835.     ;--------------------
  1836.     ;-- Check Vertical --
  1837.     ;--------------------
  1838.  
  1839.     Cmp.w    d1,d3
  1840.     Bge.s    .1
  1841.     Exg.w    d0,d2            ; D1 < D3
  1842.     Exg.w    d1,d3
  1843.     Bchg    #0,d6
  1844.  
  1845. .1    Cmp.w    TD_ClipY1,d3
  1846.     Blt.s    .nodraw            ; D3 < BottomClip -> No Draw
  1847.     Cmp.w    TD_ClipY2,d1
  1848.     Bgt.s    .nodraw            ; D1 > TopClip -> No Draw
  1849.  
  1850.     ;-- Check Top --
  1851.     Cmp.w    TD_ClipY1,d1
  1852.     Bge.s    .2            ; Y1 OK
  1853.  
  1854.     ;-- Clip Top --            ; (dx/DX) = (dy/DY)
  1855.                     ; New x = X1 + (DX/DY)*dy
  1856.     Move.w    d0,d4
  1857.     Sub.w    d2,d4            ; D4.w = DX
  1858.     Move.w    d1,d5
  1859.     Sub.w    TD_ClipY1,d5        ; D5.w = dy
  1860.     Muls    d5,d4            ; D4.l = DX.dy
  1861.     Move.w    d3,d5
  1862.     Sub.w    d1,d5            ; D5.w = DY
  1863.     Divs    d5,d4            ; D4.w = (DX/DY)*dy = dx
  1864.     Add.w    d4,d0            ; New X Coord
  1865.     Move.w    TD_ClipY1,d1        ; New Y Coord
  1866.  
  1867.     ;-- Check Bottom --
  1868.  
  1869. .2    Cmp.w    TD_ClipY2,d3
  1870.     Ble.s    .3            ; Y2 OK
  1871.  
  1872.     ;-- Clip Bottom --        ; New x1 = X1 + (DX/DY)*dy
  1873.     Move.w    d0,d4
  1874.     Sub.w    d2,d4            ; D4.w = DY
  1875.     Move.w    d3,d5
  1876.     Sub.w    TD_ClipY2,d5
  1877.     Muls    d5,d4
  1878.     Move.w    d3,d5
  1879.     Sub.w    d1,d5
  1880.     Divs    d5,d4
  1881.     Add.w    d4,d2
  1882.     Move.w    TD_ClipY2,d3
  1883.  
  1884.  
  1885.     ;----------------------
  1886.     ;-- Check Horizontal --
  1887.     ;----------------------
  1888.  
  1889. .3    Cmp.w    d0,d2
  1890.     Bge.s    .4
  1891.     Exg.w    d0,d2
  1892.     Exg.w    d1,d3
  1893.     Bchg    #0,d6
  1894.  
  1895. .4    Cmp.w    TD_ClipX1,d2
  1896.     Blt.s    .nodraw            ; X2 < LeftClip -> No Draw
  1897.     Cmp.w    TD_ClipX2,d0
  1898.     Bgt.s    .nodraw            ; X0 > RightClip -> NoDraw
  1899.  
  1900.     ;-- Check Left --
  1901.     Cmp.w    TD_ClipX1,d0
  1902.     Bge.s    .5            ; X1 OK
  1903.  
  1904.     ;-- Clip Left --        ; New Y1 = Y1 + (DY/DX)*dx
  1905.     Move.w    d1,d4
  1906.     Sub.w    d3,d4            ; D4.w = DY
  1907.     Move.w    d0,d5
  1908.     Sub.w    TD_ClipX1,d5        ; D5.w = dx
  1909.     Muls    d5,d4            ; D4.l = DY.dx
  1910.     Move.w    d2,d5
  1911.     Sub.w    d0,d5            ; D5.w = DX
  1912.     Divs    d5,d4
  1913.     Add.w    d4,d1            ; D1 = New Y Coord
  1914.     Move.w    TD_ClipX1,d0        ; D0 = New X coord
  1915.     
  1916. .5    ;-- Check Right --
  1917.     Cmp.w    TD_ClipX2,d2
  1918.     Ble.s    .6            ; X2 OK
  1919.  
  1920.     ;-- Clip Right --
  1921.     Move.w    d1,d4
  1922.     Sub.w    d3,d4
  1923.     Move.w    d2,d5
  1924.     Sub.w    TD_ClipX2,d5
  1925.     Muls    d5,d4
  1926.     Move.w    d2,d5
  1927.     Sub.w    d0,d5
  1928.     Divs    d5,d4
  1929.     Add.w    d4,d3
  1930.     Move.w    TD_ClipX2,d2
  1931.  
  1932.     ;-- Clipping Finished --
  1933. .6    Tst.w    d6
  1934.     Beq.s    .7
  1935.     Exg.w    d0,d2
  1936.     Exg.w    d1,d3
  1937. .7    Jsr    (a0)            ; Go ahead and draw it!
  1938.  
  1939. .nodraw    Movem.l    (sp)+,d4-6
  1940.     Rts
  1941.  
  1942.  
  1943.  
  1944.  
  1945.  
  1946. ClearPlanes
  1947.     Lea    Planes,a0
  1948.     Move.w    #320*200*2/8-1,d0
  1949. .0    Clr.l    (a0)+
  1950.     Clr.l    (a0)+
  1951.     Dbra    d0,.0
  1952.     Rts
  1953.  
  1954.  
  1955.  
  1956.  
  1957.     ; ***************************************************************
  1958.     ; ***                                                         ***
  1959.     ; ***  EFFECT #1: HIDDEN-LINE LOGO                            ***
  1960.     ; ***                                                         ***
  1961.     ; ***************************************************************
  1962.  
  1963.  
  1964.     ;
  1965.     ; Usage:
  1966.     ;
  1967.     ;   * Just call LINE_INIT as part of the precalculation phase
  1968.     ;
  1969.     ;   * Call LINE_SHOW to actually display the effect
  1970.     ;
  1971.     ;   * Call LINE_END preferably at the end of the demo
  1972.     ;
  1973.     ;   * Call LINE_VBL as part of your VBLANK interrupt code (assuming that
  1974.     ;     you have a vblank interrupt going, otherwise just call it everytime
  1975.     ;     in the main loop). I have added the VBlank interrupt setup code
  1976.     ;     at the start of LINE_SHOW, and remove the interrupt after the effect
  1977.     ;     is finished. You may want to replace this if you hack the INTENA
  1978.     ;     registers directly!!
  1979.     ;
  1980.     ;
  1981.     ; Notes:
  1982.     ;
  1983.     ;   * I've made some comments that I think deserve attention. They start with '** '
  1984.     ;
  1985.     ;   * A major space-waster is the sine-table found in 'TDLIB/TD_Sine.i'. It
  1986.     ;     probably uses about 2.5K of RAM, but should crunch fairly well.
  1987.     ;
  1988.     ;   * DMA is assumed to be at least COPEN | BPLEN | DMAEN  ($8380)
  1989.     ;
  1990.  
  1991.  
  1992. line_SCR_WIDTH    = 320
  1993. line_SCR_HEIGHT    = 100
  1994. line_SCR_WH    = line_SCR_WIDTH*line_SCR_HEIGHT
  1995.  
  1996. SPHERE_POINTS    = 512                ; ** Change this to alter sphere density **
  1997.  
  1998.  
  1999.  
  2000.     ; ********************************************************
  2001.     ; **                                                    **
  2002.     ; **  LINE_INIT - Call as part of precalculation phase  **
  2003.     ; **                                                    **
  2004.     ; ********************************************************
  2005.  
  2006.     section    'Code1',CODE
  2007.  
  2008.  
  2009. LINE_INIT
  2010.     ; --+----------------------+--
  2011.     ; --| PRECALCULATION STUFF |--
  2012.     ; --+----------------------+--
  2013.  
  2014.     ; -- Precalc Radial Points Of Sphere-Object --
  2015.     Lea    pnts,a0
  2016.     Lea    TD_Sine,a1
  2017.     Move.w    #SPHERE_POINTS-1,d3
  2018.     Moveq    #0,d0
  2019.     Move.w    d0,d1
  2020.     Move.w    d0,d2
  2021.  
  2022.     Move.l    d0,d4
  2023.     Move.l    d0,d5
  2024.     Move.l    d0,d6
  2025.  
  2026. .lp    Move.w    d0,(a0)+
  2027.     Move.w    d1,(a0)+
  2028.     Move.w    d2,(a0)+
  2029.  
  2030.     Add.w    #256-43,d4
  2031.     Add.w    #512+27,d5
  2032.     Add.w    #256+512+87,d6
  2033.  
  2034.     And.w    #$01FF,d4
  2035.     And.w    #$01FF,d5
  2036.     And.w    #$01FF,d6
  2037.  
  2038.     Move.w    0(a1,d4.w*2),d0        ; +/- 1024
  2039.     Move.w    0(a1,d5.w*2),d1
  2040.     Move.w    0(a1,d6.w*2),d2
  2041.     Asr.w    #2,d0            ; +/- 256
  2042.     Asr.w    #2,d1
  2043.     Asr.w    #2,d2
  2044.  
  2045.     Dbra    d3,.lp
  2046.  
  2047.  
  2048.     ; -- Precalc Edge-Draw Table --
  2049.     Lea    lines,a0
  2050.     Moveq    #1,d1
  2051.     Move.w    #SPHERE_POINTS-2,d0
  2052. .edt    Move.l    d1,(a0)+
  2053.     Addq.w    #1,d1
  2054.     Dbra    d0,.edt
  2055.     Move.l    #-1,(a0)+
  2056.  
  2057.     Rts
  2058.  
  2059.  
  2060.  
  2061.  
  2062.  
  2063.     ; ********************************************************
  2064.     ; **                                                    **
  2065.     ; **  LINE_SHOW - Call this to display the effect       **
  2066.     ; **                                                    **
  2067.     ; ********************************************************
  2068.  
  2069. LINE_SHOW
  2070.  
  2071.     ; -- ADD VBLANK INTERRUPT --
  2072.     Moveq    #5,d0
  2073.     Lea    line_ints,a1
  2074.     Move.l    4.w,a6
  2075.     Jsr    -168(a6)        ; _LVOAddIntServer
  2076.  
  2077.  
  2078.     _LoadPalette24    Palette,CLIST_Palette,2
  2079.     _LoadPlanes    line_scr_p,CLIST_Planes,8,40*200
  2080.     _WaitVBL
  2081.     _LoadCList    CLIST
  2082.     Lea    $DFF000,a5
  2083.  
  2084.     _TD_ChangeScreenSize    line_SCR_WIDTH, line_SCR_HEIGHT
  2085.     _TD_ChangeClipRegion    1,1, line_SCR_WIDTH-2,line_SCR_HEIGHT-2
  2086.  
  2087.  
  2088.  
  2089.     ; ---------------
  2090.     ; -- MAIN LOOP --
  2091.     ; ---------------
  2092.  
  2093. .lp    ; -- DRAW LOGO TO SCREEN --
  2094.     Lea    Chunky,a0
  2095.     Lea    Logo,a1
  2096.     Move.w    #line_SCR_WH/8-1,d0
  2097. .logo    Move.l    (a1)+,(a0)+
  2098.     Move.l    (a1)+,(a0)+
  2099.     Dbra    d0,.logo
  2100.  
  2101.  
  2102.     ; -- DRAW THE GLOWING SPHERE --
  2103.     Move.w    Sphere_x,d0
  2104.     Move.w    Sphere_y,d1
  2105.     Moveq    #0,d2
  2106.     Lea    Sphere,a0
  2107.     Jsr    TD_MovAbs
  2108.  
  2109.     _TD_Rot        Sphere
  2110.  
  2111.     Lea    Sphere,a0
  2112.     Lea    Chunky,a1
  2113.     Bsr    DrawWire
  2114.  
  2115.  
  2116.  
  2117.     ; -----------------------------
  2118.     ; -- LensFlares! yeahhhhh!!! --
  2119.     ; -----------------------------
  2120.  
  2121.  
  2122.     Move.w    Sphere_x,d2
  2123.     Move.w    Sphere_y,d3
  2124.     Neg.w    d2
  2125.     Neg.w    d3
  2126.     Lsl.w    #2,d2
  2127.     Lsl.w    #2,d3
  2128.  
  2129.     ; -- First LensFlare --
  2130.     Move.w    d2,d0
  2131.     Move.w    d3,d1
  2132.     Add.w    #line_SCR_WIDTH/2,d0
  2133.     Add.w    #line_SCR_HEIGHT/2,d1
  2134.     Lea    Flare3,a0
  2135.     Lea    Chunky,a1
  2136.     Bsr    DrawBob32
  2137.  
  2138.     ; -- Second LensFlare --
  2139.     Asr.w    #1,d2
  2140.     Asr.w    #1,d3
  2141.     Move.w    d2,d0
  2142.     Move.w    d3,d1
  2143.     Add.w    #line_SCR_WIDTH/2,d0
  2144.     Add.w    #line_SCR_HEIGHT/2,d1
  2145.     Lea    Flare5,a0
  2146.     Lea    Chunky,a1
  2147.     Bsr    DrawBob32
  2148.  
  2149.     ; -- Third LensFlare --
  2150.     Asr.w    #1,d2
  2151.     Asr.w    #1,d3
  2152.     Move.w    d2,d0
  2153.     Move.w    d3,d1
  2154.     Add.w    #line_SCR_WIDTH/2,d0
  2155.     Add.w    #line_SCR_HEIGHT/2,d1
  2156.     Lea    Flare1,a0
  2157.     Lea    Chunky,a1
  2158.     Bsr    DrawBob32
  2159.  
  2160.     ; -- Fourth LensFlare --
  2161.     Asr.w    #1,d2
  2162.     Asr.w    #1,d3
  2163.     Move.w    d2,d0
  2164.     Move.w    d3,d1
  2165.     Add.w    #line_SCR_WIDTH/2,d0
  2166.     Add.w    #line_SCR_HEIGHT/2,d1
  2167.     Lea    Flare4,a0
  2168.     Lea    Chunky,a1
  2169.     Bsr    DrawBob32
  2170.  
  2171.     ; -- Fifth LensFlare --
  2172.     Asr.w    #1,d2
  2173.     Asr.w    #1,d3
  2174.     Move.w    d2,d0
  2175.     Move.w    d3,d1
  2176.     Add.w    #line_SCR_WIDTH/2,d0
  2177.     Add.w    #line_SCR_HEIGHT/2,d1
  2178.     Lea    Flare2,a0
  2179.     Lea    Chunky,a1
  2180.     Bsr    DrawBob32
  2181.  
  2182.  
  2183.  
  2184.  
  2185.  
  2186.     ; -- BLUR THE SCREEN --
  2187.     Jsr    Smooth
  2188.  
  2189.  
  2190.     ; -- C2P STUFF --
  2191.     Lea    Chunky,a0            ; Chunky Buffer
  2192.     Move.l    line_scr_l,a1            ; Planar Buffer
  2193.     Move.l    #line_SCR_WH,d0            ; Size of C2P
  2194.     Jsr    _c2p_020
  2195.  
  2196.  
  2197.     ; -- DOUBLEBUFFER --
  2198.     _WaitVBL
  2199.     _LoadPlanes    line_scr_l, CLIST_Planes, 8, 40*200
  2200.     Move.l    line_scr_l,d0
  2201.     Move.l    line_scr_p,line_scr_l
  2202.     Move.l    d0,line_scr_p
  2203.  
  2204.  
  2205.  
  2206.     ; -- EXIT CHECK    --
  2207.     Cmp.w    #L_FRAMES,l_Timer        ; Will exit after L_FRAMES refreshes
  2208.     Bge.s    .end                ;  has occurred
  2209.  
  2210.     ; -- LEFT MOUSE BUTTON PRESSED? --
  2211.     Btst    #6,$BFE001            ; ** Just change this to whatever you use
  2212.     Bne.s    .lp                ;    to check for end-of-effect (check a
  2213.                         ;    VBL-updated counter, or something like
  2214.                         ;    that)
  2215.     ; ------------------
  2216.     ; -- END MAINLOOP --
  2217.     ; ------------------
  2218.  
  2219.  
  2220.  
  2221. .end    ; -- CLEAR DISPLAY --
  2222.     _LoadCLIST    CLIST_EMPTY
  2223.     _WaitVBL
  2224.     Jsr    ClearPlanes
  2225.  
  2226.     ; -- REMOVE VBLANK INTERRUPT --
  2227.     Moveq    #5,d0
  2228.     Lea    line_ints,a1
  2229.     Move.l    4.w,a6
  2230.     Jsr    -174(a6)        ; _LVORemIntServer
  2231.  
  2232.  
  2233.     Rts
  2234.  
  2235.  
  2236.  
  2237.  
  2238.     ; ********************************************************
  2239.     ; **                                                    **
  2240.     ; **  LINE_VBL - The Vertical-Blank Interrupt Code      **
  2241.     ; **                                                    **
  2242.     ; ********************************************************
  2243.  
  2244. LINE_VBL
  2245.     Movem.l    d2-7/a2-6,-(sp)
  2246.  
  2247.     ; -- Update the Sphere's coordinates --
  2248.  
  2249.     _TD_RotRel    Sphere, 1,0,1    ; Perform 'logical' rotation on sphere
  2250.                     ; (3d rotation not actually performed here)
  2251.     Move.w    line_angx,d0
  2252.     Move.w    line_angy,d1
  2253.     Addq.w    #1,d0
  2254.     Addq.w    #3,d1
  2255.     And.w    #$03FF,d0
  2256.     And.w    #$03FF,d1
  2257.     Move.w    d0,line_angx
  2258.     Move.w    d1,line_angy
  2259.  
  2260.     Lsr.w    #1,d0
  2261.     Lsr.w    #1,d1
  2262.     Lea    TD_Sine,a0        ; Sine Table
  2263.     Lea    TD_Cosine,a1        ; Cosine Table
  2264.     Move.w    0(a0,d0.w*2),d0
  2265.     Move.w    0(a1,d1.w*2),d1
  2266.     Asr.w    #1,d0
  2267.     Asr.w    #5,d1
  2268.     Move.w    d0,Sphere_x
  2269.     Move.w    d1,Sphere_y
  2270.  
  2271.  
  2272.     ; -- ** TIMER ** --
  2273.     Add.w    #1,l_Timer
  2274.  
  2275.     Movem.l    (sp)+,d2-7/a2-6
  2276.     Moveq    #0,d0            ; Required for VBlank interrupts thru OS!!
  2277.  
  2278.     Rts
  2279.  
  2280.  
  2281.  
  2282.  
  2283.  
  2284.  
  2285.     ; *****************************
  2286.     ; **                         **
  2287.     ; **  S U B R O U T I N E S  **
  2288.     ; **                         **
  2289.     ; *****************************
  2290.  
  2291.  
  2292.     ; ---------------
  2293.     ; -- Smoothing --
  2294.     ; ---------------
  2295.  
  2296.     ; ** Limited to 64 colour chunky bitmaps (byte overflows otherwise!) **
  2297.  
  2298.  
  2299. Smooth    Movem.l    d0-7/a0-3,-(sp)
  2300.  
  2301.     ; -- Vertical Blur Phase --
  2302.     Lea    Chunky,a0            ; Pre  Y
  2303.     Lea    line_SCR_WIDTH(a0),a1        ;      Y
  2304.     Lea    line_SCR_WIDTH(a1),a2        ; Post Y
  2305.     Lea    line_SCR_WH(a1),a3        ; Dest
  2306.  
  2307.  
  2308.     Move.l    #(line_SCR_WIDTH/4)*(line_SCR_HEIGHT-2)-1,d7
  2309. .vlp    Move.l    (a0)+,d0
  2310.     Move.l    (a1)+,d1
  2311.     Move.l    (a2)+,d2
  2312.     Lsl.l    #1,d1
  2313.     Add.l    d0,d2
  2314.     Add.l    d2,d1
  2315.     Lsr.l    #2,d1
  2316.     And.l    #$3F3F3F3F,d1
  2317.     Move.l    d1,(a3)+
  2318.     Dbra    d7,.vlp
  2319.  
  2320.  
  2321.     ; -- Horizontal Blur Phase --
  2322.     Lea    Chunky+line_SCR_WIDTH+line_SCR_WH,a0        ; Src  Y
  2323.     Lea    Chunky+line_SCR_WIDTH,a1            ; Dest Y
  2324.  
  2325.     Move.l    #(line_SCR_WIDTH*(line_SCR_HEIGHT-2)/2)-1,d7
  2326. .hlp    Move.l    (a0),d0
  2327.     Move.l    d0,d1
  2328.     Move.l    d0,d2
  2329.     Lsl.l    #8,d1
  2330.     Lsr.l    #8,d2
  2331.     Lsl.l    #1,d0
  2332.     Add.l    d1,d2
  2333.     Add.l    d0,d2
  2334.     Lsr.l    #8,d2
  2335.     Lsr.l    #2,d2
  2336.     And.w    #$3F3F,d2
  2337.     Lea    2(a0),a0
  2338.     Move.w    d2,(a1)+
  2339.     Dbra    d7,.hlp
  2340.  
  2341.     Movem.l    (sp)+,d0-d7/a0-3
  2342.     Rts
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.     ; --+----------------------------------+--
  2349.     ; --|  SIMPLE CHUNKY-BOB DRAW ROUTINE  |--
  2350.     ; --+----------------------------------+--
  2351.  
  2352. DrawBob32
  2353.  
  2354.     ; Draws a chunky-mode bob (32x32pix) to chunky screen
  2355.     ;
  2356.     ; Parameters:    a0.l - Bob Base Address
  2357.     ;        a1.l - Chunky Screen
  2358.     ;        d0.w - X Position
  2359.     ;         d1.w - Y Position
  2360.     ;
  2361.     ; Notes: Clipping not fully implemented (won't trash mem tho!)
  2362.     ;
  2363.  
  2364.     Movem.l    d0-4/a0-1,-(sp)
  2365.  
  2366.     Sub.w    #16,d0            ; Make Them Centered
  2367.     Sub.w    #16,d1
  2368.  
  2369.     ; -- CLIPPING --
  2370.     Tst.w    d0
  2371.     Blt.s    .nodr
  2372.     Tst.w    d1
  2373.     Blt.s    .nodr
  2374.  
  2375.     Cmp.w    #line_SCR_WIDTH-1-32,d0
  2376.     Bgt.s    .nodr
  2377.     Cmp.w    #line_SCR_HEIGHT-1-32,d1
  2378.     Bgt.s    .nodr
  2379.  
  2380.     ; -- It's safe to draw now ;) --
  2381.     Mulu    #line_SCR_WIDTH,d1
  2382.     Lea    0(a1,d0.w),a1
  2383.     Lea    0(a1,d1.l),a1
  2384.  
  2385.     Moveq    #32-1,d0        ;  Y Loop Counter
  2386. .0    Movem.l    (a0)+,d1-4
  2387.     Add.l    d1,(a1)+
  2388.     Add.l    d2,(a1)+
  2389.     Add.l    d3,(a1)+
  2390.     Add.l    d4,(a1)+
  2391.  
  2392.     Movem.l    (a0)+,d1-4
  2393.     Add.l    d1,(a1)+
  2394.     Add.l    d2,(a1)+
  2395.     Add.l    d3,(a1)+
  2396.     Add.l    d4,(a1)+
  2397.  
  2398.     Lea    line_SCR_WIDTH-32(a1),a1
  2399.     Dbra    d0,.0
  2400.  
  2401. .nodr    Movem.l    (sp)+,d0-4/a0-1
  2402.     Rts
  2403.  
  2404.  
  2405.  
  2406.  
  2407.  
  2408.     ; --+----------------------------------+--
  2409.     ; --|  SPECIAL WIREFRAME DRAW ROUTINE  |--
  2410.     ; --+----------------------------------+--
  2411.     ;
  2412.     ;
  2413.     ; PARAMETERS:    A0.l - Object Structure Base
  2414.     ;        A1.l - Chunky Base Address
  2415.     ;
  2416.  
  2417.  
  2418. DrawWire
  2419.     Movem.l    d0-5/a0-2,-(sp)
  2420.     Move.l    TD_PT_PERSP(a0),a2    ; A2.l = Rotated -> 2D Point-List
  2421.     Move.l    TD_LINESEGS(a0),a0    ; A0.l = LineSegs List
  2422.     Move.w    (a0)+,d4
  2423.     Move.w    (a0)+,d5        ; Point Pair Read-Ahead
  2424. .1    Move.w    0(a2,d4.w*4),d0        ; X1
  2425.     Move.w    2(a2,d4.w*4),d1        ; Y1
  2426.     Move.w    0(a2,d5.w*4),d2        ; X2
  2427.     Move.w    2(a2,d5.w*4),d3        ; Y2
  2428.     ; -- Draw Line --
  2429.     Move.l    a0,-(sp)
  2430.     Lea    DrawLine,a0        ; Pointer to line-drawing code
  2431.     Jsr    TD_ClipNDraw        ; Perform Edge-Clipping / Draw
  2432.     Move.l    (sp)+,a0
  2433.     ; -- Next Point-Pair
  2434.     Move.w    (a0)+,d4
  2435.     Move.w    (a0)+,d5
  2436.     Bge.s    .1            ; Not at end of line_seg-list (-1)
  2437.     Movem.l    (sp)+,d0-5/a0-2
  2438.     Rts
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.     ; --+-----------------------------+--
  2445.     ; --|  SPECIAL LINE-DRAW ROUTINE  |--
  2446.     ; --+-----------------------------+--
  2447.     ;
  2448.     ;
  2449.     ; PARAMETERS:    d0-3.w    - X1,Y1, X2,Y2
  2450.     ;        a1.l    - Chunky Buffer
  2451.     ;
  2452.  
  2453.  
  2454. DrawLine
  2455.     Movem.l    d0-7/a1-3,-(sp)
  2456.  
  2457.     Lea    .lkup1,a2
  2458.     Lea    Logo,a3
  2459.  
  2460.     Move.w    d2,d4
  2461.     Move.w    d3,d5
  2462.     Sub.w    d0,d4        ; dx
  2463.     Bge.s    .nn1
  2464.     Neg.w    d4        ; |dx|
  2465. .nn1    Sub.w    d1,d5        ; dy
  2466.     Bge.s    .nn2
  2467.     Neg.w    d5        ; |dy|
  2468. .nn2    Cmp.w    d4,d5
  2469.     Bgt.s    .ymaj        ; |dy| > |dx| ?
  2470.  
  2471.     ; -- X Major:  dx > dy --
  2472.     ;
  2473.     ; d4.w - number of X iterations
  2474.     ;
  2475.     Moveq    #1,d7        ; d7.w -  x delta (per loop)
  2476.     Move.l    #line_SCR_WIDTH,d6    ; d6.w -  y delta (when add overflow)
  2477.  
  2478.     Sub.w    d0,d2
  2479.     Beq.s    .nodraw        ; Don't Div 0!!
  2480.     Bge.s    .xn1
  2481.     Neg.l    d7        ; d7.w -  -1.l
  2482. .xn1    Sub.w    d1,d3        ; d3.w -  y delta
  2483.     Bge.s    .xn2
  2484.     Neg.l    d6        ; d6.w -  -line_SCR_WIDTH.w
  2485. .xn2    Mulu    #line_SCR_WIDTH,d1
  2486.     Add.l    d1,a1
  2487.     Add.l    d1,a3
  2488.     Add.w    d0,a1        ; a1.l -  start point
  2489.     Add.w    d0,a3
  2490.  
  2491.     Ext.l    d3
  2492.     Asl.l    #8,d3        ; d3.l - [24.8] fixed point Y delta
  2493.     Divs    d4,d3
  2494.     Ext.l    d3        ; (get rid of remainder part!!)
  2495.     Ror.l    #8,d3        ; d3.l - [8.24] - [fract.int]
  2496.  
  2497.     Subq.w    #1,d4
  2498.     Moveq    #0,d5
  2499.     Move.l    d5,d0
  2500.     Move.l    d5,d1
  2501.  
  2502.  
  2503.  
  2504.  
  2505.  
  2506. .xlp    ; -- Test Logo Point --
  2507.     Tst.b    (a3)
  2508.     Beq.s    .xlp2        ; -> Start drawing the line
  2509.     ;Bne.s    .xlp2        ;    as soon as we get a (non) zero colour, start drawing line
  2510.  
  2511.     ; -- Add Y Delta --    ; but only upon x-flag carry!!
  2512.     Add.l    d3,d5
  2513.     Addx.l    d1,d5
  2514.     Tst.w    d5
  2515.     Beq.s    .nya
  2516.     Clr.w    d5
  2517.     Add.l    d6,a1        ; Next/Prev vertical line
  2518.     Add.l    d6,a3
  2519. .nya    ; -- Add X Delta --
  2520.     Add.l    d7,a1        ; x delta ( +/- 1)
  2521.     Add.l    d7,a3
  2522.     Dbra    d4,.xlp
  2523.  
  2524.     Movem.l    (sp)+,d0-7/a1-3
  2525.     Rts
  2526.  
  2527.  
  2528.  
  2529.  
  2530. .xlp2    ; -- Plot Pixel (additive intensity) --
  2531.     Move.b    (a1),d0
  2532.     Move.b    0(a2,d0.l),(a1)
  2533.     ; -- Add Y Delta --    ; but only upon x-flag carry!!
  2534.     Add.l    d3,d5
  2535.     Addx.l    d1,d5
  2536.     Tst.w    d5
  2537.     Beq.s    .noyadd
  2538.     Clr.w    d5
  2539.     Add.l    d6,a1        ; Next/Prev vertical line
  2540. .noyadd    ; -- Add X Delta --
  2541.     Add.l    d7,a1        ; x delta ( +/- 1)
  2542.     Dbra    d4,.xlp2
  2543.  
  2544. .nodraw    Movem.l    (sp)+,d0-7/a1-3
  2545.     Rts
  2546.  
  2547.  
  2548.  
  2549.  
  2550.  
  2551.  
  2552. .ymaj    ; -- Y Major:  dy > dx --
  2553.     ;
  2554.     ; d5.w - number of Y iterations
  2555.     ;
  2556.  
  2557.  
  2558.  
  2559.     Moveq    #1,d7        ; d7.w -  x delta (when add overflows)
  2560.     Move.l    #line_SCR_WIDTH,d6    ; d6.w -  y delta (per loop)
  2561.  
  2562.     Sub.w    d1,d3
  2563.     Beq.s    .nodraw        ; Don't Div 0!!
  2564.     Bge.s    .yn1
  2565.     Neg.l    d6        ; d7.w -  -1.l
  2566. .yn1    Sub.w    d0,d2        ; d2.w -  y delta
  2567.     Bge.s    .yn2
  2568.     Neg.l    d7        ; d6.w -  -line_SCR_WIDTH.w
  2569. .yn2    Mulu    #line_SCR_WIDTH,d1
  2570.     Add.l    d1,a1
  2571.     Add.l    d1,a3
  2572.     Add.w    d0,a1        ; a1.l -  start point
  2573.     Add.w    d0,a3
  2574.  
  2575.  
  2576.     Ext.l    d2
  2577.     Asl.l    #8,d2        ; d2.l - [24.8] fixed point X delta
  2578.     Divs    d5,d2
  2579.     Ext.l    d2        ; (get rid of remainder part!!)
  2580.     Ror.l    #8,d2        ; d2.l - [8.24] - [fract.int]
  2581.  
  2582.     Subq.w    #1,d5
  2583.     Moveq    #0,d4
  2584.     Move.l    d4,d0
  2585.     Move.l    d4,d1
  2586.  
  2587.  
  2588.  
  2589.  
  2590. .ylp    ; -- Test Logo Point --
  2591.     Tst.b    (a3)
  2592.     Beq.s    .ylp2        ; -> Start drawing the line
  2593.     ;Bne.s    .ylp2        ;    as soon as we get a (non) zero colour, start drawing line
  2594.  
  2595.     ; -- Add X Delta (carry) --
  2596.     Add.l    d2,d4
  2597.     Addx.l    d1,d4
  2598.     Tst.w    d4
  2599.     Beq.s    .nxa
  2600.     Clr.w    d4
  2601.     Add.l    d7,a1        ; x delta ( +/- 1 )
  2602.     Add.l    d7,a3
  2603. .nxa    ; -- Add Y Delta --
  2604.     Add.l    d6,a1        ; y delta ( +/- line_SCR_WIDTH )
  2605.     Add.l    d6,a3
  2606.     Dbra    d5,.ylp
  2607.  
  2608.     Movem.l    (sp)+,d0-7/a1-3
  2609.     Rts
  2610.  
  2611.  
  2612.  
  2613. .ylp2    ; -- Plot Pixel (additive intensity) --
  2614.     Move.b    (a1),d0
  2615.     Move.b    0(a2,d0.l),(a1)
  2616.     ; -- Add X Delta --    ; but only upon x-flag carry!!
  2617.     Add.l    d2,d4
  2618.     Addx.l    d1,d4
  2619.     Tst.w    d4
  2620.     Beq.s    .noxadd
  2621.     Clr.w    d4
  2622.     Add.l    d7,a1        ; x delta ( +/- 1 )
  2623. .noxadd    ; -- Add Y Delta --
  2624.     Add.l    d6,a1        ; y delta ( +/- line_SCR_WIDTH )
  2625.     Dbra    d5,.ylp2
  2626.  
  2627.  
  2628.  
  2629.     Movem.l    (sp)+,d0-7/a1-3
  2630.     Rts
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636. .lkup1    Dc.b    02,03,04,05,06,07,08,09,10,11,12,13,14,15
  2637.     Dc.b    16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
  2638.     Dc.b    31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31
  2639.  
  2640.  
  2641.  
  2642.  
  2643.     ; --+---------------------------------------------------------------+--
  2644.  
  2645.  
  2646.     section    'DataMain',DATA
  2647.  
  2648.  
  2649. line_scr_l    Dc.l    Planes
  2650. line_scr_p    Dc.l    Planes+320*200
  2651.  
  2652. line_angx    Dc.w    0
  2653. line_angy    Dc.w    0
  2654.  
  2655. Sphere_x    Dc.w    0
  2656. Sphere_y    Dc.w    0
  2657.  
  2658. l_Timer    Dc.w    0
  2659.  
  2660.  
  2661.         ; ** The Interrupt Structure **
  2662.  
  2663. line_ints    Dc.l    0,0            ; PREV, NEXT
  2664.         Dc.b    2,0            ; TYPE, PRIORITY
  2665.         Dc.l    line_intname        ; NAME
  2666.         Dc.l    0,LINE_VBL        ; DATA, CODE
  2667. line_intname    Dc.b    'Cruddy VBlank Interrupt',0
  2668.         cnop    0,4
  2669.  
  2670.  
  2671.  
  2672.  
  2673. Sphere        Dc.w    SPHERE_POINTS - 1, 0
  2674.         Dc.l    pnts, ptrot, ptpersp
  2675.         Dc.w    0,0,0, 0,0,0            ; X,Y,Z, rX,rY,rZ
  2676.         Dc.l    lines
  2677.         Dc.l    0,0,0
  2678.  
  2679.         ; -- 24-bit Palette, 64 colours --
  2680. Palette        dc.l    $00000000,$00020705,$00050e0a,$0007150f
  2681.         dc.l    $00091c14,$000c2319,$000e291e,$00103023
  2682.         dc.l    $00123728,$00153e2d,$00174532,$00205036
  2683.         dc.l    $002a5a3b,$0033653f,$003c6f43,$00457a47
  2684.         dc.l    $004f844c,$00588f50,$00619954,$006aa458
  2685.         dc.l    $0074ae5d,$007db961,$0086c365,$008fcc68
  2686.         dc.l    $0095d56b,$009cde6d,$00ade485,$00bde99e
  2687.         dc.l    $00ceefb6,$00def4ce,$00effae7,$00ffffff
  2688.  
  2689.         dc.l    $00ffffff,$00ffffff,$00ffffff,$00ffffff
  2690.         dc.l    $00ffffff,$00ffffff,$00ffffff,$00ffffff
  2691.         dc.l    $00ffffff,$00ffffff,$00ffffff,$00ffffff
  2692.         dc.l    $00ffffff,$00ffffff,$00ffffff,$00ffffff
  2693.         dc.l    $00ffffff,$00ffffff,$00ffffff,$00ffffff
  2694.         dc.l    $00ffffff,$00ffffff,$00ffffff,$00ffffff
  2695.         dc.l    $00ffffff,$00ffffff,$00ffffff,$00ffffff
  2696.         dc.l    $00ffffff,$00ffffff,$00ffffff,$00ffffff
  2697.  
  2698.  
  2699.  
  2700.         ; -- The Logo Used For Ray Projection --
  2701. Logo        incbin    'Nuance.CNK'
  2702.         ;incbin    'CantStop.CNK'        ; ** 320x100x8 (chunky-mode graphic)
  2703.  
  2704.  
  2705.         ; -- The 3 Different Lens-Flare 'bobs' --
  2706. Flare1        incbin    'Flare1.CNK'
  2707. Flare2        incbin    'Flare2.CNK'
  2708. Flare3        incbin    'Flare3.CNK'
  2709. Flare4        incbin    'Flare4.CNK'
  2710. Flare5        incbin    'Flare5.CNK'
  2711.  
  2712.  
  2713.     section    'planes',BSS_C
  2714. Planes        Ds.b    320*200*2        ; MUST remain at this size always!! (C2P)
  2715.  
  2716.  
  2717.     section    'Data',BSS
  2718. pnts        Ds.w    3*SPHERE_POINTS
  2719. lines        Ds.w    2*(SPHERE_POINTS+1)    ; '-1.l' terminated list of lines to draw
  2720. ptrot        Ds.w    3*SPHERE_POINTS
  2721. ptpersp        Ds.w    2*SPHERE_POINTS
  2722. Chunky        Ds.b    line_SCR_WH*2        ; ** This is the chunky buffer **
  2723.  
  2724.  
  2725.  
  2726.  
  2727.     ; --+------------+--
  2728.     ; --| CopperList |--
  2729.     ; --+------------+--
  2730.  
  2731.     section    'clist',DATA_C
  2732.  
  2733. CLIST
  2734. CLIST_Planes    Dc.w    BPL0PTH,0,BPL0PTL,0,BPL1PTH,0,BPL1PTL,0
  2735.         Dc.w    BPL2PTH,0,BPL2PTL,0,BPL3PTH,0,BPL3PTL,0
  2736.         Dc.w    BPL4PTH,0,BPL4PTL,0,BPL5PTH,0,BPL5PTL,0
  2737.         Dc.w    BPL6PTH,0,BPL6PTL,0,BPL7PTH,0,BPL7PTL,0
  2738.  
  2739.         Dc.w    BPLCON0,$0211,BPLCON1,0,BPLCON2,0
  2740.         Dc.w    DIWSTRT,$7A81,DIWSTOP,$2CC1,DDFSTRT,$38,DDFSTOP,$D0
  2741.         Dc.w    BPL1MOD,-8,BPL2MOD,-8
  2742.  
  2743.         Dc.w    FMODE,$0003
  2744.  
  2745.  
  2746. CLIST_Palette    ColBank    2            ; 64 Colours
  2747.  
  2748.         Dc.w    $DE07,$FFFE,BPLCON0,$0201
  2749.         Dc.w    $FFFF,$FFFE
  2750.  
  2751.  
  2752.     ; -- The empty copperlist used between effects --
  2753.  
  2754. CLIST_EMPTY    Dc.w    BPLCON0,$0200,BPLCON3,$0000,$180,BLANK_COLOUR
  2755.         Dc.w    $FFFF,$FFFE
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.     ; ***************************************************************
  2762.     ; ***                                                         ***
  2763.     ; ***  EFFECT #2: BUMPMAPPED WIREFRAME                        ***
  2764.     ; ***                                                         ***
  2765.     ; ***************************************************************
  2766.  
  2767.     section    'code2',CODE
  2768.  
  2769.  
  2770.     ; USAGE:
  2771.     ;
  2772.     ; * Call 'BUMP_INIT' as part of precalculation phase
  2773.     ;
  2774.     ; * Call 'BUMP_SHOW' to display the effect
  2775.     ;
  2776.     ; * Call 'BUMP_END' at the end of the demo
  2777.     ;
  2778.  
  2779.  
  2780. bump_SCR_WIDTH    = 320
  2781. bump_SCR_HEIGHT    = 150
  2782. bump_SCR_WH    = bump_SCR_WIDTH*bump_SCR_HEIGHT
  2783.  
  2784. LS_WIDTH    = 512                    ; lightsource size
  2785. LS_HEIGHT    = bump_SCR_HEIGHT+64            ;     "         "
  2786. LS_WH        = LS_WIDTH*LS_HEIGHT
  2787. LS_COLOURS    = 64
  2788. LS_MAGIC    = 600
  2789. LS_NOISE    = 7
  2790. LS_CX        = LS_WIDTH/2
  2791. LS_CY        = LS_HEIGHT/2
  2792.  
  2793. b_INTENS    = 42                    ; 'depth' of line drawing (0:63)
  2794.  
  2795.  
  2796.  
  2797.  
  2798.     ; *********************************************
  2799.     ; ***                                       ***
  2800.     ; ***  BUMP_INIT - Call as part of precalc  ***
  2801.     ; ***                                       ***
  2802.     ; *********************************************
  2803.  
  2804. BUMP_INIT
  2805.  
  2806.     ; --+------------------+--
  2807.     ; --| PRECALC LIGHTMAP |--
  2808.     ; --+------------------+--
  2809.  
  2810.     Lea    b_LightSource,a0
  2811.     Move.w    #LS_CX,d4
  2812.     Move.w    #LS_CY,d5
  2813.     Move.w    #LS_HEIGHT-1,d0        ; d0.w - Y Count
  2814. .ylp    Move.w    #LS_WIDTH-1,d1        ; d1.w - X Count
  2815. .xlp    Move.w    d1,d3
  2816.     Move.w    d0,d2
  2817.     Sub.w    d4,d3            ; ( CX - x )
  2818.     Sub.w    d5,d2            ; ( CY - y )
  2819.     Muls    d3,d3            ; (CX-x)^2
  2820.     Muls    d2,d2            ; (CY-y)^2
  2821.     Add.l    d3,d2            ; (CX-X)^2 + (CY-y)^2    = r²
  2822.     Lsr.l    #1,d2            ; Make light bigger!!    (was 2)
  2823.  
  2824.     Add.l    #LS_MAGIC,d2
  2825.     Move.l    #LS_MAGIC*LS_COLOURS-1,d3
  2826.     Divu.l    d2,d3
  2827.     Move.b    d3,(a0)+        ; ~ 1/r²
  2828.  
  2829.     Dbra    d1,.xlp
  2830.     Dbra    d0,.ylp
  2831.  
  2832.  
  2833. Random    Lea    b_LightSource,a0
  2834.  
  2835.     Move.w    #LS_HEIGHT-1,d7        ; d0.w - Y Count
  2836. .ylp    Move.w    #LS_WIDTH-1,d6        ; d1.w - X Count
  2837. .xlp    Move.b    (a0),d2
  2838.     And.w    #$00FF,d2
  2839.     Moveq    #LS_NOISE,d0
  2840.     Bsr    Rnd
  2841.     Sub.w    #LS_NOISE/2,d1
  2842.     Add.w    d1,d2
  2843.     Bge.s    .nomi
  2844.     Moveq    #0,d2
  2845. .nomi    Cmp.w    #LS_COLOURS-1,d2
  2846.     Ble.s    .nopl
  2847.     Move.w    #LS_COLOURS-1,d2
  2848. .nopl    Move.b    d2,(a0)+
  2849.     Dbra    d6,.xlp
  2850.     Dbra    d7,.ylp
  2851.  
  2852.  
  2853. Smooth2    Move.w    #LS_WIDTH,d0
  2854.     Move.w    #LS_HEIGHT,d1
  2855.     Lea    b_LightSource,a0
  2856.     Lea    b_LightSource,a1
  2857.     Bsr    b_Smooth
  2858.  
  2859.  
  2860.  
  2861.     ; --+-------------------------+--
  2862.     ; --| CREATE BUMPY BACKGROUND |--
  2863.     ; --+-------------------------+--
  2864.  
  2865.     Lea    b_Background,a0
  2866.     Move.w    #bump_SCR_WH-1,d7
  2867. .bumplp    Move.w    #37,d0
  2868.     Bsr    Rnd
  2869.     Move.b    d1,(a0)+
  2870.     Dbra    d7,.bumplp
  2871.  
  2872.     Move.w    #bump_SCR_WIDTH,d0
  2873.     Move.w    #bump_SCR_HEIGHT,d1
  2874.     Lea    b_Background,a0
  2875.     Lea    b_Background,a1
  2876.     Bsr    b_Smooth            ; Smooth it
  2877.     Bsr    b_Smooth            ; (twice!)  ;)
  2878.  
  2879.  
  2880.     ; --+-----------------+--
  2881.     ; --| Init Copperlist |--
  2882.     ; --+-----------------+--
  2883.  
  2884.     _LoadPalette24    b_Palette, bump_CLIST_pal, 2        ; Init Palette
  2885.     _LoadPlanes    b_Plane_P, bump_CLIST, 8, 40*200    ; Init Bitplanes
  2886.  
  2887.  
  2888.     Rts
  2889.  
  2890.  
  2891.  
  2892.  
  2893.     ; *********************************************
  2894.     ; ***                                       ***
  2895.     ; ***  BUMP_SHOW - Call to display effect   ***
  2896.     ; ***                                       ***
  2897.     ; *********************************************
  2898.  
  2899. BUMP_SHOW
  2900.  
  2901.     _TD_ChangeScreenSize    bump_SCR_WIDTH, bump_SCR_HEIGHT
  2902.     _TD_ChangeClipRegion    2,2, bump_SCR_WIDTH-3,bump_SCR_HEIGHT-3
  2903.     _TD_MovAbs        b_Object,0,0,200
  2904.  
  2905.     ; --+-------------------+--
  2906.     ; --| Add VBL Interrupt |--
  2907.     ; --+-------------------+--
  2908.  
  2909.     Moveq    #5,d0
  2910.     Lea    b_VBLStruct,a1
  2911.     Move.l    4.w,a6
  2912.     Jsr    -168(a6)        ; _LVOAddIntServer
  2913.  
  2914.  
  2915.     ; --+-----------------+--
  2916.     ; --| Show Copperlist |--
  2917.     ; --+-----------------+--
  2918.  
  2919.     _WaitVBL
  2920.  
  2921.     Move.l    #bump_CLIST,$DFF080        ; COP1LCH
  2922.     Move.w    #$FFF,$DFF088            ; COPJMP1
  2923.  
  2924.  
  2925.  
  2926.     ; --+-------------+--
  2927.     ; --| Show Effect |--
  2928.     ; --+-------------+--
  2929.  
  2930.  
  2931.  
  2932.  
  2933. .lp
  2934.     ; -- Clear Chunky Buffer --
  2935.     Move.w    #bump_SCR_WH/8-1,d0
  2936.     Lea    b_Chunky,a0
  2937. .l1    Clr.l    (a0)+
  2938.     Clr.l    (a0)+
  2939.     Dbra    d0,.l1
  2940.  
  2941.  
  2942.     ; -- Object Morph/Moving --
  2943.     Lea    TD_Sine,a0
  2944.     Move.w    b_ObjMorph,d0
  2945.     Move.w    0(a0,d0.w*2),d0
  2946.     Asr.w    #1,d0
  2947.     Add.w    #128,d0            ; Range 0:255
  2948.     Moveq    #b_POINTS,d1
  2949.     Lea    pnts1,a0
  2950.     Lea    pnts2,a1
  2951.     Lea    b_pnts,a2
  2952.     Bsr    b_Morph
  2953.  
  2954.     Lea    TD_Sine,a0
  2955.     Move.w    b_ObjXA,d0
  2956.     Move.w    b_ObjYA,d1
  2957.     Move.w    b_ObjZA,d2
  2958.     Move.w    0(a0,d0.w*2),d0
  2959.     Move.w    0(a0,d1.w*2),d1
  2960.     Move.w    0(a0,d2.w*2),d2
  2961.     Asr.w    #1,d0
  2962.     Asr.w    #2,d1
  2963. ;    Asr.w    #1,d2
  2964.     Add.w    #300,d2
  2965.     Lea    b_Object,a0
  2966.     Jsr    TD_MovAbs
  2967.  
  2968.  
  2969.     ; -- Draw 3D Object --
  2970.     _TD_Rot2    b_Object
  2971.  
  2972.     Lea    b_Object,a0
  2973.     Lea    b_Chunky,a1
  2974.     Bsr    b_DrawWire
  2975.  
  2976.  
  2977.     ; -- Smoothing --
  2978.     Move.w    #bump_SCR_WIDTH,d0
  2979.     Move.w    #bump_SCR_HEIGHT,d1
  2980.     Lea    b_Chunky,a0
  2981.     Lea    b_Chunky+bump_SCR_WH,a1
  2982.     Bsr    b_Smooth
  2983.  
  2984.  
  2985.     ; -- BumpMapping --
  2986.     Bsr    b_BumpMap
  2987.  
  2988.  
  2989.     ; -- Do C2P --
  2990.     Lea    b_Chunky+bump_SCR_WH,a0        ; cnky
  2991.     Move.l    b_Plane_L,a1            ; plnr
  2992.     Move.l    #bump_SCR_WH,d0            ; sizeof c2p conversion
  2993.     Jsr    _c2p_020
  2994.  
  2995.  
  2996.     ; -- DoubleBuffer --
  2997.     _LoadPlanes    b_Plane_L, bump_CLIST, 8, 40*200    ; Init Bitplanes
  2998.     Move.l    b_Plane_P,d0
  2999.     Move.l    b_Plane_L,b_Plane_P
  3000.     Move.l    d0,b_Plane_L
  3001.     _WaitVBL
  3002.  
  3003.  
  3004.     ; -- EXIT YET? --
  3005.     Cmp.w    #B_FRAMES,b_Timer
  3006.     Bge.s    .end
  3007.  
  3008.     ; -- Test Exit Condition --
  3009.     Btst    #6,$BFE001            ; ** Change this to your Exit test
  3010.     Bne.s    .lp
  3011.  
  3012.  
  3013.     ; ------------------
  3014.     ; -- END MAINLOOP --
  3015.     ; ------------------
  3016.  
  3017.  
  3018. .end    ; -- CLEAR DISPLAY --
  3019.     _LoadCLIST    CLIST_EMPTY
  3020.     _WaitVBL
  3021.     Jsr    ClearPlanes
  3022.  
  3023.     ; -- Remove VBL Interrupt --
  3024.     Moveq    #5,d0
  3025.     Lea    b_VBLStruct,a1
  3026.     Move.l    4.w,a6
  3027.     Jsr    -174(a6)        ; _LVORemIntServer
  3028.  
  3029.  
  3030.     Rts
  3031.  
  3032.  
  3033.  
  3034.  
  3035.     ; ********************************
  3036.     ; ***                          ***
  3037.     ; ***  S U B R O U T I N E S   ***
  3038.     ; ***                          ***
  3039.     ; ********************************
  3040.  
  3041.  
  3042.  
  3043. b_BumpMap
  3044.  
  3045.     Movem.l    d0-7/a0-3,-(sp)
  3046.  
  3047.  
  3048.     ; --------------------------
  3049.     ; -- BUMPY BACKGROUND ADD --
  3050.     ; --------------------------
  3051.     Lea    b_Background+bump_SCR_WIDTH,a0
  3052.     Lea    b_Chunky+bump_SCR_WIDTH,a1
  3053.     Move.w    #(bump_SCR_WIDTH*(bump_SCR_HEIGHT-2)/8)-1,d0
  3054. .bglp    Move.l    (a0)+,d1
  3055.     Move.l    (a0)+,d2
  3056.     Add.l    d1,(a1)+
  3057.     Add.l    d2,(a1)+
  3058.     Dbra    d0,.bglp
  3059.     ; --------------------------
  3060.  
  3061.  
  3062.  
  3063.     Lea    b_Chunky+bump_SCR_WH,a0                ; The bumpmap buffer (end)
  3064.     Lea    b_LightSource+((LS_CY+(bump_SCR_HEIGHT/2))*LS_WIDTH)+416,a1    ; The light texture
  3065.     Lea    b_Chunky+bump_SCR_WH*2,a2            ; Chunky Buffer (end)
  3066.  
  3067.     ; ----------------------
  3068.     ; -- LIGHTSOURCE MOVE --
  3069.     ; ----------------------
  3070.     Move.w    b_XAng,d0
  3071.     Move.w    b_YAng,d1
  3072.     Lea    TD_Sine,a3
  3073.     Move.w    0(a3,d0.w*2),d0
  3074.     Move.w    0(a3,d1.w*2),d1
  3075.     Asr.w    #1,d0            ; X coord (±128)
  3076.     Asr.w    #4,d1            ; Y coord (±32)
  3077.     Ext.l    d1
  3078.     Lsl.l    #8,d1
  3079.     Lsl.l    #1,d1
  3080.     Add.l    d1,a1
  3081.     Add.w    d0,a1
  3082.     ; -----------------------
  3083.  
  3084.  
  3085.  
  3086.  
  3087.  
  3088.     ; -----------
  3089.     ; -- LOOPS --
  3090.     ; -----------
  3091.  
  3092.     Move.w    #bump_SCR_HEIGHT-2,d7
  3093. .lpy    Moveq    #0,d1
  3094.     Move.w    #bump_SCR_WIDTH-1,d6
  3095. .lpx    ;-- UP/DOWN SHADE CALC. --
  3096.     Move.b    d1,d2    
  3097.     Sub.b    -bump_SCR_WIDTH(a0),d2
  3098.     Lsl.w    #8,d2
  3099.     ;-- LEFT/RIGHT SHADE CALC. --
  3100.     Move.b    d1,d2
  3101.     Move.b    -(a0),d1
  3102.     Sub.b    d1,d2
  3103.     Lsl.w    #1,d2
  3104.     ;-- WRITE TO CHUNKY --
  3105.     Move.b    0(a1,d2.w),-(a2)
  3106.     Lea    -1(a1),a1
  3107.     Dbra    d6,.lpx            ; X Loop
  3108.     Lea    -192(a1),a1            ; 320-512 [ MODULO ]
  3109.     Dbra    d7,.lpy            ; Y Loop
  3110.     ; -----------
  3111.  
  3112.  
  3113.  
  3114.     Movem.l    (sp)+,d0-7/a0-3
  3115.     Rts
  3116.  
  3117.  
  3118.  
  3119.  
  3120.  
  3121.     ; --+-----------------------+--
  3122.     ; --| UPDATE POLYGON COORDS |--
  3123.     ; --+-----------------------+--
  3124.  
  3125.     ; d0.w (0:255)    - Weighting of points 0 = obj1, 255 = obj2
  3126.     ; d1.w        - Points to morph
  3127.     ; a0.l        - Obj1 PointsList
  3128.     ; a1.l        - Obj2 PointsList
  3129.     ; a2.l        - PtsBuffer
  3130.  
  3131. b_Morph    Movem.l    d1-3/a0-2,-(sp)
  3132.  
  3133.     Mulu    #3,d1
  3134.     Subq    #1,d1    ; d1.w - # iterations
  3135.  
  3136. .mlp    Move.w    (a0)+,d2
  3137.     Move.w    (a1)+,d3
  3138.     Sub.w    d2,d3
  3139.     Muls    d0,d3
  3140.     Asr.l    #8,d3
  3141.     Add.w    d2,d3
  3142.     Move.w    d3,(a2)+
  3143.     Dbra    d1,.mlp
  3144.  
  3145.     Movem.l    (sp)+,d1-3/a0-2
  3146.  
  3147.     Rts
  3148.  
  3149.  
  3150.  
  3151.  
  3152.  
  3153.  
  3154.  
  3155. b_DrawWire                ; A0.l - Object Base, A1.l - Chunky Buffer
  3156.  
  3157.     Movem.l    d0-5/a0-2,-(sp)
  3158.  
  3159.     Move.l    TD_PT_PERSP(a0),a2    ; A2.l = Rotated -> 2D Point-List
  3160.     Move.l    TD_LINESEGS(a0),a0    ; A0.l = LineSegs List
  3161.  
  3162.     Move.w    (a0)+,d4
  3163.     Move.w    (a0)+,d5        ; Point Pair Read-Ahead
  3164.  
  3165. .1    Move.w    0(a2,d4.w*4),d0        ; X1
  3166.     Move.w    2(a2,d4.w*4),d1        ; Y1
  3167.     Move.w    0(a2,d5.w*4),d2        ; X2
  3168.     Move.w    2(a2,d5.w*4),d3        ; Y2
  3169.     ; -- Draw Line --
  3170.     Move.l    a0,-(sp)
  3171.     Lea    b_DrawLine,a0
  3172.     Jsr    TD_ClipNDraw        ; Perform Edge-Clipping / Draw
  3173.     Move.l    (sp)+,a0
  3174.     ; -- Next Point-Pair
  3175.     Move.w    (a0)+,d4
  3176.     Move.w    (a0)+,d5
  3177.     Bge.s    .1            ; Not at end of line_seg-list (-1)
  3178.  
  3179.     Movem.l    (sp)+,d0-5/a0-2
  3180.     Rts
  3181.  
  3182.  
  3183.  
  3184.  
  3185.  
  3186.  
  3187. b_DrawLine                ; D0-4.w - x1,y1, x2,y2, A1.l - Chunky Buffer
  3188.  
  3189.     Movem.l    d0-7/a1,-(sp)
  3190.  
  3191.     Move.w    d2,d4
  3192.     Move.w    d3,d5
  3193.     Sub.w    d0,d4        ; dx
  3194.     Bge.s    .nn1
  3195.     Neg.w    d4        ; |dx|
  3196. .nn1    Sub.w    d1,d5        ; dy
  3197.     Bge.s    .nn2
  3198.     Neg.w    d5        ; |dy|
  3199. .nn2    Cmp.w    d4,d5
  3200.     Bgt.s    .ymaj        ; |dy| > |dx| ?
  3201.  
  3202.  
  3203.  
  3204.     ; -- X Major:  dx > dy --
  3205.     ;
  3206.     ; d4.w - number of X iterations
  3207.     ;
  3208.  
  3209.     Moveq    #1,d7            ; d7.w -  x delta (per loop)
  3210.     Move.l    #bump_SCR_WIDTH,d6    ; d6.w -  y delta (when add overflow)
  3211.  
  3212.     Sub.w    d0,d2
  3213.     Beq.s    .nodraw        ; Don't Div 0!!
  3214.     Bge.s    .xn1
  3215.     Neg.l    d7        ; d7.w -  -1.l
  3216. .xn1    Sub.w    d1,d3        ; d3.w -  y delta
  3217.     Bge.s    .xn2
  3218.     Neg.l    d6        ; d6.w -  -line_SCR_WIDTH.w
  3219. .xn2    Mulu    #bump_SCR_WIDTH,d1
  3220.     Add.l    d1,a1
  3221.     Add.l    d1,a3
  3222.     Add.w    d0,a1        ; a1.l -  start point
  3223.     Add.w    d0,a3
  3224.  
  3225.     Ext.l    d3
  3226.     Asl.l    #8,d3        ; d3.l - [24.8] fixed point Y delta
  3227.     Divs    d4,d3
  3228.     Ext.l    d3        ; (get rid of remainder part!!)
  3229.     Ror.l    #8,d3        ; d3.l - [8.24] - [fract.int]
  3230.  
  3231.     Subq.w    #1,d4
  3232.     Moveq    #0,d5
  3233.     Move.l    d5,d0
  3234.     Move.l    d5,d1
  3235.  
  3236. .xlp    ; -- Plot Point --
  3237.     Move.b    #b_INTENS,(a1)
  3238.  
  3239.     ; -- Add Y Delta --    ; but only upon x-flag carry!!
  3240.     Add.l    d3,d5
  3241.     Addx.l    d1,d5
  3242.     Tst.w    d5
  3243.     Beq.s    .nya
  3244.     Clr.w    d5
  3245.     Add.l    d6,a1        ; Next/Prev vertical line
  3246. .nya    ; -- Add X Delta --
  3247.     Add.l    d7,a1        ; x delta ( +/- 1)
  3248.     Add.l    d7,a3
  3249.     Dbra    d4,.xlp
  3250.  
  3251. .nodraw    Movem.l    (sp)+,d0-7/a1
  3252.     Rts
  3253.  
  3254.  
  3255.  
  3256. .ymaj    ; -- Y Major:  dy > dx --
  3257.     ;
  3258.     ; d5.w - number of Y iterations
  3259.     ;
  3260.  
  3261.     Moveq    #1,d7            ; d7.w -  x delta (when add overflows)
  3262.     Move.l    #bump_SCR_WIDTH,d6    ; d6.w -  y delta (per loop)
  3263.  
  3264.     Sub.w    d1,d3
  3265.     Beq.s    .nodraw        ; Don't Div 0!!
  3266.     Bge.s    .yn1
  3267.     Neg.l    d6        ; d7.w -  -1.l
  3268. .yn1    Sub.w    d0,d2        ; d2.w -  y delta
  3269.     Bge.s    .yn2
  3270.     Neg.l    d7        ; d6.w -  -line_SCR_WIDTH.w
  3271. .yn2    Mulu    #bump_SCR_WIDTH,d1
  3272.     Add.l    d1,a1
  3273.     Add.l    d1,a3
  3274.     Add.w    d0,a1        ; a1.l -  start point
  3275.     Add.w    d0,a3
  3276.  
  3277.  
  3278.     Ext.l    d2
  3279.     Asl.l    #8,d2        ; d2.l - [24.8] fixed point X delta
  3280.     Divs    d5,d2
  3281.     Ext.l    d2        ; (get rid of remainder part!!)
  3282.     Ror.l    #8,d2        ; d2.l - [8.24] - [fract.int]
  3283.  
  3284.     Subq.w    #1,d5
  3285.     Moveq    #0,d4
  3286.     Move.l    d4,d0
  3287.     Move.l    d4,d1
  3288.  
  3289. .ylp    ; -- Plot Point --
  3290.     Move.b    #b_INTENS,(a1)
  3291.  
  3292.     ; -- Add X Delta (carry) --
  3293.     Add.l    d2,d4
  3294.     Addx.l    d1,d4
  3295.     Tst.w    d4
  3296.     Beq.s    .nxa
  3297.     Clr.w    d4
  3298.     Add.l    d7,a1        ; x delta ( +/- 1 )
  3299. .nxa    ; -- Add Y Delta --
  3300.     Add.l    d6,a1        ; y delta ( +/- line_SCR_WIDTH )
  3301.     Add.l    d6,a3
  3302.     Dbra    d5,.ylp
  3303.  
  3304.     Movem.l    (sp)+,d0-7/a1
  3305.     Rts
  3306.  
  3307.  
  3308.  
  3309.  
  3310.  
  3311.  
  3312.     ; --+--------------------------------+--
  3313.     ; --| General-Purpose Smoothing Code |--
  3314.     ; --+--------------------------------+--
  3315.  
  3316.     ; A0.l    - Source Buffer
  3317.     ; A1.l    - Temp Buffer (Same size as source)
  3318.     ; D0.w    - Screen Width
  3319.     ; D1.w    - Screen Height
  3320.  
  3321.  
  3322. b_Smooth    ; ** Limited to 64 colour chunky bitmaps (byte overflows otherwise!) **
  3323.  
  3324.  
  3325.     Movem.l    d0-7/a0-3,-(sp)
  3326.  
  3327.  
  3328.  
  3329.     ; -- Vertical Blur Phase --
  3330.  
  3331.     Movem.l    d0-1/a0-1,-(sp)
  3332.  
  3333.     Move.l    a1,a3
  3334.     Move.l    a0,a1
  3335.     Add.w    d0,a1                ;      Y
  3336.     Add.w    d0,a3                ; Dest Y
  3337.     Lea    0(a1,d0.w),a2            ; Post Y
  3338.  
  3339.     Move.w    d1,d7
  3340.     Subq.w    #2,d7
  3341.     Mulu    d0,d7
  3342.     Lsr.l    #2,d7
  3343.     Subq.l    #1,d7
  3344.     Swap    d7            ; bump_SCR_WIDTH*(bump_SCR_HEIGHT-2)/4 - 1
  3345.  
  3346. .vlo    Swap    d7
  3347. .vli    Move.l    (a0)+,d0
  3348.     Move.l    (a1)+,d1
  3349.     Move.l    (a2)+,d2
  3350.     Lsl.l    #1,d1
  3351.     Add.l    d0,d2
  3352.     Add.l    d2,d1
  3353.     Lsr.l    #2,d1
  3354.     And.l    #$3F3F3F3F,d1
  3355.     Move.l    d1,(a3)+
  3356.     Dbra    d7,.vli
  3357.     Swap    d7
  3358.     Dbra    d7,.vlo
  3359.  
  3360.     Movem.l    (sp)+,d0-1/a0-1
  3361.  
  3362.  
  3363.  
  3364.     ; -- Horizontal Blur Phase --
  3365.  
  3366.     Add.w    d0,a0
  3367.     Add.w    d0,a1
  3368.  
  3369.     Move.w    d1,d7
  3370.     Subq.w    #2,d7
  3371.     Mulu    d0,d7
  3372.     Lsr.l    #1,d7
  3373.     Subq.l    #1,d7        ; (bump_SCR_WIDTH*(bump_SCR_HEIGHT-2)/2) - 1
  3374.     Swap    d7
  3375.  
  3376. .hlo    Swap    d7
  3377. .hli    Move.l    (a1),d0
  3378.     Move.l    d0,d1
  3379.     Move.l    d0,d2
  3380.     Lsl.l    #8,d1
  3381.     Lsr.l    #8,d2
  3382.     Lsl.l    #1,d0
  3383.     Add.l    d1,d2
  3384.     Add.l    d0,d2
  3385.     Lsr.l    #8,d2
  3386.     Lsr.l    #2,d2
  3387.     And.w    #$3F3F,d2
  3388.     Lea    2(a1),a1
  3389.     Move.w    d2,(a0)+
  3390.     Dbra    d7,.hli
  3391.     Swap    d7
  3392.     Dbra    d7,.hlo
  3393.  
  3394.  
  3395.     Movem.l    (sp)+,d0-d7/a0-3
  3396.     Rts
  3397.  
  3398.  
  3399.  
  3400.  
  3401.  
  3402.     ;***********************************
  3403.     ;***   Random Number Generator   ***
  3404.     ;***   Borrowed Form Bullfrog!   ***
  3405.     ;***********************************
  3406.  
  3407.     ; D0 - Range (0 - x)
  3408.     ; D1 - Returns Number (Long Word, But Only Grab Word!)
  3409.  
  3410. Rnd    Move.w    .seed(pc),d1
  3411.     Mulu    #9377,d1
  3412.     Add.w    #9439,d1
  3413.     Move.w    d1,.seed        ; Store Value For Seed Next Time
  3414.     And.l    #$7FFF,d1        ; Make Sure Positive Word
  3415.  
  3416.     Divu    d0,d1
  3417.     Swap    d1            ; Make Remainder Low Word
  3418.  
  3419.     Rts
  3420.  
  3421. .seed    Dc.w    13            ; Random Seed
  3422.  
  3423.  
  3424.  
  3425.  
  3426.  
  3427.  
  3428.  
  3429.     ; ************************
  3430.     ; ***                  ***
  3431.     ; ***  Interrupt Code  ***
  3432.     ; ***                  ***
  3433.     ; ************************
  3434.  
  3435.  
  3436. b_VBLCode                ; This should be executed every frame (50-60Hz)
  3437.     Movem.l    d2-7/a2-6,-(sp)
  3438.  
  3439.  
  3440.     ; -- Rotate Object --
  3441.     _TD_RotRel    b_Object, 1,1,0        ; X,Y,Z Rotation
  3442.  
  3443.     ; -- Move Lightsource --
  3444.     Move.l    b_XAng,d0
  3445.     Add.l    #$00020003,d0
  3446.     And.l    #$01FF01FF,d0
  3447.     Move.l    d0,b_XAng
  3448.  
  3449.  
  3450.     ; -- Morph Value Update
  3451.     Move.w    b_ObjMorph,d0
  3452.     Add.w    #3,d0
  3453.     And.w    #$01FF,d0
  3454.     Move.w    d0,b_ObjMorph
  3455.  
  3456.     ; -- Move Object --
  3457.     Move.l    b_ObjXA,d0
  3458.     Move.w    b_ObjZA,d1
  3459.     Add.l    #$00010002,d0
  3460.     Add.w    #$0004,d1
  3461.     And.l    #$01FF01FF,d0
  3462.     And.w    #$01FF,d1
  3463.     Move.l    d0,b_ObjXA
  3464.     Move.w    d1,b_ObjZA
  3465.  
  3466.     ; -- ** TIMER ** --
  3467.     Add.w    #1,b_Timer
  3468.  
  3469.     Movem.l    (sp)+,d2-7/a2-6
  3470.     Moveq    #0,d0
  3471.     Rts
  3472.  
  3473.  
  3474.  
  3475.  
  3476.  
  3477.  
  3478.  
  3479.     ; *********************************
  3480.     ; ***                           ***
  3481.     ; ***  D A T A   S E C T I O N  ***
  3482.     ; ***                           ***
  3483.     ; *********************************
  3484.  
  3485.  
  3486. b_Plane_L    Dc.l    Planes            ; Logical Buffer
  3487. b_Plane_P    Dc.l    Planes+320*200        ; Physical Buffer
  3488.  
  3489. b_XAng        Dc.w    0
  3490. b_YAng        Dc.w    0
  3491.  
  3492. b_ObjXA        Dc.w    0
  3493. b_ObjYA        Dc.w    0
  3494. b_ObjZA        Dc.w    0
  3495. b_ObjMorph    Dc.w    0
  3496.  
  3497. b_Timer        Dc.w    0
  3498.  
  3499. b_Palette    dc.l    $00000028,$0008052f,$00100936,$00180e3c
  3500.         dc.l    $00201243,$0028174a,$00301b51,$00382058
  3501.         dc.l    $003f245e,$00472965,$004f2d6c,$00573273
  3502.         dc.l    $005f367a,$00673b80,$006f3f87,$00754485
  3503.         dc.l    $007a4982,$00804e80,$0086537d,$008b587b
  3504.         dc.l    $00915d78,$00976276,$009c6773,$00a26c71
  3505.         dc.l    $00a77572,$00ad7f73,$00b28875,$00b79176
  3506.         dc.l    $00bd9b77,$00c2a478,$00c7ad79,$00ccb67b
  3507.         dc.l    $00d2c07c,$00d7c97d,$00d8cb81,$00dacd86
  3508.         dc.l    $00dbce8a,$00dcd08e,$00ded293,$00dfd497
  3509.         dc.l    $00e0d69b,$00e2d7a0,$00e3d9a4,$00e4dba8
  3510.         dc.l    $00e6ddad,$00e7dfb1,$00e8e0b5,$00eae2ba
  3511.         dc.l    $00ebe4be,$00ece6c2,$00eee8c7,$00efe9cb
  3512.         dc.l    $00f0ebcf,$00f2edd4,$00f3efd8,$00f4f1dc
  3513.         dc.l    $00f6f2e1,$00f7f4e5,$00f8f6e9,$00faf8ee
  3514.         dc.l    $00fbfaf2,$00fcfbf6,$00fefdfb,$00ffffff
  3515.  
  3516.  
  3517. b_POINTS    = 12
  3518. b_FACES        = 0
  3519.  
  3520. b_Object    Dc.w    b_POINTS - 1,  b_FACES - 1
  3521.         Dc.l    b_pnts, b_ptrot, b_ptpersp
  3522.         Dc.w    0,0,0, 0,0,0
  3523.         Dc.l    .lineseg
  3524.         Dc.l    0,0,0,0
  3525.  
  3526.  
  3527. .lineseg    Dc.w    $0000,$0003,$0003,$0002,$0002,$0001,$0001,$0000,$0004,$0005
  3528.         Dc.w    $0004,$0007,$0007,$0006,$0006,$0005,$0004,$0003,$0000,$0007
  3529.         Dc.w    $0002,$0005,$0006,$0001,$0000,$0008,$0008,$0003,$0001,$0009
  3530.         Dc.w    $0009,$0002,$0000,$000A,$000A,$0001,$0002,$000B,$000B,$0003
  3531.         Dc.w    $0007,$0008,$0008,$0004,$0004,$000B,$000B,$0005,$0005,$0009
  3532.         Dc.w    $0009,$0006,$0006,$000A,$000A,$0007
  3533.         Dc.w    -1,-1
  3534.  
  3535. pnts1        Dc.w    $FFD8,$0028,$0014, $0028,$0028,$0014, $0028,$FFD8,$0014
  3536.         Dc.w    $FFD8,$FFD8,$0014, $FFD8,$FFD8,$FFEC, $0028,$FFD8,$FFEC
  3537.         Dc.w    $0028,$0028,$FFEC, $FFD8,$0028,$FFEC, $FF88,$0000,$0000
  3538.         Dc.w    $0078,$0000,$0000, $0000,$0078,$0000, $0000,$FF88,$0000
  3539.  
  3540. pnts2        Dc.w    $FFB0,$0050,$0014, $0050,$0050,$0014, $0050,$FFB0,$0014
  3541.         Dc.w    $FFB0,$FFB0,$0014, $FFB0,$FFB0,$FFEC, $0050,$FFB0,$FFEC
  3542.         Dc.w    $0050,$0050,$FFEC, $FFB0,$0050,$FFEC, $FFD8,$0000,$0000
  3543.         Dc.w    $0028,$0000,$0000, $0000,$0028,$0000, $0000,$FFD8,$0000
  3544.  
  3545.  
  3546.  
  3547. b_VBLStruct    Dc.l    0,0
  3548.         Dc.b    2,0
  3549.         Dc.l    b_VBLName
  3550.         Dc.l    0,b_VBLCode
  3551. b_VBLName    Dc.b    'BumpMap Effect VBL Interrupt',$00
  3552.         even
  3553.  
  3554.  
  3555.  
  3556.     section    'FastRAM',BSS
  3557.  
  3558. b_Chunky    Ds.b    bump_SCR_WH*2
  3559. b_LightSource    Ds.b    LS_WIDTH*LS_HEIGHT
  3560. b_Background    Ds.b    bump_SCR_WH        ; 'bumpy' background
  3561.  
  3562. b_pnts        Ds.w    3*b_POINTS
  3563. b_ptrot        Ds.w    3*b_POINTS
  3564. b_ptpersp    Ds.w    2*b_POINTS
  3565.  
  3566.  
  3567.  
  3568.     section    'CopperList',DATA_C
  3569.  
  3570. bump_CLIST    Dc.w    BPL0PTH,0,BPL0PTL,0,BPL1PTH,0,BPL1PTL,0
  3571.         Dc.w    BPL2PTH,0,BPL2PTL,0,BPL3PTH,0,BPL3PTL,0
  3572.         Dc.w    BPL4PTH,0,BPL4PTL,0,BPL5PTH,0,BPL5PTL,0
  3573.         Dc.w    BPL6PTH,0,BPL6PTL,0,BPL7PTH,0,BPL7PTL,0
  3574.  
  3575.         Dc.w    BPLCON0,$0210,BPLCON1,0,BPLCON2,0,BPLCON3,0
  3576.         Dc.w    DIWSTRT,$6181,DIWSTOP,$2CC1,DDFSTRT,$38,DDFSTOP,$A0
  3577.         Dc.w    BPL1MOD,0,BPL2MOD,0,FMODE,$0003
  3578.  
  3579. bump_CLIST_pal    ColBank    2                ; 64 colours
  3580.  
  3581.         Dc.w    $F707,$FFFE,BPLCON0,$0200
  3582.         Dc.w    $FFFF,$FFFE
  3583.  
  3584.  
  3585.  
  3586.  
  3587.  
  3588.  
  3589.     ; ***************************************************************
  3590.     ; ***                                                         ***
  3591.     ; ***  EFFECT #3: TEXTURED SCENE                              ***
  3592.     ; ***                                                         ***
  3593.     ; ***************************************************************
  3594.  
  3595.  
  3596.     ; Usual stuff applies here:
  3597.     ;
  3598.     ; * Call SCENE_INIT as part of precalc
  3599.     ;
  3600.     ; * Call SCENE_SHOW to display the effect
  3601.     ;
  3602.     ; * Call SCENE_END after demo is finished (may not even need to call this ;))
  3603.  
  3604.  
  3605.  
  3606.  
  3607.     section    'Code3',CODE
  3608.  
  3609.  
  3610. scene_SCR_WIDTH        = 320
  3611. scene_SCR_HEIGHT    = 200
  3612. scene_SCR_WH        = scene_SCR_WIDTH*scene_SCR_HEIGHT
  3613.  
  3614.  
  3615.  
  3616.  
  3617.     ; ********************
  3618.     ; ***              ***
  3619.     ; ***  SCENE_INIT  ***
  3620.     ; ***              ***
  3621.     ; ********************
  3622.  
  3623. SCENE_INIT
  3624.  
  3625.     ; -- Precalculate Textures --
  3626.  
  3627.  
  3628.     ; -- TEXTURE #1 --
  3629.     Lea    s_temp64,a0
  3630.     Move.w    #64*64-1,d7
  3631. .lp1    Moveq    #13,d0
  3632.     Jsr    Rnd
  3633.     Add.b    #16,d0
  3634.     Move.b    d1,(a0)+
  3635.     Dbra    d7,.lp1
  3636.  
  3637.     Lea    s_temp64,a0
  3638.     Move.l    a0,a1
  3639.     Moveq    #64,d0
  3640.     Move.w    d0,d1
  3641.     Jsr    b_Smooth
  3642.     Jsr    b_Smooth
  3643.     Lea    s_txr1,a1
  3644.     Bsr    s_Copy
  3645.  
  3646.     ; -- TEXTURE #2 --
  3647.     Lea    s_temp64,a0
  3648.     Move.w    #64*64-1,d7
  3649. .lp2    Add.b    #4,(a0)+
  3650.     Dbra    d7,.lp2
  3651.     Lea    s_txr1+64,a1
  3652.     Bsr    s_Copy
  3653.  
  3654.     ; -- TEXTURE #3 --
  3655.     Lea    s_temp64,a0
  3656.     Move.w    #64*64-1,d0
  3657. .lp3    Move.b    (a0),d1
  3658.     Add.b    #32+8,d1
  3659.     Move.b    d1,(a0)+
  3660.     Dbra    d0,.lp3
  3661.  
  3662.     Lea    s_txr1+128,a1
  3663.     Bsr    s_Copy
  3664.  
  3665.     ; -- TEXTURE #4 --
  3666.     Lea    s_temp64,a0
  3667.     Move.w    #64*64-1,d7
  3668. .lp4    Sub.b    #8,(a0)+
  3669.     Dbra    d7,.lp4
  3670.     Lea    s_txr1+128+64,a1
  3671.     Bsr    s_Copy
  3672.  
  3673.  
  3674.     ; -- BACKGROUND TEXTURE --
  3675.     Lea    s_Background,a0
  3676.     Move.w    #scene_SCR_WH-1,d7
  3677. .lp5    Move.w    #9,d0
  3678.     Jsr    Rnd
  3679.     Move.b    d1,(a0)+
  3680.     Dbra    d7,.lp5
  3681.  
  3682.     Lea    s_Background,a0
  3683.     Move.l    a0,a1
  3684.     Move.w    #scene_SCR_WIDTH,d0
  3685.     Move.w    #scene_SCR_HEIGHT,d1
  3686.     Jsr    b_Smooth
  3687.  
  3688.     Lea    s_Background,a0
  3689.     Move.l    a0,a1
  3690.     Move.w    #scene_SCR_WIDTH,d0
  3691.     Move.w    #scene_SCR_HEIGHT,d1
  3692.     Jsr    b_Smooth
  3693.  
  3694.     Lea    s_Background,a0
  3695.     Move.w    #scene_SCR_WH/8-1,d7
  3696. .lp6    Or.l    #$40404040,(a0)+
  3697.     Or.l    #$40404040,(a0)+
  3698.     Dbra    d7,.lp6
  3699.  
  3700.  
  3701.  
  3702.     ; -- Setup CopperList
  3703.     _LoadPalette24    s_Palette, s_CLIST_Pal, 4
  3704.     _LoadPlanes    s_PlaneL, s_CLIST, 8, 40*200
  3705.  
  3706.  
  3707.     Rts
  3708.  
  3709.  
  3710.  
  3711. s_Copy    Lea    s_temp64,a0        ; Fill in a1 as needed
  3712.     Moveq    #63,d0
  3713. .1    Move.l    (a0)+,(a1)+
  3714.     Move.l    (a0)+,(a1)+
  3715.     Move.l    (a0)+,(a1)+
  3716.     Move.l    (a0)+,(a1)+
  3717.     Move.l    (a0)+,(a1)+
  3718.     Move.l    (a0)+,(a1)+
  3719.     Move.l    (a0)+,(a1)+
  3720.     Move.l    (a0)+,(a1)+
  3721.     Move.l    (a0)+,(a1)+
  3722.     Move.l    (a0)+,(a1)+
  3723.     Move.l    (a0)+,(a1)+
  3724.     Move.l    (a0)+,(a1)+
  3725.     Move.l    (a0)+,(a1)+
  3726.     Move.l    (a0)+,(a1)+
  3727.     Move.l    (a0)+,(a1)+
  3728.     Move.l    (a0)+,(a1)+
  3729.     Lea    256-64(a1),a1
  3730.     Dbra    d0,.1
  3731.     Rts
  3732.  
  3733.  
  3734.  
  3735.  
  3736.     ; ********************
  3737.     ; ***              ***
  3738.     ; ***  SCENE_SHOW  ***
  3739.     ; ***              ***
  3740.     ; ********************
  3741.  
  3742. SCENE_SHOW
  3743.  
  3744.     ; -- ADD VBL INTERRUPT --
  3745.     Moveq    #5,d0
  3746.     Lea    s_VBL_IntS,a1
  3747.     Move.l    4.w,a6
  3748.     Jsr    -168(a6)        ; _LVOAddIntServer
  3749.  
  3750.  
  3751.     ; -- OTHER INIT STUFF --
  3752.     _WaitVBL
  3753.     _LoadCList    s_CLIST
  3754.  
  3755.  
  3756.     _TD_ChangeScreenSize    scene_SCR_WIDTH, scene_SCR_HEIGHT
  3757.     _TD_ChangeClipRegion    1,1, scene_SCR_WIDTH-2,scene_SCR_HEIGHT-2
  3758.     _TD_ChangeTxlSize    1        ; 64x64 textures
  3759.  
  3760.  
  3761. .lp    ; -- Clear Screen --
  3762.     Move.w    #scene_SCR_WH/8-1,d0
  3763.     Sub.w    #scene_SCR_WIDTH/8,d0
  3764.     Lea    s_Background+scene_SCR_WIDTH,a0
  3765.     Lea    s_Chunky+scene_SCR_WIDTH,a1        ; Workaround for weird bug!!
  3766. .cllp    Move.l    (a0)+,(a1)+
  3767.     Move.l    (a0)+,(a1)+
  3768.     Dbra    d0,.cllp
  3769.  
  3770.     ; -- Draw Scene --
  3771.     Bsr    s_DrawScene
  3772.  
  3773.  
  3774.     ; -- C2P --
  3775.     Lea    s_Chunky,a0
  3776.     Move.l    s_PlaneL,a1
  3777.     Move.l    #scene_SCR_WH,d0
  3778.     Jsr    _c2p_020
  3779.  
  3780.  
  3781.     ; -- DoubleBuffer --
  3782.     _WaitVBL
  3783.     _LoadPlanes    s_PlaneL, s_CLIST, 8, 40*200
  3784.     Move.l    s_PlaneL,d0
  3785.     Move.l    s_PlaneP,s_PlaneL
  3786.     Move.l    d0,s_PlaneP
  3787.  
  3788.  
  3789.     ; -- END OF EFFECT? --
  3790.     Cmp.w    #S_FRAMES,s_Timer
  3791.     Bge.s    .end
  3792.  
  3793.     ; -- EXIT? --
  3794.     Btst    #6,$BFE001
  3795.     Bne.s    .lp
  3796.  
  3797.  
  3798.  
  3799.     ; ------------------
  3800.     ; -- END MAINLOOP --
  3801.     ; ------------------
  3802.  
  3803.  
  3804.  
  3805. .end    ; -- CLEAR DISPLAY --
  3806.     ;_LoadCLIST    CLIST_EMPTY
  3807.     ;_WaitVBL
  3808.     Jsr    ClearPlanes
  3809.  
  3810.     ; -- REMOVE VBL INTERRUPT --
  3811.     Moveq    #5,d0
  3812.     Lea    s_VBL_IntS,a1
  3813.     Move.l    4.w,a6
  3814.     Jsr    -174(a6)            ; _LVORemIntServer
  3815.  
  3816.  
  3817.     Rts
  3818.  
  3819.  
  3820.  
  3821.  
  3822.     ; ********************************
  3823.     ; ***                          ***
  3824.     ; ***  S U B R O U T I N E S   ***
  3825.     ; ***                          ***
  3826.     ; ********************************
  3827.  
  3828.  
  3829. s_DrawScene
  3830.  
  3831.     ; -- ROTATE STAR SHAPE --
  3832.  
  3833.     _TD_Rot2    s_Star
  3834.  
  3835.  
  3836.     ; -- FILL DEPTH-SORT ARRAY --
  3837.     Lea    s_Star_ptr,a0
  3838.     Lea    s_Star_dsarr,a1
  3839.     Moveq    #5-1,d0
  3840.     Moveq    #0,d1
  3841. .dsl    Move.w    4(a0),d2        ; Z Coord
  3842.     Move.w    d1,(a1)+        ; Point Number
  3843.     Move.w    d2,(a1)+
  3844.     Lea    6(a0),a0
  3845.     Addq.w    #1,d1
  3846.     Dbra    d0,.dsl
  3847.  
  3848.     ; -- DEPTH-SORT COORDS --
  3849.     Lea    s_Star_dsarr,a0
  3850.     Moveq    #5-1,d0
  3851.     Jsr    TD_InsertSort
  3852.  
  3853.     ; -- DRAW OBJECTS --
  3854.     Lea    s_Star_dsarr,a0
  3855.     Lea    s_Objects,a1
  3856.     Lea    s_Star_ptr,a2        ; Star's rotated coords
  3857.  
  3858.  
  3859.     Moveq    #4,d7
  3860. .lp    Move.w    (a0),d4            ; Object Number
  3861.     Lea    4(a0),a0        ; (next object)
  3862.  
  3863.     Movem.l    a0-1,-(sp)
  3864.     Move.l    0(a1,d4.w*4),a0        ; The Object
  3865.     Mulu    #6,d4
  3866.     Move.w    0(a2,d4.w),d0        ; X Pos
  3867.     Move.w    2(a2,d4.w),d1        ; Y Pos
  3868.     Move.w    4(a2,d4.w),d2        ; Z Pos
  3869.     Add.w    #350,d2        ; Mystery Add Factor ;)
  3870.     Jsr    TD_MovAbs        ; Move this object to correct spot
  3871.     Jsr    TD_Rot2            ; And rotate its points
  3872.     Lea    s_Chunky,a1
  3873.     Jsr    TD_Ck_DepthSort_TmapObj    ; And Draw it
  3874.     Movem.l    (sp)+,a0-1
  3875.  
  3876.     Dbra    d7,.lp
  3877.  
  3878.     Rts
  3879.  
  3880.  
  3881.  
  3882.  
  3883.     ; ***************************************
  3884.     ; ***                                 ***
  3885.     ; ***  V B L A N K   I N T   C O D E  ***
  3886.     ; ***                                 ***
  3887.     ; ***************************************
  3888.  
  3889.  
  3890. s_VBL_IntCode
  3891.     Movem.l    d2-7/a2-6,-(sp)
  3892.  
  3893.  
  3894.     Lea    TD_Sine,a0
  3895.  
  3896.     Move.w    s_S_xyz,d0
  3897.     Move.w    s_S_xyz+2,d1
  3898.     Move.w    s_S_xyz+4,d2
  3899.  
  3900.     Addq.w    #2,d0
  3901.     Addq.w    #1,d1
  3902.     Addq.w    #3,d2
  3903.  
  3904.     And.w    #$01FF,d0
  3905.     And.w    #$01FF,d1
  3906.     And.w    #$01FF,d2
  3907.  
  3908.     Move.w    d0,s_S_xyz
  3909.     Move.w    d1,s_S_xyz+2
  3910.     Move.w    d2,s_S_xyz+4
  3911.  
  3912.     Move.w    0(a0,d0.w*2),d0
  3913.     Asr.w    #3,d0
  3914.  
  3915.  
  3916.  
  3917.     Moveq.w    #0,d2
  3918.  
  3919.     Lea    s_Star,a0        ; The Star
  3920.     Jsr    TD_RotAbs
  3921.  
  3922.  
  3923.     Move.w    s_S_xyz+4,d2
  3924.  
  3925.     And.w    #$01FF,d1
  3926.     Lea    s_S_obj1,a0        ; Tri 1
  3927.     Jsr    TD_RotAbs
  3928.     Add.w    #128,d1
  3929.     And.w    #$01FF,d1
  3930.     Lea    s_S_obj2,a0        ; Tri2
  3931.     Jsr    TD_RotAbs
  3932.     Add.w    #128,d1
  3933.     And.w    #$01FF,d1
  3934.     Lea    s_S_obj3,a0        ; Tri 3
  3935.     Jsr    TD_RotAbs
  3936.     Add.w    #128,d1
  3937.     And.w    #$01FF,d1
  3938.     Lea    s_S_obj4,a0        ; Tri 4
  3939.     Jsr    TD_RotAbs
  3940.  
  3941.  
  3942.     Moveq.w    #0,d2
  3943.  
  3944.     Neg.w    d1
  3945.     And.w    #$01FF,d1
  3946.     Lea    s_N_obj,a0        ; N obj
  3947.     Jsr    TD_RotAbs
  3948.  
  3949.  
  3950.     ; -- ** TIMER ** --
  3951.     Add.w    #1,s_Timer
  3952.  
  3953.     Movem.l    (sp)+,d2-7/a2-6
  3954.     Moveq    #0,d0
  3955.     Rts
  3956.  
  3957.  
  3958.  
  3959.  
  3960.     ; *********************************
  3961.     ; ***                           ***
  3962.     ; ***  D A T A   S E C T I O N  ***
  3963.     ; ***                           ***
  3964.     ; *********************************
  3965.  
  3966.  
  3967. s_PlaneL    Dc.l    Planes
  3968. s_PlaneP    Dc.l    Planes+320*200
  3969.  
  3970. s_Timer        Dc.w    0
  3971.  
  3972. s_N_xyz        Dc.w    0,0,0
  3973. s_S_xyz        Dc.w    0,0,0
  3974.  
  3975.  
  3976. s_Palette
  3977.  
  3978.         dc.l    $00000000,$00061117,$000c1a22,$0013232c
  3979.         dc.l    $00192c37,$00203541,$00263e4c,$002d4756
  3980.         dc.l    $00335061,$0039586c,$00406176,$00466a81
  3981.         dc.l    $004d738b,$00537c96,$005a85a0,$00608eab
  3982.         dc.l    $006894b0,$00709ab6,$0077a0bb,$007fa6c0
  3983.         dc.l    $0087acc5,$008fb2cb,$0097b8d0,$009fbed5
  3984.         dc.l    $00a6c4da,$00aecae0,$00b6d0e5,$00bed6ea
  3985.         dc.l    $00c6dcef,$00cde2f5,$00d5e8fa,$00ddeeff
  3986.  
  3987.         dc.l    $00000000,$00080807,$0011100e,$00191815
  3988.         dc.l    $0022201c,$002a2823,$00332f2a,$003b3731
  3989.         dc.l    $00443f38,$004c473f,$00554f46,$005d574c
  3990.         dc.l    $00655f53,$006e675a,$00766f61,$007f7768
  3991.         dc.l    $00877f6f,$00908676,$00988e7d,$00a19684
  3992.         dc.l    $00a99e8b,$00b2a692,$00baae99,$00c2b7a4
  3993.         dc.l    $00c9c0b0,$00d1c9bb,$00d9d2c6,$00e0dbd2
  3994.         dc.l    $00e8e4dd,$00f0ede8,$00f7f6f4,$00ffffff
  3995.  
  3996.         dc.l    $00110b1c,$00161021,$001c1626,$00211b2b
  3997.         dc.l    $00262030,$002b2635,$00312b3a,$0036303f
  3998.         dc.l    $003b3643,$00403b48,$0046404d,$004b4652
  3999.         dc.l    $00504b57,$0055505c,$005b5661,$00605b66
  4000.         dc.l    $00ff0000,$00ee0000,$00dd0000,$00cc0000
  4001.         dc.l    $00bb0000,$00aa0000,$00990000,$00880000
  4002.         dc.l    $00770000,$00660000,$00550000,$00440000
  4003.         dc.l    $00330000,$00220000,$00110000,$00000000
  4004.         dc.l    $0000ff00,$0000ee00,$0000dd00,$0000cc00
  4005.         dc.l    $0000bb00,$0000aa00,$00009900,$00008800
  4006.         dc.l    $00007700,$00006600,$00005500,$00004400
  4007.         dc.l    $00003300,$00002200,$00001100,$00000000
  4008.         dc.l    $000000ff,$000000ee,$000000dd,$000000cc
  4009.         dc.l    $000000bb,$000000aa,$00000099,$00000088
  4010.         dc.l    $00000077,$00000066,$00000055,$00000044
  4011.         dc.l    $00000033,$00000022,$00000011,$00000000
  4012.  
  4013.  
  4014.  
  4015. s_VBL_IntS    Dc.l    0,0
  4016.         Dc.b    2,0
  4017.         Dc.l    s_VBL_IntN
  4018.         Dc.l    0,s_VBL_IntCode
  4019. s_VBL_IntN    Dc.b    'Krusty VBlank Int #3',0
  4020.         CNOP    0,4
  4021.  
  4022.  
  4023.     ; ------------------------
  4024.     ; -- OBJECT DEFINITIONS --
  4025.     ; ------------------------
  4026.  
  4027. s_Objects    Dc.l    s_N_obj,s_S_obj1,s_S_obj2,s_S_obj3,s_S_obj4
  4028.  
  4029. s_N_POINTS    = 20
  4030. s_N_FACES    = 16
  4031.  
  4032. s_N_obj        Dc.w    s_N_POINTS-1, s_N_FACES-1
  4033.         Dc.l    .pts,s_ptr,s_ptp
  4034.         Dc.w    0,0,0, 0,0,0
  4035.         Dc.l    0        ; lineseg
  4036.         Dc.l    .facel        ; facelist
  4037.         Dc.l    0        ; goraud list
  4038.         Dc.l    .txlst        ; texel coord list
  4039.         Dc.l    s_dsarr        ; depth-sort array
  4040.  
  4041. .facel    Dc.l    .f0,.f1,.f2,.f3,.f4,.f5,.f6,.f7
  4042.     Dc.l    .f8,.f9,.fa,.fb,.fc,.fd,.fe,.ff
  4043.  
  4044.     ; -- FRONT FACE --
  4045. .f0    Dc.l    s_txr1+128
  4046.     Dc.w    0,0, 9,1, 3,7, 2,8, 1,9, 0,0, -1
  4047. .f1    Dc.l    s_txr1+128
  4048.     Dc.w    9,1, 8,2, 4,6, 3,7, 9,1, -1
  4049. .f2    Dc.l    s_txr1+128
  4050.     Dc.w    7,3, 6,4, 5,5, 4,6, 8,2, 7,3, -1
  4051.  
  4052.     ; -- BACK FACE --
  4053. .f3    Dc.l    s_txr1+128
  4054.     Dc.w    10,0, 11,9, 12,8, 13,7, 19,1, 10,0, -1
  4055. .f4    Dc.l    s_txr1+128
  4056.     Dc.w    19,1, 13,7, 14,6, 18,2, 19,1, -1
  4057. .f5    Dc.l    s_txr1+128
  4058.     Dc.w    16,4, 17,3, 18,2, 14,6, 15,5, 16,4, -1
  4059.  
  4060.  
  4061.     ; -- SURROUNDING FACES --
  4062. .f6    Dc.l    s_txr1+64+128
  4063.     Dc.w    10,0, 19,1, 9,1, 0,0, 10,0, -1
  4064. .f7    Dc.l    s_txr1+64+128
  4065.     Dc.w    19,1, 18,2, 8,2, 9,1, 19,1, -1
  4066. .f8    Dc.l    s_txr1+64+128
  4067.     Dc.w    17,3, 7,3, 8,2, 18,2, 17,3, -1
  4068. .f9    Dc.l    s_txr1+64+128
  4069.     Dc.w    17,3,16,4, 6,4, 7,3, 17,3, -1
  4070. .fa    Dc.l    s_txr1+64+128
  4071.     Dc.w    6,4, 16,4, 15,5, 5,5, 6,4, -1
  4072. .fb    Dc.l    s_txr1+64+128
  4073.     Dc.w    4,6, 5,5, 15,5, 14,6, 4,6, -1
  4074. .fc    Dc.l    s_txr1+64+128
  4075.     Dc.w    4,6, 14,6, 13,7, 3,7, 4,6, -1
  4076. .fd    Dc.l    s_txr1+64+128
  4077.     Dc.w    3,7, 13,7, 12,8, 2,8, 3,7, -1
  4078. .fe    Dc.l    s_txr1+64+128
  4079.     Dc.w    1,9, 2,8, 12,8, 11,9, 1,9, -1
  4080. .ff    Dc.l    s_txr1+64+128
  4081.     Dc.w    10,0, 0,0, 1,9, 11,9, 10,0, -1
  4082.  
  4083. .txlst    Dc.w    00,01, 19,01, 46,35, 46,01, 63,01
  4084.     Dc.w    63,62, 46,62, 19,29, 19,62, 00,62
  4085.  
  4086. .pts    Dc.w    $0078,$FFB0,$0014,$0096,$0096,$0014,$001E,$006E,$0014,$003C
  4087.     Dc.w    $FFEC,$0014,$FFEC,$0050,$0014,$FF9C,$0064,$0014,$FF74,$FF6A
  4088.     Dc.w    $0014,$FFE2,$FF9C,$0014,$FFD8,$000A,$0014,$0031,$FF93,$0013
  4089.     Dc.w    $0078,$FFB0,$FFEC,$0096,$0096,$FFEC,$001E,$006E,$FFEC,$003C
  4090.     Dc.w    $FFEC,$FFEC,$FFEC,$0050,$FFEC,$FF9C,$0064,$FFEC,$FF74,$FF6A
  4091.     Dc.w    $FFEC,$FFE2,$FF9C,$FFEC,$FFD8,$000A,$FFEC,$0031,$FF93,$FFED
  4092.  
  4093.     ;Dc.w    $006D,$FF93,$0013,$006D,$006D,$0014,$0031,$006D,$0014,$0031
  4094.     ;Dc.w    $FFF7,$0013,$FFCF,$006D,$0013,$FF93,$006D,$0013,$FF93,$FF93
  4095.     ;Dc.w    $0013,$FFCF,$FF93,$0013,$FFCF,$0009,$0013,$0031,$FF93,$0013
  4096.     ;Dc.w    $006D,$FF93,$FFED,$006D,$006D,$FFED,$0031,$006D,$FFED,$0031
  4097.     ;Dc.w    $FFF7,$FFED,$FFCF,$006D,$FFED,$FF93,$006D,$FFED,$FF93,$FF93
  4098.     ;Dc.w    $FFEC,$FFCF,$FF93,$FFEC,$FFCF,$0009,$FFED,$0031,$FF93,$FFED
  4099.  
  4100.  
  4101.  
  4102. s_S_POINTS    = 5
  4103. s_S_FACES    = 5
  4104.  
  4105.  
  4106. s_S_obj1
  4107.     Dc.w    s_S_POINTS-1, s_S_FACES-1
  4108.     Dc.l    s_pts,s_S_ptrot,s_S_ptpersp
  4109.     Dc.w    0,0,0, 0,0,0
  4110.     Dc.l    0
  4111.     Dc.l    s_facel
  4112.     Dc.l    0
  4113.     Dc.l    s_txlst
  4114.     Dc.l    s_S_dsarr
  4115.  
  4116. s_S_obj2
  4117.     Dc.w    s_S_POINTS-1, s_S_FACES-1
  4118.     Dc.l    s_pts,s_S_ptrot,s_S_ptpersp
  4119.     Dc.w    0,0,0, 0,128,0
  4120.     Dc.l    0
  4121.     Dc.l    s_facel
  4122.     Dc.l    0
  4123.     Dc.l    s_txlst
  4124.     Dc.l    s_S_dsarr
  4125.  
  4126. s_S_obj3
  4127.     Dc.w    s_S_POINTS-1, s_S_FACES-1
  4128.     Dc.l    s_pts,s_S_ptrot,s_S_ptpersp
  4129.     Dc.w    0,0,0, 0,256,0
  4130.     Dc.l    0
  4131.     Dc.l    s_facel
  4132.     Dc.l    0
  4133.     Dc.l    s_txlst
  4134.     Dc.l    s_S_dsarr
  4135.  
  4136. s_S_obj4
  4137.     Dc.w    s_S_POINTS-1, s_S_FACES-1
  4138.     Dc.l    s_pts,s_S_ptrot,s_S_ptpersp
  4139.     Dc.w    0,0,0, 0,384,0
  4140.     Dc.l    0
  4141.     Dc.l    s_facel
  4142.     Dc.l    0
  4143.     Dc.l    s_txlst
  4144.     Dc.l    s_S_dsarr
  4145.  
  4146.  
  4147.  
  4148. s_pts    Dc.w    $0014,$FFEC,$0000, $0014,$0014,$0000, $FFEC,$0014,$0000
  4149.     Dc.w    $FFEC,$FFEC,$0000, $0000,$0000,$0028
  4150.  
  4151. s_facel    Dc.l    .f0,.f1,.f2,.f3,.f4
  4152.  
  4153. .f0    Dc.l    s_txr1
  4154.     Dc.w    0,0, 1,1, 2,2, 3,3, 0,0, -1
  4155. .f1    Dc.l    s_txr1
  4156.     Dc.w    4,4, 0,0, 3,3, 4,4, -1
  4157. .f2    Dc.l    s_txr1+64
  4158.     Dc.w    4,4, 3,3, 2,2, 4,4, -1
  4159. .f3    Dc.l    s_txr1
  4160.     Dc.w    4,4, 2,2, 1,1, 4,4, -1
  4161. .f4    Dc.l    s_txr1+64
  4162.     Dc.w    4,4, 1,1, 0,0, 4,4, -1
  4163.  
  4164. s_txlst    Dc.w    0,1, 63,1, 63,62, 0,62, 31,31
  4165.  
  4166.  
  4167.  
  4168.  
  4169.     ; -- This just gives a 4-point star definition --
  4170.     ; -- for the surrounding pyramids and 'N'      --
  4171.  
  4172. s_Star    Dc.w    4,0
  4173.     Dc.l    s_S_pts, s_Star_ptr, s_Star_ptp
  4174.     Dc.w    0,0,0, 0,0,0
  4175.     Dc.l    0
  4176.     Dc.l    0
  4177.     Dc.l    0
  4178.     Dc.l    0
  4179.     Dc.l    0
  4180.  
  4181. s_S_pts    Dc.w    0,0,0, 0,0,20, 20,0,0, 0,0,-20, -20,0,0
  4182.  
  4183.  
  4184.  
  4185.  
  4186.  
  4187.  
  4188.     section    'Fast',BSS
  4189.  
  4190. s_Chunky    Ds.b    scene_SCR_WH
  4191.  
  4192. s_Background    Ds.b    scene_SCR_WH
  4193.  
  4194. s_ptr        Ds.w    3*s_N_POINTS
  4195. s_ptp        Ds.w    2*s_N_POINTS
  4196. s_dsarr        Ds.w    2*s_N_FACES
  4197.  
  4198. s_S_ptrot    Ds.w    3*s_S_POINTS
  4199. s_S_ptpersp    Ds.w    2*s_S_POINTS
  4200. s_S_dsarr    Ds.w    2*s_S_FACES
  4201.  
  4202. s_Star_ptr    Ds.w    3*5
  4203. s_Star_ptp    Ds.w    2*5
  4204. s_Star_dsarr    Ds.w    2*5
  4205.  
  4206. s_temp64    Ds.b    64*64            ; Temp space for txr calc
  4207. s_txr1        Ds.b    256*64            ; The actual textures (4)
  4208.  
  4209.  
  4210.  
  4211.  
  4212.     ; *****************************
  4213.     ; ***                       ***
  4214.     ; ***  C o p p e r L i s t  ***
  4215.     ; ***                       ***
  4216.     ; *****************************
  4217.  
  4218.     section    'CLIST',DATA_C
  4219.  
  4220. s_CLIST        Dc.w    BPL0PTH,0,BPL0PTL,0,BPL1PTH,0,BPL1PTL,0
  4221.         Dc.w    BPL2PTH,0,BPL2PTL,0,BPL3PTH,0,BPL3PTL,0
  4222.         Dc.w    BPL4PTH,0,BPL4PTL,0,BPL5PTH,0,BPL5PTL,0
  4223.         Dc.w    BPL6PTH,0,BPL6PTL,0,BPL7PTH,0,BPL7PTL,0
  4224.  
  4225.         Dc.w    BPLCON0,$0210,BPLCON1,0,BPLCON2,0,FMODE,$0003
  4226.         Dc.w    DIWSTRT,$4881,DIWSTOP,$10C1,DDFSTRT,$38,DDFSTOP,$A0
  4227.         Dc.w    BPL1MOD,0,BPL2MOD,0
  4228.  
  4229. s_CLIST_Pal    ColBank    4            ; 128 colours
  4230.  
  4231.         Dc.w    $FFFF,$FFFE
  4232.  
  4233.