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

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