╔═---- ------ ----- --
║ ##########Несколько способов ###### |
| ##############облегчить########### |
| #############себе жизнь.######### ║
-- ---- ------ ---------═╝
HIGHLANDER, Infotek.
E-MAIL: м14369@chat.ru
То, о чём пойдёт речь не является истиной
в последней инстанции, и не рассматривает-
ся как руководство к действию, каждый
должен сам определять необходимость при-
менения того или иного метода в своих
программах и разработках.
Не побоюсь утверждать, что каждый начи-
нающий кодер неI came across one once
right: the program works slower,
sprites (not in bottles) about how you fell asleep, etc.
There can be many reasons, starting with
on what is this creation written, ending
as it is written (clinical cases after
Uncle Billy's investigators are not considered,
they have it that way).
I'll start with the so-called "open loops"
if anyone hasn’t understood yet, I’ll give an example,
in the comment field - the duration of the command
in Z8O clocks:
: A piece of the printing procedure that
: prints a letter on the screen
: (up to familiarity)
: HL - address on screen
: DE - address of the letter in the font
:
LD В,8 : 7
LOOP LD A,(DE) : 7
LD (HL),A : 7
INC DE : 6
INC H : 4
DJNZ LOOP : 8/13
Немного математики не помешает,
7+7*(7+7+6+4+13)+7+7+6+4+8=298 тактов,
а если раскрыть цикл, получим:
LD A,(DE) : 7
LD (HL),A : 7
INC DE : 6
INC H : 4
LD A,(DE) : 7
LD (HL),A : 7
INC DE : 6
INC H : 4
LD A,(DE) : 7
LD (HL),A : 7
INC DE : 6
INC H : 4
LD A,(DE) : 7
LD (HL),A : 7
INC DE : 6
INC H : 6
LD A,(DE) : 7
LD (HL),A : 7
INC DE : 6
INC H : 4
LD A,(DE) : 7
LD (HL),A : 7
INC DE : 6
INC H : 4
LD A,(DE) : 7
LD (HL),A : 7
INC DE : 6
INC H : 4
LD A,(DE) : 7
LD (HL),A : 7
Путём несложных расчётов получим:
7*(7+7+6+4)+7+7=182 такта, что на 38.926%
быстрее, если учесть, что в строке 32
символа, получим экономию 3712 тактов,
неплохо, неплохо... Но воистину програм-
мист от бога заметит, что первый вариант
в памяти занимает 8 байт, а второй - 3O.
Из этого вытекает маленькая аксиома:
"The speed of the program is directly proportional to
is proportional to its size."
By the way,LDIR (LDDR)cyclic command,
and LDI (LDD) no, then everything is stated above -
The same can be applied to them:
LD HL,#COOO : from
LD DE,#ХОOO : where
LD BC,#OOO8 : how much
LDIR : 21/16 clock cycles per
: each byte
LDIR sends one byte per 21 clock cycle,
ifВС<>O or for 16, if ВС=O. Replacing
LDIR to LDI we get the following:
LD HL,#COOO : from
LD DE,#ХОOO : where
LDI :
LDI : every
LDI :
LDI : LDI
LDI :
LDI : 16 clocks
LDI :
LDI :
Moreover, the number of repetitionsLDIis equal to the number
which was sent toBCwhen used
LDIRa.
This way you can overclock the program
quite noticeable, but not worth it
abuse, your memory is not great,
may not be enough. I advise you to disclose those
cycles that are often caused by headaches
program.
Next on the agenda is the question of
"fast graphics",technique that allows
carry out data movements (not required)
preferably graphic) at a speed higher
LDIRditch and LDIshek.
╔══════════════════════════════╗
║╔--- ---══--- ---╗║
║|+--------------------------+|║
║ | ATTENTION | ║
║ | SO THAT IT DOES NOT ARISE | ║
║|| CRITICAL SITUATIONS ||║
║║|BEFORE APPLYING PROCEDURES|║║
║|| ИСПОЛЬЗУЮЩИХ СТЕК ||║
║ | ПРЕРЫВАНИЯ ДОЛЖНЫ БЫТЬ | ║
║ | ЗАПРЕЩЕНЫ!!! | ║
║|+--------------------------+|║
║╚--- ---══--- ---╝║
╚══════════════════════════════╝
Суть метода в использовании стека не по
прямому его назначению. Теория: команды
PUSH или POP кладут на или снимают с вер-
шины стека два байта, вроде бы в этом нет
ничего особенного, если не одна деталь,
PUSH - 11 тактов, а POP - 1O. But how is it
use? Elementary, Watson, place-
We place a stack at the beginning of the data and POPathese
we take the data itself, and what we want, then
barking. Something like this:
LD (SAV_SP+1),SP : save SP
LD SP,#COOO : stack to the desired
: address
POP HL : 2 bytes taken
LD (#ХОOO),HL : wherever it is needed, there
: and put
POP HL : next
LD (#ЧOO2),HL : 2 байта
......
POP HL : последние
LD (#SAFE),HL : 2 байта
SAV_SP LD SP,#OOOO : восстанавливаем
: SP
Снова математика: POP HL и LD (NNNN),HL
выполняются 1O+16=26 тактов и пересылают
два байта, а два LDI - 32 такта, как гово-
рится, результат на лице, получается 13
тактов на байт, но при этом необходимо,
чтобыthe data array was a multiple of two (if
this is a sprite, then its width is a multiple of two), I
I think this is a small price to pay for the speed
grow.
It seems like there’s no way to accelerate anymore, but
it's not like that, it's possible a little, but that's only
on large arrays:
LD (SAV_SP+1),SP : save SP
M1 LD SP,#COOO : from
POP HL
POP DE
POP BC
POP AF
EXX
EX AF,AF'
POP HL
POP DE
POP ВС
POP AF
LD SP,#4O1O : куда
PUSH AF
PUSH ВС
PUSH DE
PUSH HL
EXX
EX AF,AF'
PUSH AF
PUSH ВС
PUSH DE
PUSH HL
М2 LD SP,#CO1O : следующий
POP HL : блок данных
........
PUSH DE
PUSH HL
SAV_SP LD SP,#OOOO : restoring
: SP
If you count the number of measures between met-
kamiM1 and M2,then we get 2O4 tact, and
16 bytes will be copied, with a slight movement from -
vilin we get: 12.75 cycles per byte !!!
It can't be faster if someone comes up with it
faster way, let me know,
I will be very happy. But there is a little special
poverty, due to the fact that the stack grows
from top to bottom, this must be taken into account when
arrangement of addresses in the procedure.
Well, in order not to be unfounded, the procedure
quickly filling an attribute file with one
color:
: с применением LDIRa
LD HL,#58OO
LD DE,#58O1
LD ВС,#O2FF
LD (HL),ATRIBUT
LDIR
: ИТОГО: 16142 такта
Другой вариант:
: с применением "быстрой графики"
LD (SAV_SP+1),SP
LD SP,#5BOO
LD HL,#NNNN : в H и L код
PUSH HL : атрибута
PUSH HL : PUSH HL
........ : повторяется
PUSH HL : 384 раза
PUSH HL : (768/2=384)
SAV_SP LD SP,#OOOO
: ИТОГО: 4274 такта
На сегодня новостей больше нет, поэтому
всем большой гудбай.
The copyright is mine, and there is no point in changing it.
Share your thoughts about the article