(C) ROM corp. / VVG, 1997
----------------------
Fast graphics.
I have long wanted to talk about
chart SPECCY, and not just about graphics, and a rapid
schedule, which is used in
most music DEMO,
as well as many brand
toys. In this article I want to
offer a somewhat different approach to these issues.
1: Application of the method table
Programming for printing
sprites.
2: Use a stack to print
clear the screen. By cleaning
here defined as any action leading to refreshment
screen memory, including
filling the screen sprites
any format, create all sorts of reticula, etc.
So now more about
all of this. I will not give
here all the listings of which
will be discussed, since all
it's pretty transparent, but
key points will be discussed in detail.
1.PECHAT Sprite
All attempts to create a quick procedure for printing a
sprite classical method is doomed
to fail because of monstrous
the slow work of the calculator
address on the screen. What to do? Comes to the aid table
method of programming. Suppose that somewhere in the memory is
a table of addresses of all lines screen, then how to print
sprite looks like this:
PRINT_SPRITE
LD H, 0; HL PUT Y coordinates
LD L, YCOORD; OUR Sprite
, (In pixels)
ADD HL, HL; Multiply it by 2
, AS E-Mail address
2 bytes, then to multiply
; By 2 to give
; OFFSET from the top
; TABLES
LD DE, DATA; In DE-TOP TABLES
S address
ADD HL, DE; ADD
LD (STACK), SP; SAVE STACK
; In VARIABLE
LD SP, HL; rearrange the stack on
, Address table
LD A, LINES; In A-HEIGHT Sprite
; In pixels
; PREPARATORY operation is over,
; NOW BEGINS own stamp
LOOP LD BC, XCOORD; In BC-X coordinate
; Sprite from the left edge
; SCREEN IN familiarity
POP DE; HERE this team and
; Select address FROM
; TABLES
EX DE, HL; Tracing X
ADD HL, BC; COORDINATES
EX DE, HL;
LDI; transfer LINE Sprite
LDI; IN SCREEN TEAM
; LDI FASTER THAN LDIR
... ; TO 5 cycles per byte
; Number of teams
LDI; LDI equal to the width
, Sprite
DEC A; DECREASE COUNTER
JR NZ, LOOP; LINES AND TRANSITION
LD SP, (STACK); RECOVERY STACK
RET; RETURN
Now let's see what
us a cost: 384 bytes
plates and a little LDI, but
but: print independent of
familiarity and segments of the screen,
has the highest rate:
calculation of addresses (or, more sampling) of 39 cycles.
NOTE: if X is 0,
You can delete rows from the change in X (which can be used
with scroll-e of the screen).
Print takes the following form:
POP DE
LDI
LDI
...
LDI
LDI
You can go even further and
open cycle in A, s'ekonomiv
17 more strokes on the line. In this
option to spend 16 bytes
cycles and plus 10 (POP DE) divided by the width of the sprite.
In total, average about 20 cycles per byte.
You may ask: how
the seal up to a horizontal pixels? The answer is:
can be up to the pixel, but again with
a little trick. We will
print sprite up
pixel familiarity. You
say: what nonsense! So
cause there is! The idea is to
creation of eight phases of our
sprite with a shift to one
pixel and print each of the
them up to familiarity.
The algorithm is as follows: take
X, in pixels, divided by 8.
Private is the X coordinate in the
familiarity, and the remainder is the number of phases of our
sprite with a corresponding shift, and further just print
already familiar to us protsedurkoy
Now about how to create
plate addresses. I will not
result in listing, it is not complicated, and will describe the
algorithm: take any procedure for calculating the address in
pixels (I used procedure from the elementary diagrams). Next, a
loop from 0 to 191. Compute the address and records
table, we increase the pointer
current element by 2 and repeat all over again. By the way,
the same plate can be used for any transactions
screen
2.OSVEZHENIE SCREEN AND reticula
To ensure the smooth graphics to refresh the screen
50 times per second. For this purpose, a nice way stack
printing method. He There are many varieties.
Consider some of them.
1: Cleaning the Screen
LD A, 0 (XOR A); Zeroing BATTERY
LD H, A; FILLS HL BATTERY
LD L, A; (although you can use
; ANY Distinctive PAIR)
PUSH HL; REPEAT AS MANY PUSH
... ; Times as you want
PUSH HL; for complete cleaning
Instead of 0 you can send any
another byte and receive all sorts of stripes on the screen.
3.SETOCHKA 8x8
From the previous paragraph can easily obtain a variety of
meshes in full screen, which
so love to use in demah. The idea is: take
spraytik 8x8 pixels, and the late start is displayed on the
screen, line by line. There are several ways to implement this
effect, we consider one of them. Let there is some spraytik
8x8pix, our task is to fill their screen.
LD IX, SPRITE; pointer to sprite
LD (STACK), SP; SAVE SP
LD SP, 22528; rearrange SP at the end DISPLAY
LD H, (IX +7); HL FILL IN THE LAST
LD L, H; BYTES Sprite
PUSH HL; PUSH HL REPEATS 128
... ;> TIME TO FILL ALL
PUSH HL; / BOTTOM LINE SCREEN
LD H, (IX +6); FILL HL penultimate
LD L, H; BYTES
PUSH HL;
... ;> PUSH HL * 128
PUSH HL; /
; REPEAT ALL FOR IX +5, IX +4,
... ; IX +3, IX +2, IX +1
LD H, (IX +0); And FOR IX +0
LD L, H;
PUSH HL;
... ;
PUSH HL;
; Lower segment ZAPOLNEN.TEPER NEED
; TO REPEAT THE ENTIRE TEXT OF LD H, (IX +7) TO
; END 2 more times TO FILL THE REST
; SEGMENTS OF THE SCREEN
LD SP, (STACK); LATE TO RESTORE THE STACK
RET; AND RETURN TO RET
Here, the fixed mesh
on the screen. And how to make it
move? Very simple: we must
create a block sprites containing motion phase of mesh
screen. In this case (8x8)
this is normal font,
created in ARTSTUDIO or
another editor. Algorithm
motion to file sprites
(Fonts) is very similar to the beginning of the routine
character 8x8:
LD A, NUM; NUM-IS CURRENT ISSUE
, Sprite
LD XH, 0; DOWNLOADED THROUGH IX suboxide
LD XL, A; MENTIROVANNYE TEAMS
; To expedite the process
ADD IX, IX; MULTIPLICATION BY 8
ADD IX, IX;
ADD IX, IX;
LD DE, SPRITES; Tracing the start address
ADD IX, DE; FILE Sprite
Received in IX address is used in the previous procedure.
Now I would like to say
on how to get the file
phases of movement. The first and most obvious, but the most
time-consuming it is to draw them
(Phase) in a photo editor. And the second - is to generate it
during the installation program. Consider the idea of
installation details. In the steepest option is
will look like this: there
some two-dimensional function (although
The same sine wave), the program
computes the schedule and records
him to sign. Next, the program performs the conversion
plate mod 8, and simply leaves instead of the full
coordinates of the remainder of the division
it to 8. Next step: the formation of a set of sprite
(Font): take the initial
sprite rotates (!) X times
right, Y down again and recorded
on a regular place in the table.
You can create multiple functions and multiple sets
sprites, and can be combined
them on the OR or other logical operations for
reticula with several plans
motion (for example: two grids: one moves up and
other diagonally down). Here
and is ready to mesh, but if you
try to start it, even
through HALT then you have nothing
good would come (although the whole
Printing takes about half
INTa (30000 cycles) because of the intersection of the ULA and
the fill stack. Helps out a second screen (128-x models). His
incorporation takes place almost instantaneously, and this
provides the desired effect.
LOOP LD BC, 32765; CONNECT THE SECOND PAGE
LD A, 23; screen when you turn
OUT (C), A; FIRST SCREEN
CALL PRINT; PRINT
HALT; TIMING
LD BC, 32765; CONNECT THE FIRST PAGE
LD A, 21 +8 Vågå screen when you turn
OUT (C), A; second screen
CALL PRINT; PRINT
HALT; TIMING
JR LOOP;
That's two screen technology.
On this matter can be hung
music, sprites, and also that
anything, but we need to monitor
execution time so that it
not surpassed 1 INT. A couple more
Note: If used
Sprites, the address sign
necessary to generate a
address of 49152 rather than 16384, for
IM2 using vector
interrupts must be below
49152, and if higher, then it should be duplicated at all
used pages. Music is also desirable to be
is below 49152, and if
You want to put it on
page, you have to memorize the number of port 32765 and not
switch screens for the time
playing music.
2: mesh 16x16
LD IX, SPRITE; pointer to sprite
LD (STACK), SP; SAVE SP
LD SP, 22528; rearrange SP at the end DISPLAY
LD B, (IX +31); In BC Get the latest and
LD C, (IX +30); penultimate BYTES Sprite
LD D, (IX +15); AV DE two bytes FROM THE MIDDLE
LD E, (IX +14); Sprite: 15 AND 16
PUSH BC * 16 * 4; draw LOWER AND MIDDLE
PUSH DE * 16 /; Sprite LINES IN ONE
; Third of the screen
LD B, (IX +29); REUPLOAD Distinctive
LD C, (IX +28); couples Sweep PER
LD D, (IX +13); LINE UP
LD E, (IX +12);
PUSH BC * 16 * 4; draw another 2 LINES
PUSH DE * 16 /;
... ; BE continues to shift
; UP AND DRAW
; ON TWO LINES
LD B, (IX +17); and, finally, Loads
LD C, (IX +16); Distinctive PAIR OF BYTES
LD D, (IX +1); FROM THE MIDDLE AND FROM THE BEGINNING
LD E, (IX +0); Sprite
PUSH BC * 16 * 4;
PUSH DE * 16 /;
, ALL, one-third draw, It now remains
; REPEAT IT ALL STILL ON THE TEAM 2 times
; LD B, (IX +31) to finish.
LD SP, (STACK)
RET
By the time this mesh
is almost the same
as the previous one is 30000 cycles. All of the above about the
movement and the establishment phase applies to this species
effect, but creation function of the movement, it is necessary
to take the remainder after dividing by 16, not 8, as in
previous case. I must say that it's pretty versatile way to
print on the screen. If you understand the principle of the
above effects, then you will easily modify them to other
dimensions: 3x3, 4x4, 2x4, etc.
In conclusion I would like to receive
feedback on this material, and
also offers help and
cooperation on all issues related to programming ASSEMBLERe.
My address is:
394016, Voronezh
UL.TULSKAYA, 16
Nasonova RA
(ROM CORP.)