Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #1855

Re: "Best practices" for animating sprites in Apple II Assembly? (HGR/HGR2)

From "Anton Treuenfels" <teamtempest@yahoo.com>
Newsgroups comp.sys.apple2.programmer
References <3dfeb2b4-f124-40fe-afe1-cfde8912151d@googlegroups.com>
Subject Re: "Best practices" for animating sprites in Apple II Assembly? (HGR/HGR2)
Date 2015-10-16 08:32 -0500
Message-ID <e-mdnWqBXdziYb3LnZ2dnUU7-fOdnZ2d@earthlink.com> (permalink)

Show all headers | View raw


You might start by working out for yourself, on pencil and paper, a formula 
to convert an (x,y) location - the actual way you'll likely be thinking of 
your sprite positions, as it's by far the easiest - into the address of the 
byte on the screen that represents that location. Then think about how you'd 
go about converting that formula into assembly language.

Whatever formula you come up with will likely involve a multiplication. The 
6502 does not have a multiplication instruction, but you can write a routine 
to do it using the instructions it does have. Put the result into a pair of 
zero-page locations and you have a pointer to the exact byte you need to 
change.

That will work, but it will be slow. If that's a problem for what you have 
in mind, consider that you can have Merlin do multiplications at assembly 
time. A common approach is to create a table of 192 pointers to the start of 
each of the 192 screen lines. Use the y-coordinate to index this table and 
copy the result to a pair of zero-page locations. Now use the x-coordinate 
to index the byte on that line you need to change using the zero-page 
pointer to the first byte on that line.

Both indices are less than 256, so that limit on index register values is 
not a problem (split the line pointer table into upper and lower halves to 
make it easy to access).

- Anton Treuenfels


<jamesiwalker77@gmail.com> wrote in message 
news:3dfeb2b4-f124-40fe-afe1-cfde8912151d@googlegroups.com...
My family had an Apple IIe when I was young, but the furthest I got in game 
programming on the Apple IIe as a kid (age 6-13, after which I migrated to 
C++ programming on Windows PC's) was animated text games in the upper-left 
corner of the screen (because the Apple IIe didn't animate fast in BASIC and 
I couldn't find a book that explained Apple II assembly graphics programming 
in a way that I could understand at the time).  I am now getting into Apple 
II assembly programming on the Apple IIe emulator, AppleWin. I am using the 
Merlin assembler, and have learned a lot of what I know so far from 
"Programming the Apple II in Assembly Language" by Rodnay Zaks, which I 
bought a hard-copy of on Amazon.  I'm wondering, I have not seen any 
commands in the Assembly language instruction set that can put values into 
an address in memory that is specified by a 2-byte "variable."  The closest 
I see to that is specifying a static 2-byte address, which can take a 1-byte 
"variable" offset, which I think can be accomplished with STA, if I 
correctly understand the instruction set. If you only have 1 byte of 
variability with STA, and in Apple IIe hi-res games, a sprite moves all 
around a screen that spans 8,192 bytes, what is a typical way that a game 
programmer would plot pixels to the screen for animation in assembly 
language? I already understand how screen memory is mapped on the Apple IIe, 
and how a particular byte will display a particular 7-pixel pattern, so I 
don't need an explanation of that.  (I created a program in C# .NET that 
spits out all of the starting address for each row in hi-res page 2 memory, 
according to a formula from Rodnay Zaks' book.) It seems to me that 1 byte 
of variability in the offset would only allow you to plot to 256 bytes of 
memory dynamically, and if you wanted to plot to more, you would have to 
jump through a lot of hoops in order to do so.  So, is there an assembly 
language instruction that I am not aware of that allows 2 byte variability? 
And, if not, what techniques did (or do) Apple II assembly language 
programmers typically use to accomplish animation where sprites move all 
around the screen, which provide an optimum balance of both memory storage 
and processing speed?  I would really appreciate if anyone would answer this 
question for me, as I haven't yet found an answer to this on the internet 
and I really want to know how to do it, preferably in a way that would be 
recommended for best coding practices given the available instruction set. 
Thanks. 

Back to comp.sys.apple2.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

"Best practices" for animating sprites in Apple II Assembly? (HGR/HGR2) jamesiwalker77@gmail.com - 2015-10-15 19:15 -0700
  Re: "Best practices" for animating sprites in Apple II Assembly? (HGR/HGR2) Michael J. Mahon <mjmahon@aol.com> - 2015-10-16 01:58 -0500
    Re: "Best practices" for animating sprites in Apple II Assembly? (HGR/HGR2) jamesiwalker77@gmail.com - 2015-10-16 08:38 -0700
  Re: "Best practices" for animating sprites in Apple II Assembly? (HGR/HGR2) mmphosis <mmphosis@macgui.com> - 2015-10-16 07:01 +0000
    Re: "Best practices" for animating sprites in Apple II Assembly? (HGR/HGR2) jamesiwalker77@gmail.com - 2015-10-16 08:49 -0700
  Re: "Best practices" for animating sprites in Apple II Assembly? (HGR/HGR2) "Anton Treuenfels" <teamtempest@yahoo.com> - 2015-10-16 08:32 -0500
  Re: "Best practices" for animating sprites in Apple II Assembly? (HGR/HGR2) John Brooks <jbrooks@blueshiftinc.com> - 2015-10-16 08:08 -0700
  Re: "Best practices" for animating sprites in Apple II Assembly? (HGR/HGR2) jamesiwalker77@gmail.com - 2015-10-16 08:34 -0700

csiph-web