home *** CD-ROM | disk | FTP | other *** search
/ Global Amiga Experience / globalamigaexperience.iso / compressed / development / heliosdemodisk3.dms / heliosdemodisk3.adf / Source / SimpleAttHSprite.src < prev    next >
Text File  |  1995-01-24  |  16KB  |  566 lines

  1.  
  2.   \ ***********************************************************
  3.   \
  4.   \            SIMPLE ATTACHED HARDWARE SPRITE DEMO
  5.   \
  6.   \ ***********************************************************
  7.   \
  8.   \ This code demonstrates how to create a simple HeliOS single
  9.   \ playfield display and generate an attached hardware sprite.
  10.   \
  11.   \ An IFF file is loaded and displayed, and the hardware sprite
  12.   \ is moved around the screen using the mouse.
  13.   \
  14.   \ Press <Space> to quit when finished.
  15.   \
  16.   \ ***********************************************************
  17.  
  18.  
  19.   \ ***********************************************************
  20.   \ Re-initialise HeliOS dictionary to standard CORE vocabulary
  21.   \ ***********************************************************
  22.  
  23.   \ This should always be used at the start of any program which
  24.   \ is to be repeatedly recompiled.
  25.  
  26.   FORGET **CORE**
  27.  
  28.   \ *************************
  29.   \ Load include symbol files
  30.   \ *************************
  31.   \
  32.   \ These "include files" are pre-compiled (for speed) versions of the
  33.   \ Amiga includes and the Helios system includes.
  34.   \
  35.   \ Uncomment the lines below for standalone compilation, but otherwise
  36.   \ it is better to set these include files from the Helios Forth menus
  37.  
  38.   AMIGAINCLUDE Helios:Amiga_Include
  39.   USERINCLUDE  Helios:Helios_Include
  40.  
  41.   \ ****************************************
  42.   \ Create display imagery file name strings
  43.   \ ****************************************
  44.  
  45.   \ These files are ordinary IFF's (and may be "PowerPacked" if required)
  46.   \
  47.   \ The pictures here will be loaded into each of the display BitMaps.
  48.   \
  49.  
  50.   $CONSTANTL Slice1Pic $Helios:Source/Data/Pic2$
  51.  
  52.   \ **************************************
  53.   \ Create display configuration constants
  54.   \ **************************************
  55.   \
  56.   \ Collect all "display-specific" parameters here and generate "named"
  57.   \ constants which make references easier than using numeric values.
  58.   \
  59.   \ Collecting these together here makes it easier to adjust things at any
  60.   \ time without having to search source code to replace values individually.
  61.   \
  62.  
  63.  
  64.   256                      CONSTANT DisplayHeight      \ Full PAL display
  65.   320                      CONSTANT DisplayWidth       \ Lores display
  66.   44                       CONSTANT DisplayTopLine     \ Display start
  67.  
  68.   DisplayWidth             CONSTANT Slice1Width        \ Lores width
  69.   DisplayWidth 32 +        CONSTANT Slice1RasterWidth  \ Raster=screenwidth
  70.   DisplayHeight            CONSTANT Slice1Height       \ Slice height
  71.   DisplayHeight 32 +       CONSTANT Slice1RasterHeight \ Slice Raster=Displayheight
  72.   0                        CONSTANT Slice1Mode         \ Lores
  73.   3                        CONSTANT Slice1Planes       \ Slice bitplanes
  74.  
  75.   \ The calculation below takes the number of bitplanes and calculates
  76.   \ how many colours this represents.
  77.   \
  78.   \ One bitplane gives two colours.
  79.   \
  80.   \ Each additional bitplane multiplies the number of colours by two.
  81.   \
  82.   \ Performing a single LSL operation on any number multipies by 2, so we
  83.   \ have a quick method of multiplying by two for our colour calculation.
  84.   \
  85.   \ In this case, we need "2 to the power 3", which is 2*2*2=8.
  86.   \
  87.   \ e.g.                              2*2*2
  88.   \                                   ^ ^ ^
  89.   \                                   Total number of planes = 3
  90.   \
  91.   \
  92.   \ So, we take the first value two
  93.   \
  94.   \ e.g.                              2*2*2
  95.   \                                   ^
  96.   \                                  Initial start value of 2
  97.   \
  98.   \ and we now need to multiply it by two "the_number_of_planes minus_one"
  99.   \ more times.
  100.   \
  101.   \ e.g.                              2*2*2
  102.   \                                     ^ ^
  103.   \                                     Total planes minus one
  104.   \
  105.   \
  106.   \ So, Number of colours = 2 operated on by LSL NumberOfPlanes-1 times.
  107.   \
  108.  
  109.   2 Slice1Planes 1- LSL    CONSTANT Slice1Colours      \ A-slice colours
  110.  
  111.   \ ***********************
  112.   \ Error handling routines
  113.   \ ***********************
  114.  
  115.   \ This error handler allows all errors to be routed via a comprehensive
  116.   \ sequential closedown routine, which is associated with the HeliOS
  117.   \ system error handler word ERROR".
  118.   \
  119.   \ When ERROR" senses an error, it prints an associated error message
  120.   \ delimited by '"' characters, and then closes everything down using the
  121.   \ routine CLOSEDOWN below which you have supplied.
  122.   \
  123.   \ This simplifies errors checks to the use of a single word, ERROR", which
  124.   \ displays a text message and closes eveything down.
  125.   \
  126.  
  127.   0 VARIABLE (CLOSEDOWN)
  128.  
  129.   : ?CLOSEDOWNERROR
  130.  
  131.   IF
  132.     CR
  133.     CR
  134.     TYPE
  135.     CR
  136.     CR
  137.     ." Press <Space> to quit!"
  138.     CR
  139.     CR
  140.     WAITSPACE
  141.     (CLOSEDOWN) @EXECUTE
  142.     QUIT
  143.   ELSE
  144.     DDROP
  145.   THEN
  146.   ;
  147.  
  148.   LATESTCFA VARIABLE ERROR1
  149.  
  150.   \ ****************************************
  151.   \ Create display pointer storage variables
  152.   \ ****************************************
  153.  
  154.   \ Here we create a set of "pointers", initially set to a "null" value.
  155.   \
  156.   \ These "pointers" are set up as "long addresses" when various components
  157.   \ of the display system are allocated and initialised.
  158.   \
  159.   \ Note that initially these are all set to zero, and we clear them back
  160.   \ to zero when we de-allocate the associated resource.
  161.   \
  162.   \ These DPOINTERs are all initially set to "null" by using 'D0'.
  163.   \
  164.   \ When we allocate memory or Amiga system resources in the program at
  165.   \ run-time, these pointers are updated to contain the 32-bit address
  166.   \ of the newly allocated resource.
  167.   \
  168.   \ Subsequently the symbolic DPOINTER name can be used in your code to
  169.   \ represent the associated address.
  170.  
  171.   D0 DPOINTER Display1             \ Main Display structure pointer
  172.   D0 DPOINTER Slice1               \ Slice 1 Slice structure pointer
  173.  
  174.   D0 DPOINTER Slice1_ColorMap      \ Slice 1 ColourMap structure pointer
  175.  
  176.   D0 DPOINTER Slice1_RasInfo       \ Slice 1 RasInfo structure pointer
  177.  
  178.   D0 DPOINTER Slice1_BMap          \ Slice 1 BitMap structure pointer
  179.  
  180.   D0 DPOINTER Slice1_SliceControl  \ Slice 1 SliceControl structure pointer
  181.  
  182.   \ *************
  183.   \ Colour tables
  184.   \ *************
  185.  
  186.   \ Each colour entry requies 2 bytes of storage space
  187.  
  188.   CREATEL Slice1_ColorTable        \ Create longword pointer to table
  189.   Slice1Colours 2* 0 ALLOTFILL     \ Allocate Slice1 colours * 2 bytes
  190.  
  191.   \ ***********************************
  192.   \ Create Display and Slice structures
  193.   \ ***********************************
  194.  
  195.   \ This routine simply makes blank structures, which then need to be
  196.   \ initialised later (in the CREATE_DISPLAY routine).
  197.  
  198.   : CREATE_DSLICES
  199.  
  200.   DS_SIZEOF MAKESTRUCTURE Display1 MAKEPOINTER  \ Main "Display" structure
  201.  
  202.   SL_SIZEOF MAKESTRUCTURE Slice1   MAKEPOINTER  \ Display "Slice" structure
  203.   ;
  204.  
  205.   : FREE_DSLICES
  206.  
  207.   Slice1    DDUP FREEMEMORY   CLEARPOINTER
  208.   Display1  DDUP FREEMEMORY   CLEARPOINTER
  209.   ;
  210.  
  211.   \ ******************************
  212.   \ Create RasInfo structures etc.
  213.   \ ******************************
  214.  
  215.   : CREATE_RASINFO
  216.  
  217.   \ First allocate and initialise complete RasInfo structures.
  218.   \
  219.   \ This routine automatically allocates all BitMaps etc.
  220.   \
  221.  
  222.   Slice1RasterWidth Slice1RasterHeight Slice1Planes  OPENRASINFO
  223.   DFLAG0= ERROR" Fail: RasInfo1"
  224.   Slice1_RasInfo MAKEPOINTER
  225.  
  226.   \ Set invisible area "sprite margins" for slice RasInfo
  227.  
  228.   16              Slice1_RasInfo         ri_RxOffset    INDEX!L
  229.   16              Slice1_RasInfo         ri_RyOffset    INDEX!L
  230.  
  231.   \ Store BitMap pointer - often useful for later reference
  232.  
  233.   Slice1_RasInfo  ri_BitMap INDEXD@L Slice1_BMap MAKEPOINTER
  234.   ;
  235.  
  236.   : FREE_RASINFO
  237.  
  238.   Slice1_RasInfo   DDUP CLOSERASINFO   CLEARPOINTER
  239.   ;
  240.  
  241.   \ ********************************
  242.   \ Create Display/Slice Copperlists
  243.   \ ********************************
  244.  
  245.   \ This function builds the main display copperlist by:
  246.   \
  247.   \ 1. Initialising the Slice data structure
  248.   \ 2. Calling MAKECOPSTRIP for the slice, to build a copperlist
  249.   \ 3. Calling MAKEDISPLAY to build the master Display copperlist
  250.   \
  251.  
  252.   : CREATE_DISPLAY
  253.  
  254.   \ First initialise main display structures
  255.  
  256.   Slice1                           Display1  DS_Slice     INDEXD!L
  257.  
  258.   Slice1Width                      Slice1    SL_DWidth    INDEX!L
  259.   Slice1Height                     Slice1    SL_DHeight   INDEX!L
  260.   DisplayTopLine                   Slice1    SL_DyOffset  INDEX!L
  261.   Slice1_RasInfo                   Slice1    SL_RasInfo   INDEXD!L
  262.   Slice1_ColorMap                  Slice1    SL_ColorMap  INDEXD!L
  263.   Slice1Mode                       Slice1    SL_Modes     INDEX!L
  264.  
  265.   \ Generate copper list information for each of the display slices
  266.  
  267.   Slice1 MAKECOPSTRIP
  268.   D0= ERROR" Fail: Slice1CopStrip"
  269.  
  270.   \ Make display
  271.  
  272.   Display1 MAKEDISPLAY
  273.   D0= ERROR" Fail: Display1"
  274.   ;
  275.  
  276.   : FREE_DISPLAY
  277.  
  278.   Display1                 FREEDISPLAY
  279.   Slice1                   FREECOPSTRIP
  280.   ;
  281.  
  282.   \ ********************************************************
  283.   \ Create SliceControl structures for double buffered slice
  284.   \ ********************************************************
  285.  
  286.   \ SliceControl structures are used to control any slices which perform
  287.   \ mapping or scrolling functions, or which require double or triple
  288.   \ playfield buffering.
  289.   \
  290.   \ In this case we have one slice which does not scroll, is not mapped,
  291.   \ but IS double buffered.
  292.   \
  293.  
  294.   : CREATE_SLICECONTROL
  295.  
  296.   \ Make SliceControl for double buffered bitmap display
  297.  
  298.   Slice1  0 0 MAKESLICECONTROL
  299.   DFLAG0= ERROR" Fail: SliceControl1"
  300.   Slice1_SliceControl MAKEPOINTER
  301.  
  302.   \ Install slice controls into HeliOS display control system
  303.  
  304.   Slice1_SliceControl  INSTALLSLICECONTROL
  305.   ;
  306.  
  307.   : FREE_SLICECONTROL
  308.  
  309.   CLEARSLICECONTROLS
  310.   Slice1_SliceControl  CLOSESLICECONTROL
  311.   ;
  312.  
  313.   \ These routines load an IFF picture into supplied BitMap, and correctly
  314.   \ initialises the supplied ColorTable.
  315.   \
  316.   \ The ColorTable is then used to create an initialised ColorMap structure.
  317.   \
  318.  
  319.   : CREATE_IMAGERY
  320.  
  321.   Slice1_BMap
  322.   Slice1_ColorTable
  323.   Slice1Pic
  324.   10 2 DOSLIB                        \ Call to internal HeliOS library
  325.   10 <> ERROR" Fail: Slice1Pic"
  326.  
  327.   Slice1_ColorTable  Slice1Colours MAKECOLORMAP  \ Allocate ColourMap
  328.   DFLAG0= ERROR" Fail: Slice1ColorMap"
  329.   Slice1_ColorMap MAKEPOINTER
  330.   ;
  331.  
  332.   : FREE_IMAGERY
  333.  
  334.   Slice1_ColorMap  DDUP FREECOLORMAP  CLEARPOINTER
  335.   ;
  336.  
  337.   \ **************************************
  338.   \ Create attached hardware sprite images
  339.   \ **************************************
  340.  
  341.   \ These images use the standard Amiga hardware sprite convention with
  342.   \ respect to the way bits are interpreted as colour information.
  343.  
  344.   \ Note that we need two image definitions for an attached sprite
  345.  
  346.   CREATEL MyHSImage1
  347.  
  348.   16 ,                   \ Width
  349.   5  ,                   \ Height
  350.  
  351.   BIN
  352.  
  353.   0000111111110000 ,     \ Row 1 first colour definition bits
  354.   0000111111110000 ,     \ Row 1 second colour definition bits
  355.  
  356.   0000110000110000 ,     \ Row 2 first colour definition bits
  357.   0000110000110000 ,     \ Row 2 second colour definition bits
  358.  
  359.   0000100110010000 ,     \ Row 3 first colour definition bits
  360.   1110100000010111 ,     \ Row 3 second colour definition bits
  361.  
  362.   0000110000110000 ,     \ Row 4 first colour definition bits
  363.   0000110000110000 ,     \ Row 4 second colour definition bits
  364.  
  365.   0000111111110000 ,     \ Row 5 first colour definition bits
  366.   0000111111110000 ,     \ Row 5 second colour definition bits
  367.  
  368.   DECIMAL
  369.  
  370.   CREATEL MyHSImage2
  371.  
  372.   16 ,                   \ Width
  373.   5  ,                   \ Height
  374.  
  375.   BIN
  376.  
  377.   1110111111110111 ,     \ Row 1 first colour definition bits
  378.   0000110000110000 ,     \ Row 1 second colour definition bits
  379.  
  380.   0000110000110000 ,     \ Row 2 first colour definition bits
  381.   0000110000110000 ,     \ Row 2 second colour definition bits
  382.  
  383.   0000100110010000 ,     \ Row 3 first colour definition bits
  384.   1110100000010111 ,     \ Row 3 second colour definition bits
  385.  
  386.   0000110000110000 ,     \ Row 4 first colour definition bits
  387.   0000110000110000 ,     \ Row 4 second colour definition bits
  388.  
  389.   0000110000110000 ,     \ Row 5 first colour definition bits
  390.   1110111111110111 ,     \ Row 5 second colour definition bits
  391.  
  392.   DECIMAL
  393.  
  394.   \ ***********************************
  395.   \ Create hardware sprite colour table
  396.   \ ***********************************
  397.  
  398.   \ This colour table simply specifies a few arbitrary colours which we
  399.   \ will then set into colour registers 16 to 31
  400.  
  401.   CREATEL MySpriteColourTable
  402.  
  403.   HEX
  404.  
  405.   0000 ,  \ Colour 16
  406.   0FFF ,  \ Colour 17
  407.   0AA0 ,  \ Colour 18
  408.   000F ,  \ Colour 19
  409.   0F0F ,  \ Colour 20
  410.   000F ,  \ Colour 21
  411.   00F0 ,  \ Colour 22
  412.   0F00 ,  \ Colour 23
  413.   00FF ,  \ Colour 24
  414.   0004 ,  \ Colour 25
  415.   0040 ,  \ Colour 26
  416.   0400 ,  \ Colour 27
  417.   00F0 ,  \ Colour 28
  418.   0008 ,  \ Colour 29
  419.   0080 ,  \ Colour 30
  420.   0800 ,  \ Colour 31
  421.  
  422.   DECIMAL
  423.  
  424.   \ ***************************
  425.   \ Allocate two pointer stores
  426.   \ ***************************
  427.  
  428.   D0 DPOINTER  MyHSpriteData1
  429.   D0 DPOINTER  MyHSpriteData2
  430.  
  431.   \ **********************
  432.   \ Set up hardware sprite
  433.   \ **********************
  434.  
  435.   \ First we set sprite colours 16 to 31
  436.   \ Then we create two hardware sprite definition blocks
  437.   \ Then we install the two hardware sprite definitions
  438.  
  439.   : SetupHSprite
  440.  
  441.   Slice1 MySpriteColourTable 16 16 SETSLICECOLOURS
  442.  
  443.   1 1 MyHSImage1 MAKEHSPRITEBLOCK MyHSpriteData1 MAKEPOINTER
  444.   1 1 MyHSImage2 MAKEHSPRITEBLOCK MyHSpriteData2 MAKEPOINTER
  445.  
  446.   MyHSpriteData1 0 HSPRITE_INSTALL
  447.   MyHSpriteData2 1 HSPRITE_INSTALL
  448.   ;
  449.  
  450.   \ **************************
  451.   \ Close down hardware sprite
  452.   \ **************************
  453.  
  454.   \ First we remove the hardware sprites
  455.   \ Then we de-allocate the sprite definitions
  456.  
  457.   : FREE_HSPRITE
  458.  
  459.   MyHSpriteData1  HSPRITE_REMOVE
  460.   MyHSpriteData2  HSPRITE_REMOVE
  461.  
  462.   MyHSpriteData2  DDUP FREEHSPRITEBLOCK  CLEARPOINTER
  463.   MyHSpriteData1  DDUP FREEHSPRITEBLOCK  CLEARPOINTER
  464.   ;
  465.  
  466.   \ ********************************
  467.   \ Display and move hardware sprite
  468.   \ ********************************
  469.  
  470.   \ Switch on mouse position reporting
  471.   \ Switch off the HeliOS mouse pointer image
  472.   \ Repeatedly set the sprite to the current mouse pointer position
  473.  
  474.   : TestHSprite
  475.  
  476.   1 REPORTMOUSE
  477.   0 HELIOSMPOINTER
  478.  
  479.   BEGIN
  480.     0 MOUSEX MOUSEY 0 MyHSpriteData1 HSPRITE_PLACE  \ No attach flag on even
  481.     1 MOUSEX MOUSEY 0 MyHSpriteData2 HSPRITE_PLACE  \ Set attach flag on odd
  482.     ?TERMINAL 32 =
  483.   UNTIL
  484.   ;
  485.  
  486.  
  487.   \ *********************
  488.   \ Close down everything
  489.   \ *********************
  490.  
  491.   : CLOSEDOWN
  492.  
  493.   FREE_HSPRITE
  494.   FREE_SLICECONTROL
  495.   FREE_DISPLAY
  496.   FREE_IMAGERY
  497.   FREE_RASINFO
  498.   FREE_DSLICES
  499.   RESETERROR"
  500.   ;
  501.  
  502.   LATESTCFA (CLOSEDOWN) !
  503.  
  504.   : TestDisplay          \ Start of program
  505.  
  506.   SCRCLR
  507.  
  508.   CR
  509.   ."        **********************************************************"
  510.   CR 6 FPENSET
  511.   ."                   SIMPLE ATTACHED HARDWARE SPRITE DEMO"
  512.   CR 1 FPENSET
  513.   ."        **********************************************************"
  514.   CR
  515.   CR
  516.   ."        This code demonstrates how to create a simple HeliOS single"
  517.   CR
  518.   ."        playfield display and generate an attached hardware sprite."
  519.   CR
  520.   CR
  521.   ."        An IFF file is loaded and displayed, and the hardware"
  522.   CR
  523.   ."        sprite can then be moved around using the mouse."
  524.   CR
  525.   CR
  526.   ."        Press <Space> to quit demo."
  527.   CR
  528.   CR
  529.   ."        **********************************************************"
  530.   CR 6 FPENSET
  531.   ."                  Press <Space> or <L-Mouse> to see Demo          "
  532.   CR 1 FPENSET
  533.   ."        **********************************************************"
  534.   CR
  535.  
  536.   WAITSPACE
  537.  
  538.   SCRCLR
  539.  
  540.   ERROR1 SETERROR"       \ Redirect system errors to our routine ERROR1
  541.  
  542.   CREATE_DSLICES
  543.   CREATE_RASINFO
  544.   CREATE_IMAGERY
  545.   CREATE_DISPLAY
  546.   CREATE_SLICECONTROL
  547.  
  548.   SetupHSPrite
  549.  
  550.   HeliOS_On
  551.  
  552.   1 FrameRate !L
  553.  
  554.   Display1 SHOWDISPLAY
  555.  
  556.   TestHSprite
  557.  
  558.   HeliOS_Off
  559.  
  560.   0 REPORTMOUSE
  561.  
  562.   CLOSEDOWN
  563.   ;
  564.  
  565.   TestDisplay
  566.