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

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