home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI07.ARJ / ictari.07 / ASSEMBLY / SPRITES / SPRITES.TXT < prev   
Text File  |  1993-09-03  |  15KB  |  290 lines

  1.      SPRITE GENERATOR SYSTEM using the NEOCHROME-MASTER ART PROGRAM
  2.      ==============================================================
  3.  
  4.         by Peter Hibbs for the ICTARI USER group.  September 1993
  5.  
  6. INTRODUCTION.
  7.  
  8. This document details a method of generating colour sprites (of any size)
  9. using the NEOCHROME-MASTER art program  and  how  to  display them in the
  10. users program. The NEOCHROME-MASTER program is  a modified version of the
  11. original  NEOCHROME  art  program  from   ATARI   and  has  a  number  of
  12. improvements including a facility to  cut  out  a  large number of sprite
  13. objects from up to  10  Neochrome  pictures  and  store  them in a sprite
  14. object file which is then saved  back  to disk. Unfortunately, ATARI have
  15. banned the sale of this program for  copyright reasons (it is a pity they
  16. did not adopt it  as  the  official  version)  but  it  is probably still
  17. available from some sources. Although  the  original  version did have an
  18. option to save sprite objects (as source  code) it is not powerful enough
  19. to be that useful.
  20.  
  21. A number of other files and  programs  should be used in conjunction with
  22. this document, they are -
  23.  
  24.         SPRITE.S        Source code for the sprite display routines
  25.         SPR_INIT.DOC    Data sheet for the sprite initialisation S/R
  26.         M_SPRITE.DOC    Data sheet for the m_sprite S/R
  27.         S_SPRITE.DOC    Data sheet for the s_sprite S/R
  28.         GRIDLOCK.S      Source code for the sprite demo program
  29.         GRIDLOCK.PRG    Assembled version of the demo program
  30.         GRIDLOCK.OBJ    Sprite object file for the demo program
  31.         GRIDLOCK.NEO    Neochrome object definitions for the demo program
  32.         SPR_CHCK.DOC    Document file for sprite check program
  33.         SPR_CHCK.PRG    Sprite check program
  34.         SPR_CHCK.RSC    Resource file for SPR_CHCK program
  35.         SPRITES.TXT     This document
  36.  
  37. To write a program using sprites you should follow these steps -
  38.  
  39. 1. First plan out the program  and  the  number,  shape, size, etc of the
  40. sprites to be used. It is  easy  to  add sprites to the sprite definition
  41. picture file at a later stage but  it  can  save  a lot of hassle if some
  42. thought is given to how they are stored (see later for more info).
  43.  
  44. 2. Run the NEOCHROME-MASTER program  (I  use  version 2.10) and design or
  45. import the sprite images. If there are more sprites than can be fitted on
  46. one screen, use screens 1-9 as  necessary.  Screen 0 should be used first
  47. and the colour palette set  as  required, the SPR_CHCK program (described
  48. later) uses the screen 0 palette when displaying the sprites.
  49.  
  50. 3. Generate a sprite  object  file  using  the CUTTER facility (described
  51. later) and save the file  to  disk  using  the  name of the program being
  52. written, i.e. GRIDLOCK.OBJ.
  53.  
  54. 4. Write your  program  and  load  the  sprite  object  file  into memory
  55. somewhere near the start of the  program (see the SPR_INIT.DOC data sheet
  56. for more information).
  57.  
  58. 5. The program can  then  display  the  sprites  using the sprite display
  59. routines supplied.
  60.  
  61. SPRITE DESIGN.
  62.  
  63. There a number of points to observe when designing sprites and allocating
  64. colours to the colour palette.
  65.  
  66. 1. First set up  the  colour  palette.  Index  colour  0  (the one on the
  67. extreme left of the palette display)  is always regarded as 'transparent'
  68. by the sprite display routines and  must  not  be  used as a 'colour'. It
  69. would normally be set to black although  if  a sprite also uses black, it
  70. can be made any colour (say a  very  dark blue) so that black sprites can
  71. be seen. Even though index colour 0 is  shown as a colour, it will not be
  72. displayed within the user program. Note  that  if  black is required as a
  73. colour, it must be  set  up  on  another  index  colour  (index  No 1 for
  74. example). Index colour 15 should  normally  be  set  to  white (or a very
  75. light colour) so  that  the  SPR_CHCK  program  can  display  the palette
  76. correctly. If more than one screen  is  used to store sprites, the colour
  77. palettes on these should be the same as screen 0, as far as possible.
  78.  
  79. 2. Design the sprites  and  store  as  many  as  possible on each screen,
  80. especially if they are large or there  are  a large number or you may run
  81. out of screens. It is useful to number each sprite on screen (starting at
  82. 1) and to make a note  on  paper  of  the  number  of each sprite and its
  83. function for use when writing the program later.
  84.  
  85. When positioning the sprites on screen  the y co-ordinate is unimportant.
  86. The x co-ordinate of the left edge  of the sprite, however, should be set
  87. on a 16 pixel boundary. Each sprite  should be regarded as being an exact
  88. multiple of 16 pixels wide, for example  if  the visible area of a sprite
  89. is 40 pixels wide, it should be  regarded  as being 48 pixels wide (3x16)
  90. when placing other sprites near to  it.  When the sprite CUTTER option is
  91. used, the rectangle around the  sprite  must  be  a multiple of 16 pixels
  92. wide. This is due  to  a  small  bug  in NEOCHROME-MASTER which sometimes
  93. colours in  the  transparent  pixels  around  the  sprite  image  if this
  94. procedure is not observed. It is also  useful to draw a small 'corner' at
  95. the top left and bottom right  of  irregular  shaped sprites to assist in
  96. the cutting out  process  later.  See  the  GRIDLOCK.NEO  picture  for an
  97. example of these techniques.  The  pixel  boundaries  for  the x axis are
  98. shown below for reference (to save you working them out) -
  99.  
  100.  0,16,32,48,64,80,96,112,128,144,160,176,192,208,224,240,256,272,288,304
  101.  
  102. When a sprite is displayed, the  program  passes the x and y co-ordinates
  103. to the sprite S/R to  define  the  position on screen. These co-ordinates
  104. (known as the hot spot)  normally  refer  to  the  top  left pixel of the
  105. sprite rectangle.  For  stationary  sprites  this  is  usually  adequate,
  106. however, for moveable sprites it  is  frequently  useful  to have the hot
  107. spot  in  the  centre  of   the   sprite   to  make  programming  easier.
  108. Unfortunately, NEOCHROME-MASTER  does  not  provide  any  facilities  for
  109. changing the hot spot but it does  provide  two spare bytes in the sprite
  110. object definition file for each sprite  which  can  be used to store an x
  111. and y offset value  for  the  hot  spot.  The SPR_CHCK program (described
  112. elsewhere) provides an option to store  the  offset values in these spare
  113. bytes. If this  option  is  required  it  should  be  borne  in mind when
  114. designing the sprite, i.e. the width  and  height should be an odd number
  115. of pixels so that the hot spot  can  be placed in the exact centre. Also,
  116. if a number of sprites are to  have  the hot spot changed, they should be
  117. made consecutive numbers  so  that  the  'range'  option  in the SPR_CHCK
  118. program can be used. Note that  the  maximum  value  of the offset is 255
  119. (one byte size).
  120.  
  121. CUTTING OUT SPRITES.
  122.  
  123. When the sprites have been designed  (and  the NEOCHROME picture saved to
  124. disk) it is time to generate  a  sprite  object file. Click on the CUTTER
  125. (scissors) icon to display  various  options  most  of which are 'greyed'
  126. out. If this is a new object  file  being stored, select the first sprite
  127. with the mouse (see below), if a file has already been stored on disk and
  128. needs to be amended, click on LOAD  and  load in the file. Also 'load all
  129. used pictures' when requested, this  loads  in the NEOCHROME screens with
  130. the sprite definitions. MAKE SURE that any existing sprite file in memory
  131. is first cleared (by clicking on NEW)  because  any new file loaded in is
  132. tagged on to the end of any  file  already  in memory and you will end up
  133. with hundreds of sprites (is this a bug or intentional ?).
  134.  
  135. To select a sprite, click on the  top left pixel of the sprite rectangle,
  136. drag the flashing dotted box down  to  the bottom right pixel and release
  137. the button. Note that the sprite  width  and  height are displayed in the
  138. CUTTER box during this  operation.  As  mentioned  above, ensure that the
  139. left x co-ordinate is on a 16 pixel boundary and the right co-ordinate is
  140. on a 16 pixel boundary minus 1.  Click  on  the ADD icon (or press F1) to
  141. add the sprite to the  object  file,  the  number  001 will appear in the
  142. centre box. Repeat the process  for  each  sprite  until all sprites have
  143. been captured and then click  on  SAVE  to  save  the sprite file back to
  144. disk. Enter an appropriate  filename  into  the  file  selector (the .OBJ
  145. extension is added  automatically)  and  save  the  file  WITH the header
  146. information.
  147.  
  148. It is IMPORTANT that when  adding  further  sprites to an existing object
  149. file, the last used sprite (this  number  is  shown  at the bottom of the
  150. CUTTER box) is displayed in  the  centre  box  before clicking on the ADD
  151. box. If this is not done  the  additional  sprite/s will be placed at the
  152. current sprite position and mess up the whole file.
  153.  
  154. To display (or select) a  sprite,  click  on  the  box either side of the
  155. current sprite box until the required sprite number appears in the centre
  156. box and then click on SHOW.  The  dotted rectangle will appear around the
  157. selected sprite (you can use  the  GRIDLOCK.OBJ and GRIDLOCK.NEO files to
  158. try these options out).
  159.  
  160. To change an existing sprite first edit  the sprite image with the normal
  161. NEOCHROME tools and then select  it  as  described above. Move the dotted
  162. rectangle to the new position  by  dragging  the  bottom right corner (if
  163. required) and then click on the CHNGE  box  to store the new image in the
  164. sprite object file. Don't  forget  to  re-save  the  sprite  file AND the
  165. NEOCHROME picture to disk.
  166.  
  167. It is also possible to delete a  sprite  but  as this will change all the
  168. numbering system it is not recommended, if you plan your sprites properly
  169. this should not be necessary anyway.
  170.  
  171.  
  172. COLOUR PALETTE.
  173.  
  174. The sprite object file does  not  store  any information about the colour
  175. palette since the  palette  colours  could  be  different  for sprites on
  176. different screens. NEOCHROME-MASTER  does  have  a  facility, however, to
  177. save the palette information to disk as  a  source file which can then be
  178. imported into the program source file  to  set  up the palette colours at
  179. the start of the program.
  180.  
  181. Select the main screen by pressing key 0  on the keypad and then click on
  182. the GRABBER (hand) icon. Click on  SAVE  PALETTE  *.S to save the palette
  183. colours to disk using  a  suitable  filename.  This  file  should then be
  184. inserted into the program source file and  used to set the screen colours
  185. with the usual BIOS call. The file can  then be deleted from the disk, if
  186. required.
  187.  
  188.  
  189.  
  190. Although the programmer should not need to  know the format of the sprite
  191. object file it is shown below for reference.
  192.  
  193.  
  194.  
  195.  ------------ FORMAT OF NEOCHROME-MASTER SPRITE DATA FILE ------------
  196.  
  197. Offset  Size    Contents        Function
  198.  
  199.         Section 1 (Ident and version, 10 bytes)
  200.  
  201. 0       6       'NEOOBJ'        Identification characters
  202. 6       2       01 01           Version (11)
  203. 8       2       nn nn           Offset from next byte to section 4
  204.  
  205.         Section 2 (Screen filenames, 14 bytes/filename)
  206.  
  207. 0       1       nn              Screen number (0-9)
  208. 1       12      FILENAME.OBJ    Filename + extn
  209. 12      1       00              NUL chr
  210.  
  211.  The above section repeated for each screen filename used
  212.  
  213.         Section 3 (Offset to end of file and number of sprites, 6 bytes)
  214.  
  215. 0       4       nn nn nn nn     Offset to end of file
  216. 4       2       nn nn           Number of objects in file
  217.  
  218.         Section 4 (Header block for sprite objects, 20 bytes/sprite)
  219.  
  220. 0       4       nn nn nn nn     Offset to object data block
  221. 4       2       nn nn           Width of sprite in pixels
  222. 6       2       nn nn           Height of sprite in pixels
  223. 8       2       00 04           Number of planes (always 4)
  224. 10      2       nn nn           Width of sprite in bytes
  225. 12      2       nn nn           x co-ordinate in screen
  226. 14      2       nn nn           y co-ordinate in screen
  227. 16      2       00 00           x and y offset values (see text)
  228. 18      2       nn nn           Screen number (0-9)
  229.  
  230. The above section repeated for each sprite
  231.  
  232.         Section 5 (Sprite data, nnnnnnnn bytes/sprite)
  233.  
  234. 0       ?       nn nn           Sprite data to end of file
  235.  
  236.                 ------------End of sprite data-----------
  237.  
  238.  
  239.  
  240.  
  241. SPRITE CHECK PROGRAM.
  242.  
  243. One small problem with NEOCHROME-MASTER is that it is not easy to display
  244. the sprites easily from within the program one after the other, it is not
  245. easy to determine the size of each  sprite  and it is not possible to set
  246. the hot spot offset values. The SPR_CHCK program allows the programmer to
  247. display the information on  each  sprite  as  well  as  the sprite images
  248. themselves easily. It also allows the  sprite  object file to be modified
  249. with the hot spot offset values and saved back to disk. If the programmer
  250. wishes to use these options the  SPR_CHCK  program should be used to make
  251. the necessary  changes.  See  the  SPR_CHCK.DOC  file  for  the operating
  252. instructions.
  253.  
  254. GRIDLOCK PROGRAM.
  255.  
  256. To demonstrate the use and programming  techniques of the sprite routines
  257. I  have  written  a  simple  word  game  program  called  GRIDLOCK  which
  258. programmers may study and change as they like.
  259.  
  260. The source code is  provided  and  should  be  assembled  with the Devpac
  261. Assembler using the GEMMACRO, VDILIB and  AESLIB files (you will probably
  262. have to change the pathnames in the 'include' pseudo ops for your own set
  263. up. An assembled version (GRIDLOCK.PRG) is  also  provided on the disk to
  264. try out first, the GRIDLOCK.OBJ file  is  the  sprite data and must be in
  265. the same directory as the program  itself. The GRIDLOCK.NEO file contains
  266. the sprite definitions and  can  be  viewed  with the NEOCHROME-MASTER or
  267. SPR_CHCK programs.
  268.  
  269. The idea of the game is for two players to make words across and down (as
  270. in Scrabble) which must  have  three  or  more  letters.  Each player has
  271. alternate turns and moves one letter down  into  the grid on each turn to
  272. try and make a word. A three  letter  word scores 3 points, a four letter
  273. word scores 4 points and so on.  Words  that  are made across and down at
  274. the same time score for both  words.  Press  the right button to change a
  275. letter after it has been selected.
  276.  
  277. Perhaps someone would like to  add  to  the  program so that the computer
  278. plays against the user and also keeps  score. If you don't like the rules
  279. you can make up your own.
  280.  
  281. CONCLUSION.
  282.  
  283. Programmers are welcome to use any  of the sub-routines mentioned in this
  284. document in their  own  programs.  If,  however,  they  are  used  in any
  285. published programs I  would  appreciate  a  mention  in  the accompanying
  286. documentation. If anyone has any comments  (good  or  bad) to make on the
  287. above please let me know at -
  288.  
  289.       63 Woolsbridge Road, Ashley Heath, Ringwood, Dorset, BH24 2LX
  290.