PRINT Sprite
(Coordinates are
In the familiarity)
Now we're with you, we consider
simple procedure for printing
sprites. All their simplicity lies in the fact that the
coordinates are given in print familiarity. This the fastest
and at the same time not are really necessary and the
procedure, but we must consider them, because they provide the
basis for all procedures for printing sprites.
Consider the basic structure of the procedure. What is it
should be: let's look at the data that we have
There are at this point: it is
length and height of the sprite, its address in the box and the
coordinates of the press. The first thing we need to get
address in the screen, which would correspond to the
coordinates of our press, and it helps us to calculate the
unpretentious files of: 140.
------------------------------------ 3 (C) 1994 A. Ivanov
(ZX-Review N3 1994) ------------------------------------ ADR LD
A, L
AND 7
RRCA
RRCA
RRCA
ADD A, H
LD H, L
LD L, A
LD A, H
AND # 18
OR # 40
LD H, A
RET
2
Now absolutely all data from
We have and we can do nothing except print a sprite
on the screen. We still have some data - is the length and
height of the sprite. You have not thought about which of these
numbers is more important? Now is the time think about it,
because of This depends on the speed of
Your procedure. If you look at this earlier scheme for storing
a sprite, you can easily answer this question. So, the
important thing here is the height of the sprite, with her and
we organize the first cycle of the press.
Now it was time to give all
procedure completely.
140.
SETSPR LD HL, (COORD); Writes in HL coordinates printing.
CALL ADR; calculate the address on the screen.
LD DE, (ADRSPR); In DE enters the address data sprite.
LD A, (LENHGT +1); In case A enters the height of the
sprite.
LD B, A; In case B the height of the sprite in the
peak ; Mudflows.
SETSPR1 PUSH HL; Save the address on the screen.
LD A, (LENHGT); In case A enters the length of the
sprite.
LD C, A; In case C the length of the sprite as a sign
of ; Places.
SETSPR2 LD A, (DE); Take a byte mask / sprite.
IZM AND (HL); impose on AND / OR for byte screening
; On. It depends on what we ne
; Chat - a mask or a sprite.
LD (HL), A; Rewrite the screen.
INC DE; proceed to the next byte masks -
; Sprite
INC HL; proceed to the next familiarity eq
; Wound.
DEC C; reduces the length of the sprite.
JR NZ, SETSPR2; If the length is not 0, continue
; Print in length.
POP HL; Restore address on your screen.
CALL DOWN; proceed to the next pixel is
; Institute below.
DJNZ SETSPR1; If the height is not equal to 0,
continue
; Print.
RET
--------------------------------------- 3 (C) 1995 Paul Starks
(ZX-Review N4 1995) ---------------------------------------
DOWN INC H
LD A, H
AND # 07
RET NZ
LD A, L
ADD A, # 20
LD L, A
RET C
LD A, H
SUB # 08
LD H, A
RET
2
Now let's try to print on screen the sprite with the mask
from the game 3D BATMAN. Look at how this will look Program:
140.
PRINSPR LD HL, (COORD); We take the coordinates of the press.
CALL ADR; calculate the address on the screen.
PUSH HL; Store.
LD DE, (ADRSPR); In DE address of sprite in memory.
CALL SETSPR; impose a mask.
POP HL; Restore address on your screen.
LD A, # B6; Change command AND (HL) on the OR (HL).
LD (IZM), A
CALL SETSPR; Print the sprite.
LD A, # A6; Restore command AND (HL).
LD (IZM), A
RET
SETSPR LD A, (LENHGT +1)
LD B, A
SETSPR1 PUSH HL
LD A, (LENHGT)
LD C, A
SETSPR2 LD A, (DE)
IZM AND (HL)
LD (HL), A
INC DE
INC HL
DEC C
JR NZ, SETSPR2
POP HL
CALL DOWN
DJNZ SETSPR1
RET
2
As seen from this program,
we printed a sprite like 2 times, that does not work very
quickly and does not speak in favor of such storage format.
Now let's print it
sprite to the program ELEFANT-1:
140.PRINTSPR LD HL, (COORD)
CALL ADR
LD DE, SPRDATA
LD B, HGT
SETSPR1 PUSH HL
LD C, LEN
SETSPR2 LD A, (DE); Take a byte mask.
AND (HL); combines it with the byte of the screen.
INC DE; proceed to byte sprite.
EX DE, HL; temporarily changes the HL and DE, in
places, so
, As OR (DE) no.
OR (HL); Print the bytes in the sprite.
EX DE, HL; Restore DE.
LD (HL), A; redraw the screen.
INC DE
INC HL
DEC C
JR NZ, SETSPR2
POP HL
CALL DOWN
DJNZ SETSPR1
RET
2
This is the fastest of all
given before this procedure
printing and the most effective.
I want to focus your attention on the
the next moment - as
byte mask, and byte sprite alternate with each other, then the
length sprite can not be 3
familiarity, and 6 (where 6 can
bypassed if the program that creates the sprites, do not take
into account this point), then you should
before entering the length of the register
C to reduce it to twice the team SRL A. Feature of this program
is that sprite appears on the screen
smoothly, because when you print
sprite previous (particularly
first) programs, if the sprite
is quite large, you can see
screen flicker.
Well, now we have to print a sprite from the program
JACK THE NIPPER-2. Here, too,
should draw your attention to
that in the header length can
indicated wrong: can
be given the total length of the mask and
sprite, and you have the same C
divided by 2, as in the previous procedure:
140.
PRINTSPR LD HL, (COORD)
CALL ADR
LD DE, (ADRSPR)
LD A, (LENHGT +1)
LD B, A
SETSPR1 PUSH HL
LD A, (LENHGT)
LD C, A
SETSPR2 LD A, (DE); Print the line masks.
AND (HL)
LD (HL), A
INC DE
INC HL
DEC C
JR NZ, SETSPR2
POP HL; Restore address on your screen.
PUSH HL; again save it.
LD A, (LENHGT)
LD C, A
SETSPR3 LD A, (DE); Print the line of the sprite.
OR (HL)
LD (HL), A
INC DE
INC HL
DEC C
JR NZ, SETSPR3
POP HL
CALL DOWN
DJNZ SETSPR1
RET
2
I did not give detailed
Comments on this procedure,
it almost doubles the second and differs from it only
arrangement of structural elements.
Previous sprites we printed without attributes to print the
attributes of the sprite, we must add to these procedures,
another small. For the second procedure, it should be made into
a routines and cause a
CALL at the end of the head of the program.
To print the attributes of the sprite
we need to address in the screen, which we got after calling
sub ADR, for this HL
must maintain two, not one
times, as in previous versions.
For the first procedure before calling the print attributes
restore the address on the screen, and the first line labeled
SETATTR Playing print attributes remove. Well, now the
procedure itself:
140.SETATTR POP HL; Restore address on your screen.
--------------------------------------- 3 (C) 1994 Vladimir
Patrakhin ( ZX-Revue N6 1994)
--------------------------------------- LD A, H;
translate the address in the address on the screen
; Attributes.
RRCA
RRCA
RRCA
AND # 03
OR # 58
LD H, A
---------------------------------------
LD A, (LENHGT +1)
LD B, A; In case B the height in pixels.
LD A, # 04
SRL B; divide by 2.
JR NC, R1; If strained, transition.
LD (IZM), A; In A command code INC B, introducing it
to
; Variable.
R1 SRL B; Divide at # 04.
JR NC, R2
LD (IZM), A
R2 SRL B; at # 08.
JR NC, IZM
LD (IZM), A
IZM NOP; Except where not divided evenly,
And here is a team INC B.
SETATTR1 PUSH HL; Save the address on the screen.
LD A, (LENHGT)
LD C, A; length of the sprite (for JACK THE NIPPER-2
, It is necessary after this command
to add SRL
; C, too, and for ELEFANT-1).
SETATTR2 LD A, (DE); We transfer the attributes of the screen.
LD (HL), A
INC DE
INC HL
DEC C
JR NZ, SETATTR2
POP HL
PUSH DE
LD DE, # 0020
ADD HL, DE
POP DE
DJNZ SETATTR1
RET
2
For sprites in the format ELEFANT-1 and JACK NIPPER-2 length
also is divided by 2 (unless, of course, you had to share it
for printing sprites).
Many may notice a strange design in the place where
We divided the height of the sprite to 8. I
forced to clarify this situation.
If your sprite in height is a multiple of
familiarity (divisible by
8), then this construction can be replaced by three teams SRL
B; but That is, if the sprite in
height not a multiple of familiarity, there may be disputes:
Example: height was 9
pixels. When divided by two, we
we get 4, 4 - 2, 8 - 1
but then the sprite in the attributes of familiarity takes 2 (9
line is as follows familiarity), and painted attributes will
only the first 8 lines. But for this, and
need a similar design.
Well, here we are with you and print all major formats of
sprites in familiarity, and we should go to print on sprites
pixels.