__________________________________________
(C) KAPsoft '2000
__________________________________________
ON THE QUESTION...
In my short article I tried
highlight some issues that
encountered recently. Mostly
This material is intended for a programmer,
but it would do well for others to read him too.
...ABOUT CONVERSION
InDeja Vu #08there was an article about conversion
SCREEN's to text files. The idea was that
kova: counting the number of included
pixels (dots) in a block (8 by 4), and, in
depending on their quantity, we put one or
another symbol.
I propose a different algorithm. I'll describe it
briefly its essence. For the block in question
we superimpose in turn all the symbols of the loading
married FONT. Counting the quantity
matches (either on or off)
hatched pixels). The symbol that
If there are more matches, we put it instead of a block.
We repeat everything for the remaining blocks.
Yes, this will all work quite well
lazy. But the quality will be better.
Here is a listing of a program that performs this
what kind of conversion.
DEMO CALL START
LD A,2
CALL #1601
LD A,22
RST 16
XOR A
RST 16
XOR A
RST 16
LD BC,768
LD DE,TEXT
JP #203C
;
START LD HL,#4000
LD DE,TEXT
CALL ST1
LD HL,#4800
CALL ST1
LD HL,#5000
JP ST1
;
ST1 LD BC,256
LOOP PUSH BC
PUSH DE
LD DE,15616
LD B,96
XOR A
LD (NUM+1),A
LD (NUP+1),A
DEC A
LD (RAZL+1),A
N_4 PUSH BC
LD C,0
PUSH HL
LD A,8
N_2 PUSH AF
LD A,(DE)
XOR (HL)
LD B,8
N_1 RRA
JR NC,NO
INC C
NO DJNZ N_1
INC DE
INC H
POP AF
DEC A
JR NZ,N_2
LD HL,NUP+1
INC (HL)
RAZL LD A,0
POP HL
CP C
JR C,N_3
NUP LD A,0
DEC A
LD (NUM+1),A
LD A,C
N_3 POP BC
LD (RAZL+1),A
DJNZ N_4
NUM LD A,0
ADD A,32
POP DE
LD (DE),A
INC DE
POP BC
INC L
DEC BC
LD A,B
OR C
JR NZ,LOOP
RET
В программе есть некоторые интересные
приемчики.
Например, если у вас в прогах есть та-
кие строки:
LD (МЕТКА),A
...
LDA,(LABEL)
...
METKA DEFB 0,
then they can be replaced with:
LD (METKA+1),A
...
METKA LD A,0
That is. store variables in the text itself
programs.
The comparison is made using XOR-
bytes and counting included bits.Es-
whether the bits are the same (1-1 or 0-0), then after
XORs are 0, and if different, then 1.
Because we need differences, then we count
zeros with the command JR NC,S.
In this program, a block is one
familiar place, and comparison is made with the standard
standard SPECTRUM FONT, located
married in ROM.
This is just an example, a serious program for
to do more universally: various
block sizes, loaded FONT, etc.
...ABOUT ARROWS.
Or more precisely about arrow interfaces. In
of all the "intellectual" in-
interfaces (such that if you press for a long time
joystick in one direction, then speed
cursor - arrows increases) speed
increases in onedirection, and her
reset to initial occurs at any
joystick movement.
I propose a different algorithm. Speed
changes for four directions separately
but... If the user does not press in any way
direction, then the speed in this direction is
leniya is reset to the initial value.
Here's the listing:
ORG 30000
ENT
LD DE,#8080 ;Initial
START HALT ;coordinates
LD HL,TABL
IN A,(#1F) ;Interrogated the joystick
BIT 0,A ;Right ?
PUSH AF
LD A,#3C
LD (LOOP),A
LD A,#51
LD (SBROS),A
LD A,#57
LD (REG),A
CALL NZ,MOVE ;Да - двигаемся
POP AF
CALL Z,SBR ;Нет - сброс
BIT 1,A ;Влево ?
PUSH AF
LD A,#3D
LD (LOOP),A
CALL NZ,MOVE
POP AF
CALL Z,SBR
BIT 2,A ;Вниз ?
PUSH AF
LD A,#5F
LD (REG),A
LD A,#59
LD (SBROS),A
CALL NZ,MOVE
POP AF
CALL Z,SBR BIT 3,A ;Вверх ?
PUSH AF
LD A,#3C
LD (LOOP),A
CALL NZ,MOVE
POP AF
CALL Z,SBR
BIT 4,A ;Огонь - выход
RET NZ
LD C,D ;Рисуем точку с
LD B,E ;помощью программы
PUSH DE ;ПЗУ по адресу ┐
CALL #22E5 ; <────────────┘
POP DE
JR START
;
MOVE LD A,(REG) ;Подпрограмма
CP #57 ;перемещения
LD A,E
JR NZ,NEXT
LD A,D
NEXT LD C,(HL)
INC HL
LD B,(HL)
LOOM CP C
JR Z,SBROS
LOOP INC A ;или DEC A
DJNZ LOOM
REG LD D,A ;или LD E,A
INC HL
DEC (HL)
JR NZ,L_1
LD (HL),24 ;Время закончи-
DEC HL ;лось - увеличиваем
INC (HL) ;скорость
INC HL
L_1 INC HL
RET
;
SBROS LD D,C ;или LD E,C
JR CONT
SBR INC HL ;Сброс скорости и
LD (HL),1 ;времени на началь-
INC HL ;ные значения.
LD (HL),24
INC HL
RET
;
TABL DEFB 255,1,24 ;Первое - MAX/MIN
DEFB 0,1,24 ;Второе - скорость
DEFB 0,1,24 ;Третье - время
DEFB 175,1,24
Для упрощения вместо стрелки использу-
ется точка. Для того,to run fast
lock, instead of CALL #22E5 put a call
its arrow output procedure.
To make the point run faster, you can reduce
show the time value, but not in the table, but
in lines LD (HL),24 at the end of procedures MOVE
and SBROS. You can also increase the frequency of calling the process
fools (in this program - once in interruption -
or 50 times per second).
...ABOUT MULTITASKING.
As you know, Intel processors are
we can execute several programs simultaneously
exactly. In reality, of course, they are not
all work at once. Operating system
runs a small piece of one program
us, then a piece of another, a third. And pol-
it seems to the callers that they are all working
at the same time.
I came up with a (crazy?) idea -
try to create such a system using SPEC-
C.Y. In the first minute of thinking I stood up
problem:HOW TO INTERRUPT THE PROCESSOR AFTER NON-
WHAT TIME IS IT? On PC everything is simple: yes
special interruptions. So this would have sunk
the idea is in vain, if notmy second idea:
IM 2. But it is already used for polling
keyboards, music, etc.
What can you do, programs for such a system
the topic will have to be written specially. But that's how
they say, if he presses hard (you have to press hard)
children), then they will do it. Moreover, the tra-
takes up about 1% of CPU time. And you-
the call of Mouzon and others is carried out as without
systems, i.e. 50 times per second.
So, the idea:
* For each program, a personal
ny stack.
* The first one is connected and starts
first program.
┌>* When an interrupt arrives, the
│ there is a system that saves everything
│ processor registers on the stack are executed
│ of the program being used. She remembers
│ stack value in a special table
│ tse. The stack is connected for the next
│ task, the values of the re-
│ гистров и адрес запуска(или продол-
│ жения, если это не запуск).
│ * Запускается вторая программа.
└─┘
Вот листинг :
ORG 30000
ENT
DEMO DI
LD HL,KOL+1
LD (HL),3
LD HL,PROG2
LD (29022),HL
LD A,#7F
LD I,A
LD HL,INT
LD (#7FFF),HL
IM 2
EI
;
PROG1 LD A,#87
LD (#5800),A
LD A,#7F
IN A,(#FE)
AND #1F
XOR #1F
JR Z,PROG1
DI
LD A,63
LD I,A
IM 1
EI
RET
;
PROG2 LD A,#78
LD (#581F),A
JR PROG2
;
NUMB DEFB 0
TABL1 DEFB 0,1,0
TABL2 DEFW 0,29000
;
INT PUSH AF
LD A,R
PUSH AF
PUSH DE
PUSH BC
PUSH HL
PUSH IX
PUSH IY
EX AF,AF'
PUSH AF
EXX
PUSH DE
PUSH BC
PUSH HL
LD A,(NUMB)
LD E,A
LD D,0
LD HL,TABL1
ADD HL,DE
LD A,(HL)
ADD A,A
LD E,A
LD HL,TABL2
ADD HL,DE
LD A,L
LD (KK+2),A
LD A,H
LD (KK+3),A
KK LD (#FFFF),SP
;Здесь можно поставить вызовы ваших
;программ обработки прерываний
;типа CALL MYINT
LD A,(NUMB)
INC A
KOL CP 3
JR NZ,OBHOD
LD A,0
OBHOD LD (NUMB),A
LD HL,TABL1
LD E,A
ADD HL,DE LD A,(HL)
ADD A,A
LD E,A
LD HL,TABL2
ADD HL,DE
LD A,L
LD (LL+2),A
LD A,H
LD (LL+3),A
LL LD SP,(#FFFF)
POP HL
POP BC
POP DE
EXX
POP AF
AX AF,AF'
POP IY
POP IX
POP HL
POP BC
POP DE
POP AF
SUB 7
LD R,A
POP AF
EI
RET
Part DEMO - demonstration. The system itself
starts with NUMB.
How to use it?
1. Decide how many programs you need
but use it.
2.At the address KOL+1 enter this number:
LD HL,KOL+1
LD (HL),N
3. For each, allocate space for the stack.
4.At the address STACK+22 of each program
carry the address of its launch.
5.Create a table for calling tasks.
For example:
TABL1 DEFB 0
DEFB 1
DEFB 0
DEFB 2
DEFB 0
Where 0,1,2 are program numbers (corresponding
definitely 1st, 2nd and 3rd). With such
table 1 task is assigned 3/5*100=
=60% time. 2nd and 3rd - by 1/5*100=
=20% time.
6.In TABL2 enter the addresses of task stacks:
TABL2 DEFW STACK0
DEFW STACK1
DEFW STACK2
7. Set the address of the stereo in the SP register
for the first task:
LD SP,STACK0
8. Reset interrupts:
DI
LD A,#NN
LD I,A
LD HL,INT
LD (#NNFF),HL
IM 2
EI
9. Run the first program:
JP PROG0
Note:
If a way out of the tasks is envisaged
RET, then place it at address STACK+24 each
the next stack address of the exit program. This is mo-
There may be a procedure for disabling one task
from the system (replacing the number of this replacement in TABL1
dacha to a different number), or exit procedure
yes from the system:
DI
LD SP, standard value
LD A,63
LD I,A
IM 1
EI
RET
In the demo program there is one task -
cha draws a flashing square in the upper left
corner of the screenand polls the keyboard.Other
only draws a square in the upper right corner-
lu of the screen. When you press the space bar,
dit exit.
If you want to use Mouzon, op-
upgrade the keyboard or increase some
-or counters, place CALLs in the indicated
oh place.
Task restrictions:
1.Do not spoil memory occupied by other tasks
chami.
2.Do not change register I.
3.Before using extended memory
disable interrupts. Allow only
when the standard one is installed
configuration.
4.Do not prohibit interruptions for a long time.
Restriction '3' can be removed if the system
topic to organize a configuration check,
storing it on the stack and then
recovery.
...ABOUT ELECTRONIC MAGAZINES.
I, as an ordinary user, want
I would like to give a couple of comments for the production
tel of electronic magazines.
1.If you come up with some cool
trick and put it in the magazine header, then
describe it in a journal, or assembler
text into the application so that others can too -
whether to use it.
2.Expand the SAVE menu. For example, if in
there is a picture in the text, then add an item
SAVE SCREEN,if there is an assembly language
ting, then give the opportunity to unload it
immediately, not cutfrom the shipped stock
ty.
3.Give the opportunity to ship Mouzons, with
with or without a player.
That's all the criticism for now.
...ABOUT ADVERTISING.
I will be happy to correspond with everyone
we who love and work with SPECCY.
Do you have any questions about the program?
framing? Write. If I can, then answer
chu.
Do you need a coder? If you liked
my developments (see above), write.
And one more thing: who will help get the book P. Fe-
din "FULL DESCRIPTION AND FULL DISASSEMBLE -
LER TR-DOS 5.04(5.03)". It is also possible on disk.
...ABOUT YOURSELF.
I'm 16 years old. I'm interested in programming
on SPECTRUME, which I have had for 6 years.
Now I have SCORPION. Perfectly
I know BASIC and Pascal. Pretty good
I also work in assembler.
...ABOUT FAREWELL.
Well, my epic has come to an end, over
where I worked for a month and a half.
Wishes, comments, suggestions and requests -
then send letters to:
┌─────────────────────────────────┐
│ 612831 Кировская обл., │
│ Верхнекамский р-н, │
│ пос. Рудничный, │
│ ул. Орджоникидзе, │
│ д. 33, кв. 48. │
│ КИСЕЛЕВУ АЛЕКСАНДРУ ПЕТРОВИЧУ │
└─────────────────────────────────┘
------------------------------------------
Share your thoughts about the article