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

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