Programming - Displays a sprite on the screen. Conclusion on the virtual screen.
Programming Fundamentals
We begin a series of publications on the basics
programming. Today is the first article.
FAST, and not very fast graphics.
In the life of every programmer comes
moment when he seemed to know assembler,
trying to write something with
moving sprites, using procedures
Type this:
LD HL, SPRDTA; Address sprite HL
LD DE, # 808, coordinates the output of D - on the Y in
E - for X
LD BC, # 809; height of the sprite in the sprite in the
length of B C.
, Height, length and position - text
JP SPROUT; Output the sprite on the screen
SPROUT LD (SPROUT1 +1), HL; reserve the right data
LD A, B
LD (SPROUT2 +1), A
LD A, D; fill in the address table starting
ADD A, B; from the bottom of the screen
DEC A
LD D, A
SPROUT3 LD A, D; is calculated e
LD H, A; The row, which is given
RRCA; in register A
RRCA; 3 teams RRCA
RRCA
AND # E0
ADD A, E; add an offset X
LD L, A
LD A, H
AND # 18
OR # 40
ADD A, 7, adding the Y offset
LD H, A; 7 (tk fill in below)
PUSH HL; hammered stack addresses
DEC H
PUSH HL
DEC H
PUSH HL
DEC H
PUSH HL
DEC H
PUSH HL
DEC H
PUSH HL
DEC H
PUSH HL
DEC H
PUSH HL
DEC H
DEC D; reduce coordinate
DJNZ SPROUT3
SPROUT1 LD HL, 0000 here is the address sprite
LD A, C
EX AF, AF '
SPROUT2 LD A, 0; here is the height of the sprite
SLA A; multiplied by the number of bytes in the symbol
SLA A
SLA A
LD B, 0
SPROUT4 POP DE; remove the address output from the stack
EX AF, AF '
LD C, A
LDIR; derive sprite
EX AF, AF '
DEC A
JP NZ, SPROUT4
RET
No, I do not want to say that procedures such as
This is not needed: they are very much needed when
derivation of static images. But to
on the screen was a lot of moving sprites
and the image is not pulled, used
such cunning tricks as output to
virtual (invisible) screen, or
procedure fast graphics (for the output
moving images, under which
virtual screen will have a lot) ...
Well, consider for a start, the first
method, since it includes the second.
The essence of the image output by
virtual screen is the fact that
First, we allocate the memory under
screen size is equal to izmenyayucheysya
Part spekovskogo screen (only all
lines there are sequentially - ie,
the zero line at the address SCRADR, first with
Address SCRADR + length of the screen horizontally
and so on and so forth), in games - this game
field, there, using procedures similar to
the previous one, put a background, then articles, and
Finally, the characters, the shadow screen is very
rapidly excreted in the normal (with
special procedures), usually the output
carried out in the processing procedure
interrupts. Now more about the procedures
O virtual screen: UIS nasty
You can do as much in three ways -
Firstly, by using the LDI, secondly, by using the POP and PUSH
and, thirdly, by using the POP HL and
LD (ADR), HL. A tepericha all in order ...
Derivation of the first method is carried out
using procedures such as:
; LOGIN:
; HL - ADDRESS table is populated ZAPTAB
; DE - VIRTUAL SCREEN ADDRESS
; B - SCREEN SIZE VERTICAL
; In the text COORDINATES
; OUTPUT: NO
OUTSCR LD (OUTSP +1), SP; save SP
LD A, B; multiply B by 8
SLA A
SLA A
SLA A
DI; disable the interrupt, since working with
LD SP, HL; stack table in SP
EX DE, HL
OUTSCR1 POP DE; take the address of the output and display
DUP 20; SIZE screen horizontally
LDI; In the text COORDINATES
EDUP; DUP 1920 - LDI repeat 20 times
; Teams DUP n and EDUP, in the
corresponding XAS'e ; Exist commands
ASSM! n and CONT!
DEC A; and EDUP - the end of the fragment that
JP NZ, OUTSCR1; repeat
OUTSP LD SP, 0000
EI; allow interrupts
RET
To operate this procedure, you must
to fill a table containing addresses
O on the real screen (not to
calculate them). This can be done next
procedure:
; FOR ENTRY:
; HL - ADDRESS OF TABLES
; D - top line
; E - left column
; B - HEIGHT OF SHADOW SCREEN
; All the coordinates - Text
; OUTPUT: NO
ZAPTAB LD A, D
LD C, A
AND A
DUP 3
RRCA
EDUP
AND # E0
ADD A, E
EX AF, AF '
LD A, C
AND # 18
OR # 40
EX AF, AF '
LD C, A
EX AF, AF '
DUP 8
LD (HL), C
INC HL
LD (HL), A
INC A
INC HL
EDUP
INC D
DJNZ ZAPTAB
EI
RET
Yes, again: These procedures are designed for output
virtual screen size 20x20. For
In order to change the size of the displayed
images, you need to modify the procedure
O: Zamesto DUP 20 (repeat 20 times)
put the DUP NN, where NN screen size
horizontally, and the input register values.
Example of Table:
LD HL, TABLE; HL - Address tables
LD DE, # 101; D - coordinate for Y, E - X coordinate of
the
LD B, 20; screen size vertically
CALL ZAPTAB; fill the table
An example of a procedure call output:
LD DE, SCRADR; DE - address of the virtual screen
LD HL, TABLE; HL - Address tables
LD B, 20; B - the size of the screen vertically
CALL OUTSCR; call the procedure output
We will show the same screen with the help of
commands PUSH and POP. This will require
procedure such as this:
; LOG HL - address on the virtual screen
; DE - ADDRESS TO THE REAL SCREEN
; A - High Byte Next THIRD
; REAL SCREEN
; B - HEIGHT displayed image
, (In pixels)
OUTSCR PUSH IY
LD (OUTSP +1), SP; save SP
DI; not necessarily prohibit the interruption
, There is a possibility of death
LD (SEGSTOP +1), A
LD A, B
LD (NUMOF +1), A
LD (OUTSCR1 +1), HL
LD HL, # 114, shift down 1 and right
, At 20, since the recording is a team
; PUSH, and the shift down 1 is a
transition
; To the next line
LD (OUTSCR3 +1), HL
LD H, 0; starting position - down 0
; Right - 20 is the length of the
virtual screen
ADD HL, DE
LD (OUTSCR2 +1), HL
OUTSCR1 LD SP, 0000 here is the address in the virtual screen
POP HL; take the data
POP BC
POP DE
POP AF
EX AF, AF '
EXX
POP HL
POP BC
POP DE
POP AF
POP IX
POP IY
LD (OUTSCR1 +1), SP; remember where you left off
OUTSCR2 LD SP, 0000 there will be an address on the real screen
PUSH IY; put data
PUSH IX
PUSH AF
PUSH DE
PUSH BC
PUSH HL
EXX
EX AF, AF '
PUSH AF
PUSH DE
PUSH BC
PUSH HL
OUTSCR3 LD HL, 0000, move down and right
ADD HL, SP
LD A, H; 8 lines already laid
SEGSTOP CP 00; here next byte-thirds
; Real screen
JR C, OUTSCR4; if not then the rest
LD DE, # F820; actually # F820 + HL = HL-# 800 + # 20 go
; To the next character string
ADD HL, DE
OUTSCR4 LD (OUTSCR2 +1), HL; put the address from where there
have NUMOF LD A, 0, height is the sprite in pixels
DEC A
LD (NUMOF +1), A
JP NZ, OUTSCR1; if you did not ask then we deduce
OUTSP LD SP, 0000 restoring the stack pointer and
POP IY; goodbye
EI
RET
The procedure is not perfect, and
written only to some
show still funny. Namely, the speed
O distigaetsya here due to the withdrawal
of two bytes (Team POP and PUSH).
And here is an example of calling it (shown
suffering a virtual screen 20x20)
in the upper left corner:
LD HL, SCRADR
LD DE, # 4000
LD A, # 48
LD B, 64, 8 * 8 = 64
CALL OUTSCR
LD HL, SCRADR + # 500, # 500 = 64 * 20 = 1280
LD DE, # 4800
LD A, # 50
LD B, 64
CALL OUTSCR
LD HL, SCRADR + # A00; # A00 = # 500 + # 500
LD DE, # 5000
LD A, # 58
LD B, 32, 8 * 4 = 32
CALL OUTSCR
, Or in a position with coordinate X = 1, Y = 2 (coordinates in
the text)
LD HL, SCRADR
LD DE, # 4041
LD A, # 48
LD B, 48, 6 * 8 = 48
CALL OUTSCR
LD HL, SCRADR + # 500, # 500 = 64 * 20 = 1280
LD DE, # 4801
LD A, # 50
LD B, 64
CALL OUTSCR
LD HL, SCRADR + # A00; # A00 = # 500 + # 500
LD DE, # 5001
LD A, # 58
LD B, 48, 8 * 6 = 48
CALL OUTSCR
However, when the size of the screen virtualnogo
32xNN in text coordinates, faster
will be working procedure based on
teams POP HL, LD (ADDR), HL. However, it
has nemeryanye (large) size, and
fill it in assembly language would
tedious, so for its manufacturing
Use the following procedure:
; LOGIN:
; HL - address of a procedure OUTPUT
; D - TOP POSITION ON Y
; E - LEFT POSITION ON X
; B - HEIGHT Virtual Screen
, (In the text coordinates)
; C - LENGTH OF VIRTUAL SCREEN / 2
, (Also in TEKSTVYH coordinates)
; OUTPUT: NO
MAKOUT LD (HL), # 21; LD HL, 0000 Save the stack pointer
XOR A
DUP 2
INC HL
LD (HL), A
EDUP
INC HL
LD (HL), # 39; ADD HL, SP
INC HL
LD (HL), # EB; EX DE, HL
INC HL
LD (HL), # F9; LD SP, HL
INC HL
MAKOUT1 PUSH DE
LD A, D; calculate the real address on the screen
DUP 3
RRCA
EDUP
AND # E0
ADD A, E
LD E, A
LD A, D
AND # 18
OR # 40
LD D, A; in DE - Address
LD A, 8, 8 bytes in the symbol
MAKOUT2 PUSH BC; stored for subsequent cycles
PUSH DE
MAKOUT3 LD (HL), # E1; POP HL
INC HL
LD (HL), # 22; LD (ADDR), HL
INC HL
LD (HL), E; ADDRESS
INC HL
LD (HL), D
INC HL
INC E
DEC C
JR NZ, MAKOUT3; fill line
POP DE
POP BC
INC D
DEC A
JR NZ, MAKOUT2; fill eight rows
, Which in one symbol
POP DE
INC D
DJNZ MAKOUT1; fill D characters
LD (HL), # EB; EX DE, HL
INC HL
LD (HL), # F9; LD SP, HL
INC HL
LD (HL), # C9; RET
RET
And this makes the procedure at HL
procedure for rapid withdrawal. Here's an example
constructing a table to display the virtual
Screen size 20x20 to the real screen
position X = 2, Y = 1:
LD HL, SPEED; Address Procedure
LD DE, # 102; D = Y, E = X
LD BC, # 1414; B = 20, C = 20
CALL MAKOUT
Tepericha, will give an example of resorting to this
Procedure:
DI; sure to forbid interrupts
LD DE, SPRADR; in DE address of virtual screen
CALL SPEED; derive this thing
EI; All are free, and break too
Actually, from the procedures outlined here,
This is best suited for O
large image (it has the greatest
efficiency), but it has a substantial
disadvantage - for each of bytes
in the process of withdrawal has two!
That's all that I wanted to say.
The next time I will tell you how distorting
with the latter procedure can be obtained
cool effects.
P.S. All assembler listing are given in
format assembler ALASM, and the only
possible incompatibility with other
assembler is a command DUP nn,
means an area bounded by the DUP and
EDUP nn must be repeated again ...
All these procedures can be found in Appendix
to the newspaper, they are in text format and can easily
convert into any assmov.
Bye!
(C) Ilya Trusov (500:812 / 08.19)
Other articles:
|
|
|
|
|
|
|
|
Programming - Displays a sprite on the screen. Conclusion on the virtual screen.
|
|
|
|
|
|
|