home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 229 / 229.d81 / t.js1 < prev    next >
Text File  |  2022-08-26  |  7KB  |  305 lines

  1. u
  2.           J O Y S P R I T E
  3.            by Dave Moorman
  4.  
  5.  
  6.     What this country needs is a
  7. good, healthy five cent cigar. Yeah,
  8. that will happen! The next best thing
  9. would be a really powerful
  10. Joystick and Sprite Control Module.
  11.  
  12.     And, lo! and behold, we now have
  13. JoySprite -- which will make
  14. designing sprite-loaded programs
  15. almost easy! No more hunting down
  16. register addresses or doing bit-logic
  17. calculations. Here are the
  18. commands you can use in BASIC to make
  19. sprites do their stuff -- and
  20. MORE!
  21.  
  22.     If you are newish at programming,
  23. you will want to read "Build a
  24. Boot," also in this issue. It uses
  25. JoySprite as an example and shows
  26. how to use a boot program to "move up
  27. the Bottom of BASIC," something
  28. many of us do every time we sit down
  29. to write a program. Also, the
  30. article "Sprites Are Fun" will
  31. explain much about how sprites and
  32. video work on the C-64.
  33.  
  34.     JoySprite runs in the background,
  35. using the Jiffy IRQ. So the first
  36. thing you want to do is turn on the
  37. IRQ driver.
  38.  
  39.     The variable AD here refers to the
  40. Load address of the JOYSPRITE ML file.
  41.  
  42.  
  43. IRQ ON
  44.     SYS AD
  45.  
  46.  This is fully protected and will
  47. work with other IRQ drivers that are
  48. already running on the computer.
  49.  
  50.     Of course, the last thing to do
  51. in your program is turn it off.
  52.  
  53. IRQ OFF
  54.     SYS AD+03
  55.  
  56.     (After testing, I have found that
  57. a SYS AD+3 at the very beginning of
  58. the program resets everything and
  59. makes JoySprite run better -- DMM)
  60.  
  61.  IRQ drivers should be turned off in
  62. the reverse order of how they were
  63. turned on. JoySpirit saves whatever
  64. location was in the IRQ Vector when
  65. started, and when stopped, replaces
  66. this address.
  67.  
  68.  
  69. [SPRITES]
  70. [-------]
  71.  
  72.     If you are using a text screen
  73. other than the default at 1024, you
  74. need to use this next command. The
  75. sprite image pointers are always at
  76. TextScreen + 1016. For bitmap
  77. graphics, the pointers are at
  78. VideoColor + 1016. Use this command to
  79. put the value into the program.
  80.  
  81. SPRITE POINTER
  82.     SYS AD+06 , LOC (2040 DEFAULT)
  83.  
  84.  (If you are using the default text
  85. screen, this command is not
  86. needed.) This is the only internal
  87. location you will need to know --
  88. other than the Sprite Image numbers.
  89.  
  90.     Since we are not using any direct
  91. POKEs, the following command will put
  92. the Sprite Image into the sprite's
  93. image pointer.
  94.  
  95. SPRITE IMAGE
  96.     SYS AD+09 ,SP,IMG
  97.  where
  98.     SP = Sprite Number (0-7)
  99.     IMG = Image Number (0-255)
  100.  
  101.  
  102.     Sprites have many registers to be
  103. set -- and the following command
  104. sets most of them.
  105.  
  106. SPRITE SET
  107.     SYS AD+12 ,SP,CO,MC,XY,PR
  108.  where
  109.     SP = Sprite Number
  110.     CO = Color       (0-15)
  111.     MC = Multi-Color (0 - Off, 1 - On)
  112.     XY = X- and Y-expand
  113.             (0 - Both Off)
  114.             (1 - X-expand)
  115.             (2 - Y-expand)
  116.             (3 - Both On)
  117.     PR = Priority (0-Sprite in Front)
  118.                   (1 - Sprite Behind)
  119.  
  120.  This one command replaces 5 POKEs,
  121. and many bit-logic headaches.
  122.  
  123.     Our sprite position command
  124. handles the X-coordinate high bit for
  125. you. All you have to do is remember
  126. the off-sets.
  127.  
  128. SPRITE AT
  129.     SYS AD+15 ,SP,X,Y
  130.  where
  131.     SP = Sprite Number
  132.     X = X-coordinate (0-511)
  133.     Y = Y-coordinate (0-255)
  134.  
  135.  
  136.     Now to turn the sprite on (or
  137. off).
  138.  
  139. SPRITE ON
  140.     SYS AD+18 ,SP,OFF/ON
  141.  where
  142.     SP = Sprite Number
  143.     OFF/ON = Switch (0 - Off, 1 - On)
  144.  
  145.  What? No more POKE53269,byte?
  146. Exactly! Unless you want to, of
  147. course!
  148.  
  149.  
  150.     To enable IRQ-driven sprite
  151. movement, use the following command:
  152.  
  153. SPRITE MOVE
  154.     SYS AD+21 ,sp,DX,DY,SK
  155.  where
  156.     SP = Sprite Number
  157.     DX = DeltaX -- pixels to change
  158.                     X-coordinate
  159.     DY = DeltaY -- pixels to change
  160.                     Y-coordinate
  161.     SK = Skipped Jiffies
  162.                  1 fastest,
  163.                  255 - painfully slow
  164.                  0 -- no movement
  165.  
  166.     Suppose you want to automatically
  167. move Sprite 7 to the southeast.
  168. You would use this command:
  169.  
  170.     SYS AD+21, 7, 1, 1, 1
  171.  
  172.  If that proves too fast, increase
  173. the SK value. If too slow, increase
  174. the DX and DY values.
  175.  
  176.     One quirk -- I could not find how
  177. to use a negative number after a SYS
  178. command. So for moving right (DX=-1)
  179. or up (DY=-1), subtract the movement
  180. value from 256:
  181.  
  182.     SYS AD+21, 7, 256-1, 256-1, 1
  183.  
  184.  for a northwest diagonal. By
  185. combining different DX an DY values
  186. (and compensating with SK) you can
  187. move the sprite in most any general
  188. direction:
  189.  
  190.    SYS AD+21, 7, 256-3, 1, 2
  191.  
  192.  
  193.     Modern programming languages such
  194. as C++ and Visual Basic use a new
  195. conceptual model called Object
  196. Oriented Programming Systems (OOPS).
  197. Rather than deal with hardware
  198. registers and numerous variables, each
  199. feature in a program is an Object with
  200. certain attributes. In full OOPS, the
  201. name and attribute function something
  202. like an "active variable." To set set
  203. Sprite7's color, you would use
  204. something like
  205.  
  206.  [Sprite7.color = "blue"]
  207.  
  208.  You can use the same attribute to
  209. find out what Sprite7's color is:
  210.  
  211.  [Color = Sprite7.color]
  212.  
  213.     This is all theoretical for Basic
  214. 2.0 people, since we don't have such
  215. "active variables." But JoySprite uses
  216. a quasi-Object Oriented approach. Each
  217. sprite is a programming object with
  218. certain Attributes such as position,
  219. image, color, etc.
  220.  
  221.     For JoySprite, you can access the
  222. Attributes with something like an
  223. array. Use the following SYSes with
  224. the Sprite Number, and the
  225. information is available to BASIC in
  226. integer variables.
  227.  
  228. SPRITE ASK
  229.     SYS AD+24 ,SP
  230.  where
  231.     SP = Sprite Number
  232.  
  233.  The returned values are in the
  234. following integer variables:
  235.  
  236.   X% - X-coordinate (0-511)
  237.   Y% - Y-coordinate (0-255)
  238.   I% - Image Number (0-255)
  239.   EN% - Sprite Enabled (0-1)
  240.  
  241.     But that's not all. The values
  242. set with SPR.SET are also available.
  243.  
  244. SET ASK
  245.     SYS AD+27 ,SP
  246.  where
  247.     SP = Sprite Number
  248.  
  249.  The returned values are in the
  250. following integer variables:
  251.  
  252.   CO% - Color (0-15)
  253.   MC% - Multi-Color Mode (0-1)
  254.   XY% - X- and Y-expansion (0-3)
  255.   PR% - Priority (0-1)
  256.  
  257.  
  258.     JoySprite can be used with any
  259. Video Bank, and up to 208 sprite
  260. images can be used directly. Is that
  261. enough? If not, SPR.CPY will move
  262. Sprite Images from anywhere in open
  263. memory (not under ROM) to the VIC
  264. II Sprite Image area.
  265.  
  266.     JoySprite uses Video Bank/Sprite
  267. Image addressing for SPR.CPY. If you
  268. are using the default text screen,
  269. with Sprite Images beginning at 8192,
  270. the location for the first image would
  271. be VBank = 0, Image = 128. VBank 1
  272. begins at 16384; VBank 2 begins at
  273. 32768; VBank 3 begins at 49152. The
  274. Images in each bank are numbered
  275. 0-255. So the location of a Sprite
  276. Image can be calculated as:
  277.  
  278.  LOC = VBank * 16384 + Image# * 64
  279.  
  280.     Here are two DEF FNs to calculate
  281. VBank and Image#:
  282.  
  283.  VBank -
  284.     DEF FNV(L)=(L-FNV(L)*16384)/64
  285.  
  286.  Image# -
  287.     DEF FNI(L)=INT(L/16384)
  288.  
  289.  You will want to use such Defined
  290. Functions for Sprite Copy:
  291.  
  292. SPRITE COPY
  293.     SYS AD+30 ,FBNK,SP,TBNK,SP,#SPS
  294.  where
  295.     FBNK = From VBank#
  296.     FSI  = From Sprite Image#
  297.     TBNK = To VBank#
  298.     TSI  = To Sprite Image#
  299.     #SPS = Number of Sprites to Move
  300.  
  301.  As you can see, SPR.CPY moves data
  302. in chunks of 64 bytes. Move one,
  303. move 'em all!
  304.  
  305.  
  306.