reader-reader - Programming arcade game with scrolling screen.

ZX Review #7-8-9-10
(C) M. Tatarinov, Solikamsk,

    Perm Region.


  Everyone who planned to do arcade game, dedicated ...


   If you decide to write a game
scrolling the screen and do not know how to do this, then this
article will help you. I want to say that the limited volume
paper does not allow me to cite specific examples (a complete
package of procedures for working with the card took me about 2 
kilobytes), but if you decide to write a game, then you are 
very skilled programmer knows what's what. All

the article said, has a practical confirmation, so
feel free to write their own procedures.


        1. Card format


   Minimal element on the map is the block size 32x32
pixel, ie 4x4 familiarity.
These sizes are not chosen randomly, here are their advantages:

   1) 4 - is one of the degrees
number 2, so that all arithmetic operations are extremely 
simplified through the use of the shift teams. 

   2) A huge plus - it's small
the size of memory occupied by the card. Thus, the map size 
1024x16 familiarity (8x8) takes only

only 1024 bytes, a map of the same
8x8 block takes 16 times more, ie 16 KB.

   3) 1 block of 4x4 prints faster than 16 separate familiarity.


   While the size of one block is equal to 16x8 +16 = 144 bytes 
(if the attributes), 30-40 units is quite sufficient and does 
not take much memory.


 2. A bit about graphic kit


   In what format to store information about graphic templates
your case. I propose the format
raster image that is printed faster.


         4 lines>


                >

                >

                >
16 lines + attributes

                >

                >

                > \ / \ /



   Arrows indicate the direction of printing, ie, line by line.

   Information about the attributes I
propose to store in a separate file, which is attributed to the 
end BitMap'a. Made it Again, to simplify calculation

address block. Because block size
without attributes is 128 bytes
then calculate the offset into the file
templates are extremely simple:

And in B - number of template

        ADD A, A
; X2 - in this case is appropriate, because for
; File in which more than 127 blocks, you
; Space insufficient

        LD H, 0

        LD L, A

        ADD HL, HL; x4

        ADD HL, HL; x8

        ADD HL, HL; x16

        ADD HL, HL; x32

        ADD HL, HL; x64

        ADD HL, HL; x128

        LD DE, TABL

        ADD HL, DE


   3. Conclusion cards with up to
familiarity on arbitrary coordinates (refers to map 
coordinates, not on the screen). 


   The attentive reader probably noticed that the discreteness
Card is a block 4x4, therefore, must scroll
not be less than 4 familiarity. Such a discrete approach for 
the Map Editor, but does not for the game, so you need to 
develop a technique that allows output to any window site maps 
to within familiarity.



  0 Y LENGTH

  1 0 1 2 3 4 5 6

  - ---- ---- ---- ---- ---- ---- ---- -

  2

  3

                                        H

  0 7 8 9 10 11 12 13 E

  1 I

  - ---- --- ---- ---- ---- ---- - - G

  2 H

  3 T
X

  0 14 15 16 17 18 19 20

  1

  - ---- --- ---- ---- ---- ---- - - -

  2

  3


  0 21 22 23 24 25 26 27

  1

  - ---- ---- ---- ---- ---- ---- ---- -

  2

  3

  0123 0123 0123 0123 0123 0123 0123


   Look at the picture, and you
once it becomes clear how to calculate the desired position of 
the window with coordinates (X, Y) on the map.

If you do not understand that quote
the following conclusions:


   1) Obviously, if the map
has dimensions of Length * Height,
then a rough calculation of the position
Window (X, Y) starting offset
printout will be equal to X + Length *
Y (coordinates are set up
4x4). To increase the accuracy
positioning of windows, we introduce
shift the window separately for X and Y.
It can be from 0 to 3 and shows the offset
beginning of the current block. In the figure, these 
coordinates = (1.2, 1.1) where the integer part of - the block 
number on map - fractional offset.


   2) To display the map on the screen, you need to calculate 
the coordinates of the print on the screen. Fractional part of 
the X and Y (in this If it's 2 and 1), if they handle a team of 
NEG, give us starting coordinates printing

screen or in the buffer, ie 2 will be -2, 1 becomes -1 (# FE, # 
FF, if you like).



   4. How does the routine
printing unit and how to accelerate the withdrawal of the card.


   You've probably noticed that
the actual number of familiarity,
printed in the window is smaller than
of familiarity, belonging to
composition window, so the number of output units should be 1
greater than the length and height of windows,
divided by 4. That is, if
window size 32x16, then the number of printed blocks 32 / 4 +1 
= 9, 16 / 4 + 1 = 5. From this it follows that routine printing 
block must able to prune invisible familiarity (clipping). I 
want to say that the comparison operations and dramatically 
increased the number of blocks reduce the speed of printing.

To increase the speed I used method of using two
print routines. Look
the figure. We see that not all
units require pruning, so we create another routine press, 
which cuts not block elements. This routine should have a cycle 
only 4 familiarity, and 8 extra output without the cycle with 
LDI. I bring you a "portrait" windows 32x1 familiarity. Clip - 
clip element, No clip - do not cut off: 

 0 9 blocks clip, but if the bias
   of = 0, then 9 blocks no clip.
 4, the first - clip, 7 no clip, 1

   clip.
 8 is similar.
12 is analogous.
16 as 0, only

   offset = 0 does not print.


         5. Scrolling


   Well, it's simple. Consider the scrolling forward 1 
familiarity. Let the variables and HPOS HDISP play the role of 
coordinates and bias. Check HDISP 3.

If = 3 then HDISP: = 0, HPOS: =
HPOS +1; otherwise increase HDISP.
In the other direction - the same way.

   Finally I will say that the press
Cards should go to the clipboard, which I organized with 
address # E000 (More details - see the book

Applied Graphics), and therefore sets the buffer format
himself a programmer. The most convenient layout of the buffer 
- the line for line, which greatly simplifies

routine.

   And yet. If you need
more speed, I advise
skip zero entries in
print (gaps), but then you
have to use sub-clearing buffer. This method
most effectively improves
performance, but the result
game speed is not constant.


   P.S. If you intend to use the stack to improve
performance and intend to
use a sound that works for IM 2, then
playback speed of sound
will "float". This is due to
the fact that when working with a stack
to prohibit the interruption.
In writing the previous toys, I ran into this problem, because 
printing unit and the cleaning of the buffer used stack. 


    Along the way I want to answer
question Vasilyev Anton (N 4-5,
1996). I also dealt with problems of digital processing
sound AY, and that's what I did.
Method of recording virtually
no different from the one proposed
Sergei Belov (read sixth
bit rotate register), but I
used psevdokompressiyu. On
AY digitized sound output
through the registers of the amplitude and maximum amplitude 
did not exceeds 15, ie, four bits. In connection with this, 1 
byte you can put in 2 times more

Information:

 1) 0000xxxx = E - 1 cycle read
 2) xxxxyyyy = E - 2 cycle read
 3) (HL) = E - memorization

    INC HL


   Registers 11 and 12 is given by
the rate of change of amplitude with a built-in envelope 
generator. 


   Ed.: Thanks to Maxim for this very interesting article. Only 
here would like to add a few words about the use of the stack 
in the derivation of the map. Yes, indeed, an interrupt when it 
should be forbidden, but to get rid of "navigation"

sound when it is still possible. For this
output card is necessary to begin immediately after
HALT, and he concluded must fit in the number of cycles between 
interrupts. Then you have time to resolve the interruption just 
at the time when the next interrupt is to occur.



           *