PRINT Sprite
(CONTACT PRESS
ASK pixels)
Yes, this topic requires special
attention, as numerous publications have not yet
shed light on it. Examples of these
procedures must include
very carefully, and there can be no unequivocal advice or
example. I will offer only its
considerations on this topic.
Let's see what's
is this complexity. First, the printing procedure is valid
Comrade Pixel extremely slow, and there can only help
talent of the programmer, his experience.
Secondly, each procedure is unique, there is no unambiguous way
that would satisfy all the requirements - all depends on the
size of a sprite. All these difficulties actually belong to
only one element of the program - print the sprite pixel
coordinate X, as the Y is made simple.
Today I offer you two
different ways of printing - the first prints the size of the
sprites 1 to 3 familiarity in length (height does not matter),
with a print of additional memory is not used, the second way
to print to print sprites of almost any size, but such an
approach will need a buffer whose size is directly proportional
to the size of the sprite (actually the memory need a bit more).
So, I propose to you the first way, it is based
on the fact that the free register pairs enough to
buffer to organize with the help of
them. Because the number of registers is small, then the
dimensions sprites, which can be printed in a way too limited
(limited only by the length, height sprites values are not
a). Well, now the program itself, it is designed to print a 2
sprites familiarity in length. Print data prepared already
considered Our ways: ADRSPR - Address
sprite into memory, LENHGT - length, height of the sprite. Adds
another variable that stores the coordinates of the print: CRDS
- Y, CRDS +1 - X.
140.
SETSPR LD DE, (CRDS); We take the coordinates of the press.
CALL ADRPIX; Calculate address for him in the screen.
LD A, D; We get the bit in a byte. In the latter
; Accordance with this number will op
; Ganizovan counter.
AND 7
EX AF, AF '; order not to expend the registers, we are
metal ; A equate to an alternative.
LD IX, (ADRSPR); In IX organize data pointer
; Sprite.
LD A, (LENHGT +1); In A put the height of the sprite.
LD C, A; organize a counter height.
SETSPR1 LD B, (IX +0); Put in B the first byte of the sprite.
LD E, (IX +1); E put in the second byte of the sprite.
EX AF, AF '; Register A indicates how to
; To move.
LD D, A
EX AF, AF '
LD A, D
LD D, 0
AND A; A check for zero.
JR Z, SETSPR3; If A were 0, then the shift is not
necessary. SETSPR2 SRL B; Move the sprite to the desired peak us
; Mudflow.
RR E
RR D
DEC A; decrements shifts.
JR NZ, SETSPR2; If A is not 0, continue to shift.
SETSPR3 PUSH HL; Store temporarily HL.
LD A, (HL); impose the first byte of the screen.
OR B
LD (HL), A
INC L; proceed to the next byte.
LD A, L; check, not out there beyond the right edge
; Screen.
AND # 1F
JR Z, SETSPR4; If left, then continue to impose no
; Necessary.
LD A, (HL); If you have not yet reached the edge, then
, Imposes the second byte of the
sprite.
OR E
LD (HL), A
INC L
LD A, L; checks again on the way out of the screen.
AND # 1F
JR Z, SETSPR4
LD A, (HL); impose the third byte, if he was
, Gives off the screen.
OR D
LD (HL), A
SETSPR4 POP HL; Restore HL.
CALL DOWN; proceed to the next pixel line
; The screen below.
LD A, H; check, did not come out if the lower boundary
; Nice sprite on the lower edge of the
screen.
CP # 58
RET NC; If you went out, then print and then not have to
; Exit.
INC IX; turn to new data from a sprite.
INC IX
DEC C; decrements height.
JR NZ, SETSPR1; If the sprite is not yet published,
continued ; Isplay.
RET
-------------------------------------- 3 (C) 1993 Inforkom
(Applied Graphics) --------------------------------------
ADRPIX LD A, E; Calculate the address on the screen. Coor
; Coordinates given in pixels - EY, DX.
AND A
RRA
SCF
RRA
AND A
RRA
XOR E
AND # F8
XOR E
LD H, A
LD A, D
RLCA
RLCA
RLCA
XOR E
AND # C7
XOR E
RLCA
RLCA
LD L, A
RET
ADRSPR DEFW 0; stores the address data sprite.
LENHGT DEFW 0; Stores the length and height of the sprite.
CRDS DEFW 0; Coordinates print sprite.
2
The program has received a relatively quick, but it has
reserve to improve. If
use of alternative registers, the size of a sprite can
increase.
Now consider, how to print the program mask
is not enough to change the OR
by AND. Firstly, in the case D
instead of 0 has to enter 255;
Second, some change
command shift. Team SRL B
puts in 7 bits are always 0, but
printing mask there shall be placed 1. Such teams do not
(To be precise, these teams have, but they are
undocumented. But such
command is available only to shift
to the left.), and we need to perform their emulation:
SETSPR2 SCF
RR B
RR E
RR D
DEC A
JR NZ, SETSPR2
In this case we are forced to include a flag C (carry flag),
and the command RR B puts it in 7-bit register B.
Why we were compelled to perform all these actions? All
very simple: if you remember
action commands AND, you'll find that on the screen are cleared
where the mask bits are
off, so instead of 0 we
puts 255 (11111111 = 255)
so as not to have effect, which can be observed in direct
copying the sprite to the screen.
Yes, the point with 0,0 in the upper left corner of the screen,
not as in BASIC, pay attention.
Apparently, when printing a sprite
mask you have to choose
format of the sprite and mask such
to ensure the highest print speeds.
Now let's move on to
the second method in print. At first I
wrote that the buffer size is directly proportional to the size
of the sprite, but at the last moment I was struck a good idea,
and I turned out to print a sprite
unscathed, with this
approach, a sprite the size of the screen will need a buffer
length 33 bytes. So you see, is always worth
sit and think, never
should dwell on one
idea. Your attention will be
proposed a "new" version of the program print using
buffer. Data for printing are prepared similarly to the
previous procedure.
The speed of this procedure
relatively normal. The program is described as a set of
procedures, but I would recommend to disclose these procedures,
as this increase the printing speed. I printed the sprite size
2 familiarity in length. 140.
SETSPR LD DE, (CRDS); We take the coordinates of the press.
CALL ADRPIX; calculate for him the address on the
screen.
LD A, D; Take the number of bits in a byte. Vposledst
; Dance with the aid of it we will
organize by ; Snip.
AND 7
EX AF, AF '; Replace A on the alternative.
LD IX, (ADRSPR); In the IX data address sprite.
LD A, (LENHGT +1); In A put the height of the sprite.
LD C, A; B C organize a counter height.
SETSPR1 PUSH BC; Save the counter.
PUSH HL; Save the address on the screen.
CALL SPRBUF; We transfer the current line of the sprite
in the bu ; Fer.
EX AF, AF '; check bit to 0 if zero, the motion
; Causeway buffer is not necessary.
LD B, A
EX AF, AF '
DEC B
INC B
JR Z, SETSPR2
LD C, B; in C Counter organize shifts.
CALL ROLBUF; Move buffer.
SETSPR2 CALL PRNBUF; We print buffer.
POP HL
POP BC
CALL DOWN; Go to the next pixel line
; The screen below.
LD A, H; check the output of the lower edge of the
equivalent ; Wound.
CP # 58
RET NC; Exit if out on the edge of the screen.
DEC C
JR NZ, SETSPR1; If C is not 0, continue typing.
RET
SPRBUF LD DE, BUFER; In DE address of a buffer in memory.
LD A, (LENHGT); organize meter in length.
LD B, A
SPRBUF1 LD A, (IX +0); Copy data to clipboard.
LD (DE), A
INC IX
INC DE
DJNZ SPRBUF1
XOR A; Before we zero D, here we obnu
; Trolled additional bytes (the buffer
; Greater than the length sprite on 1
byte).
LD (DE), A
RET
ROLBUF EX DE, HL; To increase speed, we will address
; Schrieffer record in the HL, and
data from the HL time ; Simultaneously
transfer to the DE. ROLBUF1 LD HL, BUFER
LD A, (LENHGT); organize meter length.
LD B, A
INC B; Because the buffer is larger than the sprite
, At 1 byte, then the counter is
incremented by
, 1.
AND A; Zeroing flag C.
ROLBUF2 RR (HL); Move the buffer.
INC HL
DJNZ ROLBUF2
DEC C
JR NZ, ROLBUF1
EX DE, HL; Restore the value of HL.
RET
PRNBUF LD DE, BUFER; in DE buffer address.
LD A, (LENHGT); organize a counter length sprite.
INC A; Again, it increased by 1.
LD B, A
PRNBUF1 LD A, (DE); impose a sprite on the screen.
OR (HL)
LD (HL), A
INC DE
INC L
LD A, L; Check out for the right border
; Screen
AND # 1F
RET Z; If you went abroad, stop ne
; Chat.
DJNZ PRNBUF1
RET
ADRSPR DEFW 0; stores the address data sprite.
LENHGT DEFW 0; Stores the length and height of the sprite.
CRDS DEFW 0; Stores coordinate print.
BUFER DEFB 0,0,0; this buffer. In this case, only 3
; Bytes, because we printed a sprite
; Familiarity of 2 in length.
2
At this procedure ends. Sharpens your attention
on the fact that the buffer size is equal to
length (the length is not in the sense that
that the size of the sprite, and refers to the size of the
sprite in long) sprite plus 1 byte. To print this way the mask,
you will need to last byte buffer is not null and bring back
255, and the team at AND A procedure shift the sprite is
replaced by SCF.
About the attributes of sprites, I purposely did not mention
then you yourself have to think, speculate, because here the
so-called kleshing, and other difficulties.
I mention yet another way to print the sprite
pixels, which was used
in older programs western
programmers. Its essence is that, at one stroke you draw
sprites 8 sprites with the only difference being that figure in
the sprite every time shifted by 1 pixel. Well,
Printing selected the desired
sprite.
Another article went to
his finale.