╔═════╦═════════════════════════ ═══════════════════════════════╗
║ 4 ║ Kempstone Mouse ║
╚═════╩═════════════════════════ ═══════════════════════════════╝
(c) CODEMAN.
In this article I will try to explain how to program
Kempstone Mouse.
First about the ports:
#FADF - displays the state of the mouse buttons. Only young people play the role
three bits. If the bit is cleared, the button is pressed. If the bit is set
Len-button is not pressed.
For example:
LD BC,#FADF
IN A,(C)
RRA
JP NC,BUTTON1;jump if the first button is pressed.
RRA
JP NC,BUTTON2;jump if the second button is pressed.
...
#FBDF-movement along X-coordinate.
#FFDF-movement along the Y-coordinate.
:
When you move the mouse to the right or up, the numbers in the corresponding ports
max increases cyclically, i.e. reaching 255 it becomes 0
etc. Similarly, if you move the mouse left or down, only
numbers are decreasing. The faster you move the mouse, the more changes
The number in the port appears. It will be clearer if you understand the following:
cabbage soup
KEY_SCAN
LD BC,#FBDF; read the port
IN A,(C) ;
MK3 CP 00 ; compare with the previous value
JR Z,MK ; bypass the call if the numbers are equal
CALL KOORX; call if not equal
MK
LD BC,#FFDF; read the port
IN A,(C) ;
MK4CP 00 ; compare
JR Z,MK2 ; bypass the call
CALL KOORY ;
MK2
... ; further program
KOORX
JP M,METKA ; move on if the number has decreased
PUSH AF ; save the number
LD A,(MK3+1); take the old value
LD B,A ; put in B
POP AF ; we restore
LD (MK3+1),A; we replace the old with the new
SUB B ; we take away
ADD A,A ; fold to make the mouse move faster
LD(STEP),A ; enter the change into the cell
CALL RIGHT ; We call the program to calculate the new coordinates.
RET ; refund
METKA
PUSH AF ; everything is the same
LD A,(MK3+1);
LD B,A ;
POP AF ;
LD (MK3+1),A;
CALL CHANGE ; call for an exchange
SUB B ;
ADD A,A ;
LD(STEP),A ;
CALL LEFT ;
RET ;
CHANGE
LD D,A ;
LD A,B ;
LD B,D ;
RET ;
KOORY
JP M,METKA2 ;
PUSH AF ; also only for Y coordinates
LD A,(MK4+1);
LD B,A ;
POP AF ;
LD (MK4+1),A;
SUB B ;
ADD A,A ;
LD(STEP),A ;
CALLUP;
RET ;
METKA2
PUSH AF ;
LD A,(MK4+1);
LD B,A ;POP AF ;
LD (MK4+1),A;
CALL BOL;
SUB B ;
ADD A,A ;
LD(STEP),A ;
CALL DOWN ;
RET ;
STEP DB #00 ; arrow step
Now some general explanations:
The difference between the old and new value is a step and you can use it
do whatever you want, I multiply it by two (ADD A,A) so that
one step the arrow moved by two pixels. How understandable it is to take away
you need the smaller of the larger and when you move the mouse to the right or up
This is how it happens: the old value is always less than the new one. But when -
yes, the mouse was moved in the opposite direction, then the old number will be
more new and therefore we call the CHANGE program. Having calculated the step
a subroutine is called to calculate the new coordinates of the arrow.
I hope this article helps you at least a little.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
Share your thoughts about the article