ZX Review #7-8-9-10
08 ноября 1997

reader-reader - Programming arcade game with scrolling screen.

<b>reader-reader</b> - Programming arcade game with scrolling screen.
(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.



           *







Other articles:

TR-DOS for beginners - The end.

Computer novella - Prince of Persia.

Computer novella - Laser team (the game Laser Squad).

Crossing Dragon - Game Rapscallion.

Crossing Dragon - Playing The Runes of Zendos.

Crossing Dragon - Playing The Saga.

Crossing Dragon - Game Witch's Cauldron.

Crossing Dragon - Create Adventyuru. Review of the editors.

Crossing Dragon - Create a dictionary to Adventyurnoy game.

Program, which we choose - The possible consequences of using undocumented commands.

Program, which we choose - About noticed irregularities in some programs and suggestions for future versions.

Program, which we choose - A proposal to all the authors of software, printers, memory dump. Programmers protect discs from being copied.

Program, which we choose - A few suggestions to improve the assembly.

Program, which we choose - Suggestions for refining ZX Word v2.5.

Program, which we choose - The "Spectrum emulator" v1.2.

Program, which we choose - What could want in a perfect assembly.

Retro - 40 best procedures: Copying data in memory.

Retro - 40 best procedures: Exchange token.

Retro - 40 best procedures: Determination addresses BASIC string.

Retro - 40 best procedures: Determination of the length of BASIC programs.

Retro - 40 best procedures: Determination of the amount of free memory.

Retro - 40 best procedures for: Search and replace strings.

Retro - 40 best procedure: Find the string.

Retro - 40 best procedures: Search for the string.

Retro - 40 best procedures: the list of variables.

Retro - 40 best procedures: an increase and up the screen.

Retro - 40 best treatments: Removal of REM-strings.

Retro - 40 best procedures: Remove the block of the program.

Expert Tips - Game Fredloader.

Expert Tips - Game Robin of Sherwood: The Touchstones of Rhianon.

Expert Tips - Game Scorpions: Die Machines.

Expert Tips - Game Terropods.

page iS-DOS - Description of system restarts IS DOS.

Forum - An algorithm for recognizing characters.

Forum - Time undocumented command processor Z80.

Forum - The concept of a high-color screen resolution.

Forum - A few Pokes to a game. Program Hacman96.

Forum - As for the new DOS and BIOS settings for the Spectrum.

Forum - Multicolor program on any computer model. Using the 2 nd screen Multicolor'a. Demonstration of the text. Electronic journals.

Forum - Project ZX Config.

Forum - Improve Art Studio. Ideas on file compression.

Forum - ZX Spectrum emulator for IBM. About the hexadecimal system. Program ZX-Stars. Oddities in the Elita

Forum - The effects on the curb and Multicolor.

reader-reader - ZX Spectrum 128 - new opportunities, new challenges.

reader-reader - With 'Light'. Spectrum and expert system.

reader-reader - The printer driver for the Scorpion.

reader-reader - Print numbers in different number systems.

reader-reader - Programming arcade game with scrolling screen.

reader-reader - The procedure for printing labels assembler XAS to monitor debugger STS 4.3.

Studies - attribute scrolling text. "Gasilka" screen. A simplified version of the procedure, "Curtain". Procedure is enriched with pictures. Procedure display images on the points.

Studies - Graphic effect "color bars".

Studies - Driver screen printing 64 characters per line.

Studies - Set of protective boot.

Studies - Address to the drive mode IM 2. Working with non-standard disc format.

Studies - Print the character, magnified by 8 times. The program "pouring" screen. The procedure for screen-saver on the points. Clear screen in Terminator'e. Search strings in memory. System character set conversion.

Studies - Program - cataloger of disks.

Studies - Program the output values of the amplitude channel music. coprocessor on the curb.

Studies - Program the output image.

Studies - The program plugs sprite.

Studies - Cleanup of the specified window screen.

Studies - The program sort the array in ascending order. The procedure for filling the screen specified attribute. Procedure display pictures. The effect of moving towards the stars. "Shower", coming from the upper left corner of the screen. The procedure of "shedding" pictures on the pixel lines. The program of "pulling" the picture at an angle of 45 degrees. Three procedures "Scroll".

Studies - The printing of numbers.

Studies - The procedure for drawing a character with attributes.

Studies - The procedure for display pictures. Fade-OUT effect (picture goes beyond the edge of the screen). Visual effect "Fountain." Fade-OUT effect, mimicking the TV off. Procedure "Ignition" pictures. The program continuously drawing a picture.

Studies - The procedure for drawing a line.

Studies - The procedure for making optimal symbol table.

Studies - scrolling lines of text in the specified window. Attribute scroller. Diagonal scrolling.

Studies - sprite scroller. Procedure display screen.

Studies - Short procedure indicating the amplitude channel music. coprocessor. Way to subtract a constant from a register pair HL.

Studies - The formula for calculating the day of the week.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Raskolnikovs - Kq: "now almost no motivation to participate in the ZX Democompo on such main stream demopati as CC or CAFe" ...
Games - access codes to the level in the game Magic Stripes and Sexonix. POKE's to the game land of myths.
News - Spectrum news from Rybinsk.

В этот день...   21 November