home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Demos / Stars8.s < prev    next >
Encoding:
Text File  |  1997-02-16  |  7.4 KB  |  331 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;3D STARFIELD 8
  3. ;--------------
  4. ;Same as the first starfield demo but runs in 8 colours.  Default is 500
  5. ;stars which runs fine on my A1200+Fast - but try 5000 stars or more for a
  6. ;real visual experience :-)
  7.  
  8.     INCDIR    "INCLUDES:"
  9.     INCLUDE    "exec/exec_lib.i"
  10.     INCLUDE    "games/games_lib.i"
  11.     INCLUDE    "games/games.i"
  12.  
  13. CALL    MACRO
  14.     jsr    _LVO\1(a6)
  15.     ENDM
  16.  
  17. NSTARS    =    500    ;Number of stars
  18.  
  19. XSPEED    =    -4
  20. YSPEED    =    6
  21. ZSPEED    =    2
  22.  
  23. SCR_HEIGHT =    256
  24. SCR_WIDTH =    320
  25.  
  26.     SECTION    "Stars",CODE
  27.  
  28. ;==========================================================================;
  29. ;                             INITIALISE DEMO
  30. ;==========================================================================;
  31.  
  32. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  33.     move.l    ($4).w,a6
  34.     lea    GMS_Name(pc),a1
  35.     moveq    #$00,d0
  36.     CALL    OpenLibrary
  37.     move.l    d0,GMS_Base
  38.     beq.s    .Error_GMS
  39.  
  40.     move.l    GMS_Base(pc),a6
  41.     sub.l    a0,a0
  42.     CALL    SetUserPrefs
  43.  
  44.     lea    Screen(pc),a0
  45.     CALL    AddScreen
  46.     tst.l    d0
  47.     bne.s    .Error_Screen
  48.  
  49.     CALL    ShowScreen
  50.  
  51.     bsr.s    Main
  52.  
  53. .ReturnToDOS:
  54.     move.l    GMS_Base(pc),a6
  55.     lea    Screen(pc),a0
  56.     CALL    DeleteScreen
  57. .Error_Screen
  58.     move.l    GMS_Base(pc),a1
  59.     move.l    ($4).w,a6
  60.     CALL    CloseLibrary
  61. .Error_GMS
  62.     MOVEM.L    (SP)+,A0-A6/D1-D7
  63.     moveq    #$00,d0
  64.     rts
  65.  
  66. ;==========================================================================;
  67. ;
  68. ;==========================================================================;
  69.  
  70.     ;Randomize star coordinates
  71.  
  72. Main:    lea    StarCoords,a0    ;a0 = Ptr to star co-ordinates.
  73.     move.w    #NSTARS-1,d7
  74. .loop1    move.w    #8192,d1
  75.     CALL    SlowRandom
  76.     move.w    d0,(a0)+
  77.     CALL    SlowRandom
  78.     move.w    d0,(a0)+
  79.     CALL    SlowRandom
  80.     move.w    d0,(a0)+
  81.     dbra    d7,.loop1
  82.  
  83.     ;Construct perspective table
  84.  
  85.     lea    PersTable,a0    ;a0 = ptr to perspective table.
  86.     moveq    #0,d1    ;d1 = Starting at 0.
  87. .loop2    move.l    #$95FFFF,d2    ;d2 = $95FFFF
  88.     move.l    d1,d3    ;d3 = d1
  89.     add.w    #300,d3    ;d3 = ++300
  90.     divu    d3,d2    ;d2 = ($95ffff)/d3
  91.     move.w    d2,(a0)+    ;a0 = d2+
  92.     addq.w    #1,d1    ;d1 = ++1
  93.     cmp.w    #8192,d1    ;d1 = Equal to 8192?
  94.     bne.s    .loop2
  95.  
  96.     ;Construct plot tables for fast drawing.
  97.  
  98.     lea    PlotXTable,a0    ;a0 = X table - byte positions.
  99.     lea    PlotBTable,a1    ;a1 = Bit table (X related).
  100.     lea    PlotYTable,a2    ;a2 = Y table - line position.
  101.     moveq    #0,d0    ;d0 = 00
  102. .loop3    move.w    d0,d1    ;d1 = d0
  103.     lsr.w    #3,d1    ;d1 = (d0)<<3
  104.     move.w    d1,(a0)+    ;a0 = d1+
  105.  
  106.     move.w    d0,d1    ;d1 = d0
  107.     eor.w    #$FFFF,d1    ;d1 = (d0) eor $ffff
  108.     and.w    #%00000111,d1    ;d1 = &%00000111
  109.     move.w    d1,(a1)+    ;a1 = BitSet++
  110.  
  111.     cmp.w    #SCR_HEIGHT,d0    ;Write out the Y values for the
  112.     bge.s    .plot2    ;table.
  113.     move.w    d0,d1    ;d1 = Line Number.
  114.     mulu    #120,d1    ;d1 = (LineNumber)*80
  115.     move.w    d1,(a2)+    ;a2 = (LineNumber*80)++
  116.  
  117. .plot2    addq.w    #1,d0
  118.     cmp.w    #SCR_WIDTH,d0
  119.     bne.s    .loop3
  120.  
  121. ;==========================================================================;
  122. ;                                MAIN LOOP
  123. ;==========================================================================;
  124.  
  125. MainLoop:
  126.     move.l    GMS_Base(pc),a6
  127.     CALL    WaitSVBL
  128.  
  129.     lea    Screen(pc),a0
  130.     CALL    SwapBuffers
  131.  
  132. ;==========================================================================;
  133. ;                             STAR ANIMATION
  134. ;==========================================================================;
  135.  
  136.     movem.w    StarXPos(pc),d0/d1/d2    ;MV = d0/d1/d2 = XPos/YPos/ZPos
  137.     add.w    #XSPEED,d0    ;d0 = (StarXPos)+XSPEED
  138.     add.w    #YSPEED,d1    ;d1 = (StarYPos)+YSPEED
  139.     add.w    #ZSPEED,d2    ;d2 = (StarZPos)+ZSPEED
  140.     and.w    #%0000011111111111,d0
  141.     and.w    #%0000011111111111,d1
  142.     and.w    #%0000011111111111,d2
  143.     movem.w    d0/d1/d2,StarXPos
  144.  
  145.     lea    Sinus(pc),a0    ;a0 = Sinus table.
  146.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : X/Y/Z
  147.     add.w    (a0,d0.w),d3
  148.     add.w    (a0,d1.w),d4
  149.     add.w    (a0,d2.w),d5
  150.     movem.w    d3/d4/d5,StarXAdd
  151.  
  152. ;===========================================================================;
  153. ;                              SCREEN CLEAR
  154. ;===========================================================================;
  155. ;Let the blitter clear our 3rd screen while the CPU draws the stars.
  156.  
  157.     move.l    GMS_Base(pc),a6
  158.     lea    Screen(pc),a0
  159.     moveq    #BUFFER3,d0
  160.     CALL    ClrScreen
  161.  
  162. ;==========================================================================;
  163. ;                               DRAW STARS
  164. ;==========================================================================;
  165.  
  166.     lea    StarCoords,a0    ;Draw starfield
  167.     lea    PersTable,a1    ;a1 = Perspective table.
  168.     lea    PlotXTable,a2    ;a2 = X table.
  169.     lea    PlotBTable,a3    ;a3 = Bit table.
  170.     lea    PlotYTable,a4    ;a4 = Y table.
  171.  
  172.     move.l    Screen+GS_MemPtr2(pc),a6
  173.  
  174.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : ?
  175.     add.w    #4096,d3    ;d3 = ++4096
  176.     add.w    #4096,d4    ;d4 = ++4096
  177.  
  178.     move.w    #NSTARS-1,d7
  179.  
  180. .draw    movem.w    (a0)+,d0/d1/d2    ;MV = d0/d1/d2 : XPos/YPos/ZPos.
  181.     add.w    d3,d0    ;Increase XPos.
  182.     and.w    #8191,d0    ;d0 = And'd
  183.     sub.w    #4096,d0    ;d0 = --4096
  184.  
  185.     add.w    d4,d1    ;Y-movement
  186.     and.w    #8191,d1    ;d1 = And'd
  187.     sub.w    #4096,d1    ;d1 = --4096
  188.  
  189.     add.w    d5,d2    ;Z-movement
  190.     and.w    #8191,d2
  191.     add.w    d2,d2    ;d2 = *2 [word]
  192.     move.w    (a1,d2.w),d6    ;d6 = Read from Perspective table.
  193.  
  194.     muls    d6,d0    ;X-projection
  195.     swap    d0
  196.     add.w    #176,d0
  197.  
  198.     cmp.w    #SCR_WIDTH-1,d0
  199.     bhi    .nodraw
  200.     muls    d6,d1    ;Y-projection
  201.     swap    d1
  202.     add.w    #136,d1
  203.     cmp.w    #SCR_HEIGHT-1,d1
  204.     bhi    .nodraw
  205.  
  206.     add.w    d0,d0    ;d0 = *2 [word]
  207.     add.w    d1,d1    ;d1 = *2 [word]
  208.     move.w    (a4,d1.w),d6    ;d6 = Plot Y.
  209.     add.w    (a2,d0.w),d6    ;d6 = ++PlotX.
  210.     move.w    (a3,d0.w),d0    ;d0 = BitValue.
  211.  
  212. .draw1    cmp.w    #4000,d2    ;Now draw the star according to
  213.     bgt.s    .draw2    ;its position in the Z axis.
  214.     bset    d0,(a6,d6.w)
  215.     dbra    d7,.draw
  216.     bra.s    .done
  217.  
  218. .draw2    cmp.w    #6000,d2
  219.     bgt.s    .draw3
  220.     bset    d0,40(a6,d6.w)
  221.     dbra    d7,.draw
  222.     bra.s    .done
  223.  
  224. .draw3    cmp.w    #8000,d2
  225.     bgt.s    .draw4
  226.     bset    d0,(a6,d6.w)
  227.     bset    d0,40(a6,d6.w)
  228.     dbra    d7,.draw
  229.     bra.s    .done
  230.  
  231. .draw4    cmp.w    #10000,d2
  232.     bgt.s    .draw5
  233.     bset    d0,80(a6,d6.w)
  234.     dbra    d7,.draw
  235.     bra.s    .done
  236.  
  237. .draw5    cmp.w    #12000,d2
  238.     bgt.s    .draw6
  239.     bset    d0,(a6,d6.w)
  240.     bset    d0,80(a6,d6.w)
  241.     dbra    d7,.draw
  242.     bra.s    .done
  243.  
  244. .draw6    cmp.w    #14000,d2
  245.     bgt.s    .draw7
  246.     bset    d0,40(a6,d6.w)
  247.     bset    d0,80(a6,d6.w)
  248.     dbra    d7,.draw
  249.     bra.s    .done
  250.  
  251. .draw7    bset    d0,(a6,d6.w)
  252.     bset    d0,40(a6,d6.w)
  253.     bset    d0,80(a6,d6.w)
  254. .nodraw    dbra    d7,.draw
  255.  
  256. .done    move.l    GMS_Base(pc),a6
  257.     moveq    #JPORT1,d0    ;Read from port 1 (mouse).
  258.     moveq    #JT_ZBXY,d1
  259.     CALL    ReadJoyPort    ;Go get joystick status.
  260.     btst    #MB_LMB,d0
  261.     beq    MainLoop
  262.     rts
  263.  
  264. ;===========================================================================;
  265. ;                                  DATA
  266. ;===========================================================================;
  267.  
  268. GMS_Name:
  269.     dc.b    "games.library",0
  270.     even
  271. GMS_Base:
  272.     dc.l    0
  273.  
  274. AMT_PLANES =    3
  275.  
  276. Screen:    dc.l    GSV1,0
  277.     dc.l    0,0,0    ;Screen memory 1/2/3.
  278.     dc.l    0    ;Screen link.
  279.     dc.l    .Palette    ;Address of screen palette.
  280.     dc.l    0    ;Address of rasterlist.
  281.     dc.l    0    ;Amt of colours in palette.
  282.     dc.w    320,256    ;Screen Width and Height.
  283.     dc.w    0,0,0    ;Picture Width, ByteWidth, Height.
  284.     dc.w    AMT_PLANES    ;Amount of planes.
  285.     dc.w    0,0    ;X/Y screen offset.
  286.     dc.w    0,0    ;X/Y picture offset.
  287.     dc.l    TPLBUFFER    ;Special attributes.
  288.     dc.w    LORES|COL12BIT    ;Screen mode.
  289.     dc.w    ILBM    ;Screen type
  290.  
  291. .Palette
  292.     ; 124   124   124   124
  293.     dc.w    $0000,$0fff,$0ccc,$0999    ;%000, %100, %010, %110
  294.     dc.w    $0777,$0555,$0333,$0111    ;%001, %101, %011, %111
  295.  
  296. ;===========================================================================;
  297. ;                                STAR DATA
  298. ;===========================================================================;
  299.  
  300. StarXAdd
  301.     dc.w    33    ;Star stuff
  302. StarYAdd
  303.     dc.w    12
  304. StarZAdd
  305.     dc.w    -114
  306.  
  307. StarXPos
  308.     dc.w    0    ;Sinus positions
  309. StarYPos
  310.     dc.w    310
  311. StarZPos
  312.     dc.w    1280
  313.  
  314.     INCLUDE    "GAMESLIB:source/asm/demos/StarSinus.i"
  315.  
  316.     SECTION    Storage,BSS
  317.  
  318. StarCoords
  319.     ds.w    NSTARS*3    ;Star coordinates
  320.  
  321. PersTable
  322.     ds.w    8192    ;Perspective table
  323.  
  324. PlotXTable
  325.     ds.w    SCR_WIDTH    ;Plot tables
  326. PlotBTable
  327.     ds.w    SCR_WIDTH
  328. PlotYTable
  329.     ds.w    SCR_HEIGHT
  330.  
  331.