Author : Alexander Russell
Page : << Previous 7 Next >>
scan codes: a 'press' code, and a 'release' code. The `release' code is the `press' code with the high bit set. The second keypad return three scan codes, an 0xe0 followed by the normal scan codes. The pauses key is VERY weird - I'm not going to go into it here.
JoystickThe button status can be retrieved quickly with an inportb(), but to get the joystick values you send to a port, then poll the port until it goes to zero which means this is SLOW as you have to wait until the joystick times out. There are complicated methods using timer interrupts to avoid wasting this time, but I will present the simple 'wait for it to timeout' code.
/* note!!!! buttons are pressed when b0, b1 is zero (0)
Also, the values returned by this routine will vary widely
on machines that run at different speeds for joy_x and y
reads joy1 only
if joystick is not plugged in the joy_x and joy_y will both
be 1023
generally you read the joystick at fixed intervals because
it is a slow process, and the buttons more frequently.
*/
short joy_x, joy_y; // stores joystick position
BYTE b0, b1; // button status flags
/* sets the global vars b1, and b0 */
/* ---------------------- read_joy_buttons() -------------- June 10,1993 */
void read_joy_buttons(void)
{
asm {
mov dx,201h
xor ax, ax
in al,dx
mov bl, al
and bl, 010h
mov b0, bl
and al, 020h
mov b1, al
}
}
/* sets the global vars joy_x, joy_y, b0, b1 - SLOW!!! */
/* this is slow compared to just checking the buttons.
in many projects I only check the joystick once/(certain time)
and the buttons more frequently.
*/
/* ---------------------- read_joy() --------------------- March 29,1993 */
void read_joy(void)
{
asm {
push si
xor ax,ax
/* joystick port */
mov dx,201h
mov cx,ax
mov bx,ax
mov si, 1024 /* this number may have to be LARGER on
FAST machines */
cli /* disable interupts so that our timing loop isn't
interupted */
/* begin digitize, prime joy port */
out dx,al
}
jlp:
asm {
dec si
jz abt /* timeout */
/* read port */
in al,dx
test al,1
jz nox
/* increment x counter if bit 0 high */
inc bx
}
nox:
asm {
test al,2
jz noy
/* increment y counter if bit 1 high */
inc cx
}
noy:
asm {
test al,3
/* keep going until both x and y done */
jnz jlp
}
abt:
asm {
sti /* enable interupts */
/* store x and y coordinates, and button stats */
mov joy_y, cx
mov joy_x, bx
mov bl, al
and bl, 010h
mov b0, bl
and al, 020h
mov b1, al
pop si
}
}
MouseFor the mouse we will ask the normal int33h mouse driver to install a stub program that calls our real mouse handler. The stub is written in ASM.
;****************************************************
;* *
;* File: cmousea.asm *
;* *
;* Assembly language hook for CMOUSE library event handler *
;* Assemble with /Ml switch
Page : << Previous 7 Next >>