Article View: net.micro.atari
Article #1762Re: How to read joystick/mouse ports on 520ST? (part 2 of 2)
From: Richard E. Sansom
Date: Mon, 16 Dec 1985 18:53
Date: Mon, 16 Dec 1985 18:53
330 lines
7948 bytes
7948 bytes
Here are the rest of the ikbd commands, and a C program which will
read joystick 0 (sorry it took me so long to get back to this!).
Load Mouse Position
0x0E
0x00 ; filler (?)
XMSB ; X coordinate (scaled coordinate system)
XLSB ;
YMSB ; Y coordinate
YLSB
Set Y=0 at Bottom
0x0F
Set Y=0 at Top
0x10
Resume - Resume sending data to host (after a pause)
0x11
Disable Mouse - Disable mouse event reporting (any mouse command resumes)
0x12
Pause - Stop sending data to the host
0x13
Set Joystick Event Reporting (default)
0x14
Set Joystick Interrogate Mode
0x15
Interrogate Joystick
0x16
Set Joystick Monitoring
0x17 ;
rate ; time between samples in hundredths of a second
Returns: (in packets of two as long as in mode)
%000000xy
||
|--- ; JOYSTICK1 Fire button
---- ; JOYSTICK0 Fire button
%nnnnmmmm
||||||||
||||------ ; JOYSTICK1 state
---------- ; JOYSTICK0 state
Set Fire Button Monitoring
0x18
Returns: (as long as in mode)
%bbbbbbbb ; state of JOYSTICK1 packed 8 bits
; per byte
Set Joystick Keycode Mode
0x19
RX ; horizontal velocity breakpoint (tenths of seconds)
RY ; vertical velocity breakpoint (tenths of seconds)
TX ; horizontal cursor key generation delay (tenths)
TY ; vertical cursor key generation delay (tenths)
VX ; horizontal cursor key generation repeat (tenths)
VY ; vertical cursor key generation repeat (tenths)
Disable Joysticks
0x1A
Time-of-Day Clock Set
0x1B
YY ; year (two least significant digits)
MM ; month
DD ; day
hh ; hour
mm ; minute
ss ; second
NOTE: all time-of-day data should be sent as packed BCD.
Interrogate Time-of-Day Clock
0x1C
Returns:
0xFC ; time-of-day event header
YY ; year
MM ; month
DD ; day
hh ; hour
mm ; minute
ss ; second
NOTE: time-of-day data returned as packed BCD.
Memory Load - load ikbd controller memory
0x20
ADDRMSB ; address of controller memory (high)
ADDRLSB ; address of controller memory (low)
NUM ; number of bytes (0-128)
{data}
Memory Read - read ikbd controller memory
0x21
ADDRMSB ; address of controller memory (high)
ADDRLSB ; address of controller memory (low)
Returns:
0xF6 ; status header
0x20 ; memory access
{data} ; 6 data bytes starting at ADDR
Controller Execute - execute ikbd controller subroutine
0x22
ADDRMSB ; address of subroutine in controller
ADDRLSB ; memory to be called
Status Inquiries
----------------
All status commands are formed by ORing 0x80 with the relevant SET command.
Valid Status Inquiry commands are:
0x87 mouse button action
0x88 mouse mode
0x89
0x8A
0x8B mouse threshold
0x8C mouse scale
0x8F mouse vertical coordinates
0x90 (returns 0x0F if Y=0 at bottom, 0x10 if Y=0 at top)
0x92 mouse enable/disable (0x00=enabled, 0x12=disabled)
0x94 joystick mode
0x95
0x99
0x9A joystick enable/disable (0x00=enabled, 0x1A=disabled)
NOTE: Status Inquiry commands are NOT VALID if the ikbd is in
Joystick Monitoring Mode or Fire Button Monitoring Mode.
Phew! Now that you've got all that stuff memorized, you can forget
most of it. As far as I can tell, the ST is set-up to not monitor the
joysticks at all! If you use the Kbdvbase() call, you will get a
pointer to a structure containing all of the ikbd handlers. Now, in
the version of TOS I have, the joystick handler vector (joyvec) points
to a RTS (return from subroutine) instruction. So, since I did not
want to write my own handler, I used the simplest of the joystick
monitoring modes, Joystick Keycode Mode, in the following program.
If I eventually do write a handler, I will post it to the net also. In
the meantime, enjoy!
-------------------------------------------------------------------------------
/*
* Atari 520ST Joystick/Keyboard Monitoring Demo
*
* Richard E. Sansom December 1985
*
* This is a no-frills program which will monitor joystick 0, and will
* report joystick events as keystrokes. No claims are made as to its
* efficiency (or elegance).
*
*/
#include <stdio.h>
#include <osbinds.h>
/*
* defines
*/
#define JOY_UP 0x48
#define JOY_LEFT 0x4B
#define JOY_RIGHT 0x4D
#define JOY_DOWN 0x50
#define JOY_FIRE 0x74
#define TRUE 1
#define FALSE 0
/*
* globals
*/
static
char set_joy_key_mode [] = {
0x19 /* Set Joystick Keycode Mode */
0x00,0x00, /* RX, RY */
0x00,0x00, /* TX, TY */
0x01,0x01 /* VX, VY */
};
static
char reset_ikbd [] = {
0x80,0x01 /* Reset */
};
/*
* main program
*/
main() {
int lo_chr,hi_chr,more;
long chr;
/*
* clear screen, prompt for joystick
*/
Cconout(0x1B); Cconout(0x45);
printf("Plug joystick into port 0, hit any key when ready...");
while (!Cconis())
;
Cconin();
printf("\n");
/*
* write command string to ikbd
*/
Ikbdws(6,set_joy_key_mode);
/*
* loop until 'Q' is hit
*/
more = TRUE;
while (more) {
while (Bconstat(2)) {
chr = Bconin(2);
lo_chr = chr & 0x00FF; /* ascii code */
hi_chr = chr >> 0x10; /* scan code */
switch (hi_chr) {
case JOY_UP: {
printf("Joystick UP ");
break; /* Ok, so I'm no purist */
}
case JOY_LEFT: {
printf("Joystick LEFT ");
break;
}
case JOY_RIGHT: {
printf("Joystick RIGHT ");
break;
}
case JOY_DOWN: {
printf("Joystick DOWN ");
break;
}
case JOY_FIRE: {
printf("Joystick FIRE ");
break;
}
default: printf("Keystroke ");
}
printf("(scan=0x%x, ascii=0x%x\n)",hi_chr,lo_chr);
more = !(lo_chr == 'Q');
}
}
/*
* reset ikbd, exit
*/
Ikbdws(1,reset_ikbd);
_exit(0);
}
-------------------------------------------------------------------------------
For those of you using the Hippo-C compiler - I've heard that not all
of the ST bios and xbios calls are defined (at least in the documentation),
so you may want to try the following defines, and see what happens.
#define Cconis() conis()
#define Cconin() conin()
#define Bconstat(dev) bios(1,dev)
#define Bconin(dev) bios(2,dev)
#define Ikbdws(cnt,ptr) xbios(25,cnt,ptr)
I don't know if you have a bios() call available, so you may have to
build your own:
.text
.global _bios
_bios: move.l (sp)+,.save ; save return address
trap #13 ; call bios
move.l .save,-(sp) ; restore return address
rts ; return
.bss
.save .ds.l ; storage area
You may have to build your own xbios() call also:
.text
.global _xbios
_xbios: move.l (sp)+,.save ; save return address
trap #14 ; call xbios
move.l .save,-(sp) ; restore return address
rts ; return
.bss
.save .ds.l ; storage area
I don't know whether the Hippo-C compiler pushes all of its args
on the stack as longs (the DRI compiler does NOT), so you may have to
take that into consideration also.
Richard E. Sansom
{decvax,ucbvax,ihnp4}!trwrb!trwrba!sansom
Technical Details
Message-ID:
<1732@trwrba.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!ittatc!dcdwest!sdcsvax!sdcrdcf!trwrb!trwrba!sansomReferences:
<1711@druxu.UUCP> <851203-103902-3629@Xerox> <1713@trwrba.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site trwrba.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!ittatc!dcdwest!sdcsvax!sdcrdcf!trwrb!trwrba!sansom From: sansom@trwrba.UUCP (Richard E. Sansom) Newsgroups: net.micro.atari Subject: Re: How to read joystick/mouse ports on 520ST? (part 2 of 2) Message-ID: <1732@trwrba.UUCP> Date: Mon, 16-Dec-85 13:53:16 EST Article-I.D.: trwrba.1732 Posted: Mon Dec 16 13:53:16 1985 Date-Received: Wed, 18-Dec-85 04:48:54 EST References: <1711@druxu.UUCP> <851203-103902-3629@Xerox> <1713@trwrba.UUCP> Reply-To: sansom@trwrba.UUCP (Richard E. Sansom) Distribution: net Organization: TRW EDS, Redondo Beach, CA Lines: 330