home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 100.lha / stars68.asm < prev    next >
Assembly Source File  |  1986-11-20  |  14KB  |  547 lines

  1. *  stars.asm - by A. Tuline
  2. *  revised for the Gibbs A68k Assembler by Tom Eshelman
  3. *  This assembler demands labels in column 1 - period!
  4.  
  5.    INCLUDE "exec/types.i"
  6.    INCLUDE "intuition/intuition.i"
  7.    INCLUDE "graphics/rastport.i"
  8.    INCLUDE "exec/ports.i"
  9.  
  10. * Macros
  11.  
  12. SYS      MACRO
  13.            JSR      _LVO\1
  14.          ENDM
  15.  
  16.  
  17. * exec calls
  18.  
  19.          EXTERN_LIB  OpenLibrary             ; (libName,version)(A1,D0)
  20.          EXTERN_LIB  CloseLibrary            ; (libbNode)(A1)
  21.          EXTERN_LIB  GetMsg                  ; (msgPort)(D0)
  22.          EXTERN_LIB  ReplyMsg                ; (message)(A1)
  23.          EXTERN_LIB  Wait                    ; (signalSet)(D0)
  24.  
  25. * intuition calls
  26.  
  27.          EXTERN_LIB  OpenWindow              ; (newWindow)(A0)
  28.          EXTERN_LIB  CloseWindow             ; (Window)(A0)
  29.          EXTERN_LIB  OpenScreen              ; (newScreen)(A0)
  30.          EXTERN_LIB  CloseScreen             ; (Screen)(A0)
  31.          EXTERN_LIB  ShowTitle               ; (Screen,ShowIt)(A0,D0)
  32.  
  33. * graphics calls
  34.  
  35.          EXTERN_LIB  Draw                    ; (rp,x,y)(A1,D0,D1)
  36.          EXTERN_LIB  Move                    ; (rp,x,y)(A1,D0,D1)
  37.          EXTERN_LIB  ReadPixel               ; (rp,x,y)(A1,D0,D1)
  38.          EXTERN_LIB  SetAPen                 ; (rp,pennum)(A1,D0)
  39.          EXTERN_LIB  SetDrMd                 ; (rp,drawmode)(A1,D0)
  40.          EXTERN_LIB  SetRGB4       ;(viewPort,register,r,g,b)(A0,D0/D1/D2/D3)
  41.          EXTERN_LIB  WritePixel              ; (rp,x,y)(A1,D0,D1)
  42.          EXTERN_LIB  SetRast                 ; (rp,pennum)(A1,D0)
  43.  
  44. * externally defined variables
  45.  
  46.          XREF     _AbsExecBase            ; see amiga.lib
  47.  
  48.  
  49.  
  50. ******************************
  51. *  Start of Code             *
  52. ******************************
  53.  
  54. startup:
  55.  
  56.       move.l     a7,savesp             ;save present stack ptr for return.
  57.  
  58.       movea.l   _AbsExecBase,a6        ;move into Sysbase
  59.       lea.l      IntLibArgs,a1         ;args into a1
  60.       moveq      #0,d0                 ;any version 
  61.       SYS        OpenLibrary(a6)       ;open Intuition Library
  62.       move.l     d0,IntBase            ;save this library base
  63.       beq        openerr
  64.  
  65. * Open Graphics Library
  66.  
  67.       movea.l   _AbsExecBase,a6
  68.       lea.l      GrafLibArgs,a1
  69.       moveq      #0,d0
  70.       SYS        OpenLibrary(a6)
  71.       move.l     d0,GrafBase           ;save this library base too.
  72.       beq        openerr
  73.  
  74. * Open a screen
  75.  
  76.  
  77.       movea.l  IntBase,a6
  78.       lea      screenvars,a0
  79.       SYS      OpenScreen(a6)
  80.       move.l   d0,newscreenptr          ;save the ptr to our screen
  81.       beq      openerr
  82.  
  83.       add.l    #sc_RastPort,d0          ;find rastport offset
  84.       move.l   d0,myraster              ;save a pointer to the rastport
  85.       sub.l    #sc_RastPort,d0          ;return to the screen ptr.
  86.       add.l    #sc_ViewPort,d0          ;find viewport offset
  87.       move.l   d0,myview                ;save pointer to the viewport
  88.  
  89.       movea.l  IntBase,a6               ;hide the screentitle routine
  90.       move.l   newscreenptr,a0
  91.       move.l   #0,d0                    ;cause it to be hidden
  92.       SYS      ShowTitle(a6)
  93.  
  94. * Open a window
  95.  
  96.       movea.l  IntBase,a6
  97.       lea      windowvars,a0
  98.       SYS      OpenWindow(a6)
  99.       move.l   d0,newwindowptr          ;save ptr to our new window
  100.       beq      openerr
  101.  
  102.  
  103. setcolours:
  104.  
  105. * Set the background to black and the other to blue.
  106.  
  107.       movea.l   GrafBase,a6
  108.       movea.l   myview,a0
  109.       move.l    #0,d0                   ; set color register 0 to:
  110.       moveq     #0,d1                   ; red   +
  111.       moveq     #0,d2                   ; green +----> black
  112.       moveq     #0,d3                   ; blue  +
  113.       SYS       SetRGB4(a6)
  114.  
  115.       move.l    GrafBase,a6
  116.       move.l    myview,a0
  117.       move.l    #1,d0                    ; set color register 1 to:
  118.       move.b    #10,d1                   ; red   +
  119.       move.b    #10,d2                   ; green +----> blue
  120.       move.b    #15,d3                   ; blue  +
  121.       SYS       SetRGB4(a6)
  122.  
  123.  
  124. * Set the drawing mode
  125.  
  126.       movea.l  GrafBase,a6
  127.       movea.l  myraster,a1
  128.       move.b   RP_JAM1,d0
  129.       SYS      SetDrMd(a6)
  130.  
  131. * At this point, at least the screen and window are set up well enough
  132. * to work without too much fuss.  TJE  1/12/88
  133. * I don't like unusual jsr calls.   Hence, the revision.
  134.  
  135.  
  136. starinstall:
  137.  
  138.       lea      pont,a3              ;an array of 1024 data bytes
  139.       lea      pontend,a4           ;a4 holds address of 1 byte of data
  140.  
  141.  
  142. redostars:
  143.  
  144.       jsr      starun
  145.       jsr      getmsg                  ; d0 has pointer to message
  146. ;      jsr      replymsg
  147.       tst.l    d0
  148.       beq      redostars               ; jump back if no message pointer
  149.  
  150.       move.l   d0,a0
  151.       move.l   im_Class(a0),d0
  152.       andi.l   #CLOSEWINDOW,d0
  153.       beq      redostars               ; jump back if not CLOSEWINDOW msg
  154.  
  155. *         jsr      replymsg                ; should be right after getmsg
  156.  
  157. stopprog:
  158.  
  159.       jsr      closeall
  160.  
  161. exitprog:
  162.  
  163.       movea.l   savesp,a7
  164.       rts
  165.  
  166. **********************************
  167. *  End of program. 'main'.
  168. **********************************
  169.  
  170.  
  171. newstars:
  172.  
  173.          jsr      point_maker
  174.          add.w    #lenth,a3
  175.          cmpa.l   a4,a3
  176.          blt      newstars                ;infinite loop.
  177.  
  178.          move.b   #1,speed                ; initialize various parmeters
  179.          move.w   #160*64,x_centre
  180.          move.w   #99*64,y_centre
  181.          move.w   #0,x_abs
  182.          move.w   #0,y_abs
  183.  
  184.          rts
  185.  
  186.  
  187. starun:
  188.       lea      pont,a3
  189.       lea      pontend,a4
  190.  
  191. starup:
  192.       move.b   speed,d4
  193.       move.w   xold_st(a3),d2
  194.       move.w   d2,d5
  195.       sub.w    x_centre,d5
  196.       asr.w    d4,d5                   ; shift delx by speed factor
  197.  
  198.       move.b   dx_st(a3),d4
  199.       asr.w    d4,d5                   ; distance across factor
  200.  
  201.       add.w    d5,d2
  202.       sub.w    x_abs,d2
  203.       sub.w    x_abs,d2
  204.  
  205.       cmp.w    #x_rang,d2
  206.       bcc      str_out_rang
  207.       cmp.w    #xlower,d2
  208.       bls      str_out_rang
  209.  
  210.       move.w   d2,xnew_st(a3)
  211.  
  212.       move.b   speed,d4
  213.  
  214.       move.w   yold_st(a3),d2          ; d2 <- yold
  215.       move.w   d2,d5
  216.       sub.w    y_centre,d5
  217.       asr.w    d4,d5
  218.  
  219.       move.b   dx_st(a3),d4
  220.       asr.w    d4,d5
  221.  
  222.       add.w    d5,d2
  223.       sub.w    y_abs,d2
  224.       sub.w    y_abs,d2
  225.  
  226.       cmp.w    #y_rang,d2
  227.       bcc      str_out_rang
  228.       cmp.w    #ylower,d2
  229.       bls      str_out_rang
  230.  
  231.       move.w   d2,ynew_st(a3)
  232.  
  233.       move.w   xold_st(a3),d0          ; preset old point
  234.       move.w   yold_st(a3),d1
  235.       bsr      preset
  236.  
  237.       move.w   xnew_st(a3),d0          ; pset new point
  238.       move.w   ynew_st(a3),d1
  239.       bsr      pset
  240.  
  241.       move.w   xnew_st(a3),xold_st(a3)
  242.       move.w   ynew_st(a3),yold_st(a3)
  243.  
  244.       bra      next_star
  245.  
  246.  
  247. str_out_rang:
  248.  
  249.          move.w   xold_st(a3),d0
  250.          move.w   yold_st(a3),d1
  251.          bsr      preset
  252.          bsr      point_maker
  253.  
  254. next_star:
  255.          add.w    #lenth,a3
  256.          cmpa.l    a4,a3
  257.          blt      starup
  258.  
  259. starend:
  260.          rts
  261.  
  262.  
  263. preset:
  264.  
  265.          move.l   d0,d3
  266.          move.l   d1,d4
  267.          move.b   #0,d0                   ; 0 = black
  268.          move.l   myraster,a1
  269.          move.l   GrafBase,a6
  270.          SYS      SetAPen(a6)
  271.          move.l   d3,d0
  272.          move.l   d4,d1
  273.  
  274.          lsr.w    #6,d0
  275.          lsr.w    #6,d1
  276.          and.l    #$ffff,d0
  277.          and.l    #$ffff,d1
  278.  
  279.          SYS      WritePixel(a6)
  280.  
  281.          rts
  282.  
  283.  
  284. pset:
  285.  
  286.          move.l   d0,d3
  287.          move.l   d1,d4
  288.          move.b   #1,d0                   ; 1 = white
  289.          move.l   GrafBase,a6
  290.          move.l   myraster,a1
  291.          SYS      SetAPen(a6)
  292.          move.l   d3,d0
  293.          move.l   d4,d1
  294.  
  295.          lsr.l    #6,d0
  296.          lsr.l    #6,d1
  297.          and.l    #$ffff,d0
  298.          and.l    #$ffff,d1
  299.  
  300.          SYS      WritePixel(a6)
  301.  
  302.          rts
  303.  
  304.  
  305.  
  306. point_maker:
  307.  
  308.          jsr      rando                   ; x values
  309.          move.w   d0,d2
  310.          and.w    #x_and,d0
  311.          add.w    #xlower,d0
  312.          move.w   d0,xold_st(a3)
  313.  
  314.          jsr      rando                   ; y values
  315.          and.w    #y_and,d0
  316.          add.w    #ylower,d0
  317.          cmp.w    #y_rang,d0
  318.          bls      rep_y
  319.          asr.w    #1,d0
  320.  
  321. rep_y:
  322.          move.w   d0,yold_st(a3)
  323.  
  324.          and.b    #3,d2                   ; side distance factor
  325.          add.b    #1,d2
  326.          move.b   d2,dx_st(a3)
  327.          rts
  328.  
  329.  
  330.  
  331. * Random number generator with d0 returning the number (others saved)
  332.  
  333. randomize:
  334.          move.w   #91,d0                  ; the seed
  335.          move.w   d0,rndsav
  336.          move.b   #91,d0
  337.          move.b   d0,rndlow
  338.          rts
  339.  
  340. rando:
  341.          move.l   a0,-(sp)
  342.          move.l   d1,-(sp)
  343.  
  344.          lea      rndsav,a0
  345.          move.w   #$4321,d0
  346.          mulu     (a0),d0
  347.          add.l    #1,d0
  348.          move.w   d0,(a0)
  349.          move.b   (a0),d1
  350.          eor.b    d0,d1
  351.          move.b   d1,rndlow
  352.  
  353.          move.l   (sp)+,d1
  354.          move.l   (sp)+,a0
  355.          rts
  356.  
  357.  
  358.  
  359. * get message to see if user closed the window
  360.  
  361. getmsg:
  362.          movea.l   _AbsExecBase,a6
  363.          movea.l   newwindowptr,a0
  364.          movea.l   wd_UserPort(a0),a0
  365.          SYS      GetMsg(a6)
  366.          rts
  367.  
  368.  
  369.  
  370. * reply to the current message
  371.  
  372. replymsg:
  373.          movea.l   d0,a1
  374.          movea.l   _AbsExecBase,a6
  375.          SYS      ReplyMsg(a6)
  376.          rts
  377.  
  378.  
  379.  
  380. * Wait for user to close the window
  381.  
  382. waitforbutton:
  383.          move.l   _AbsExecBase,a6
  384.          move.l   newwindowptr,a0
  385.          move.l   wd_UserPort(a0),a1
  386.          move.l   #0,d3
  387.          move.b   MP_SIGBIT(a1),d3
  388.          move.l   #1,d0
  389.          asl.l    d3,d0
  390.          SYS      Wait(a6)
  391.  
  392.          rts
  393.  
  394.  
  395. * Close a window
  396.  
  397. closeall:
  398.          move.l   IntBase,a6
  399.          move.l   newwindowptr,a0
  400.          SYS      CloseWindow(a6)
  401.  
  402.  
  403. * Close a screen
  404.  
  405.          move.l   IntBase,a6
  406.          move.l   newscreenptr,a0
  407.          SYS      CloseScreen(a6)
  408.  
  409.  
  410. * Close the graphics library
  411.  
  412.          move.l      GrafBase,a1
  413.          move.l      _AbsExecBase,a6
  414.          SYS         CloseLibrary(a6)
  415.  
  416.  
  417. *  Close the intuition library
  418.  
  419.          move.l   IntBase,a1
  420.          move.l   _AbsExecBase,a6
  421.          SYS      CloseLibrary(a6)
  422.  
  423.          rts
  424.  
  425.  
  426. openerr:
  427.          moveq    #-1,d1                  ; return code=bad
  428.          move.l   d1,d0
  429.          bra      exitprog
  430.  
  431.  
  432.  
  433. * Data section.  I prefer zeroing these things out when practical in the
  434. * style of Jake Commander.  I also found you avoid pitfalls by NOT using
  435. * SECTION directives needlessly.  With small code, you only ask for trouble.
  436.  
  437. savesp         dc.l  0
  438.  
  439. IntBase        dc.l  0          ; base addr. for intuit. calls
  440. GrafBase       dc.l  0          ; base addr. for graphics calls
  441.  
  442. myraster       dc.l  0          ; pointer to new screen raster
  443. myview         dc.l  0          ; pointer to new screen viewport
  444.  
  445. newwindowptr   dc.l  0          ; pointer to new window
  446. newscreenptr   dc.l  0          ; pointer to new screen
  447.  
  448.  
  449. windowvars
  450.                dc.w  0                    ; nw_LeftEdge
  451.                dc.w  0                    ; nw_TopEdge
  452.                dc.w  320                  ; nw_Width
  453.                dc.w  200                  ; nw_Height
  454.                dc.b  0                    ; nw_DetailPen
  455.                dc.b  1                    ; nw_BlockPen
  456.                dc.l  IDCMP_FLAGS          ; nw_IDCMPFlags
  457.                dc.l  ANDREWSGADGETS       ; nw_FLAGS
  458.                dc.l  0                    ; nw_FirstGadget
  459.                dc.l  0                    ; nw_CheckMark
  460.                dc.l  andrews_window       ; nw_Title
  461.                dc.l  0                    ; nw_Screen
  462.                dc.l  0                    ; nw_BitMap
  463.                dc.w  0                    ; nw_Minwidth
  464.                dc.w  0                    ; nw_MinHeight
  465.                dc.w  320                  ; nw_MaxWidth
  466.                dc.w  200                  ; nw_MaxHeight
  467.                dc.w  WBENCHSCREEN         ; nw_Type
  468.  
  469.  
  470.  
  471. screenvars
  472.                dc.w  0                    ; ns_LeftEdge
  473.                dc.w  0                    ; ns_TopEdge
  474.                dc.w  320                  ; ns_Width
  475.                dc.w  200                  ; ns_Height
  476.                dc.w  3                    ; ns_Depth
  477.                dc.b  3                    ; ns_DetailPen
  478.                dc.b  1                    ; ns_BlockPen
  479.                dc.w  0                    ; ns_ViewModes
  480.                dc.w  WBENCHSCREEN         ; ns_Type
  481.                dc.l  0                    ; ns_Font
  482.                dc.l  andrews_screen       ; ns_DefaultTitle
  483.                dc.l  0                    ; ns_Gadgets
  484.                dc.l  0                    ; ns_CustomBitMap
  485.  
  486. *  Library definitions
  487.  
  488. IntLibArgs     dc.b    'intuition.library',0
  489.  
  490. GrafLibArgs    dc.b     'graphics.library',0
  491.  
  492.  
  493. *  Andrew's Title definitions
  494.  
  495. andrews_window    dc.b   '3D Stars V 1.1',0
  496.  
  497. andrews_screen    dc.b   'Andrew',39,'s Screen',0
  498.  
  499. numb           equ   $40
  500. lenth          equ   $10
  501.  
  502. xnew_st        equ   0
  503. ynew_st        equ   2
  504. dx_st          equ   4
  505. dy_st          equ   6
  506. xold_st        equ   8
  507. yold_st        equ   $a
  508. viaddr         equ   $c
  509. vidata         equ   $e
  510.  
  511. x_and          equ   254*$40
  512. x_rang         equ   318*64
  513. zero           equ   0
  514. y_and          equ   254*$40
  515. y_rang         equ   197*64
  516.  
  517. xlower         equ   3*$40
  518. ylower         equ   11*$40
  519.  
  520. ANDREWSGADGETS     equ  ACTIVATE!WINDOWCLOSE!BACKDROP
  521. IDCMP_FLAGS        equ  CLOSEWINDOW!RAWKEY
  522.  
  523.  
  524.  
  525. rndsav         ds.w  2
  526. rndlow         ds.b  4
  527.  
  528.  
  529. * star variables
  530.  
  531. speed          ds.b  2
  532.  
  533. pont           ds.b  numb*lenth   ;intended to be an array of 1024 bytes
  534.  
  535. pontend        ds.b  1            ;allocate one byte. Name its spot pontend
  536.  
  537. x_centre       ds.w  1
  538. y_centre       ds.w  1
  539. x_abs          ds.w  1
  540. y_abs          ds.w  1
  541.  
  542.  
  543.  
  544.       END      ; Boy, these assembler types have no flair.  How 'bout:
  545.  
  546.                    ; Th- Th- Th- Th-  That's All Folks!!          -TJE
  547.