Page 1 of 1
Joystick Intr $15
Posted: Wed Jan 15, 2020 4:33 pm
by Chuckphd53
before I dig into the bios.... let me ask...
Does the Jr Bios support the Intr$15 call to the joysticks or only the read to port[$201]
Looking for a faster way to read the sticks with Turbo Pascal....
Re: Joystick Intr $15
Posted: Wed Jan 15, 2020 7:44 pm
by Trixter
It's in the BIOS IIRC, but it's terribly slow.
I'm happy to paste my optimized joystick code here, but before I do: Do you want a small, easy-to-read routine that works on systems up to 10 MHz, or would you like a larger routine that works on all speed systems (even pentiums)?
Re: Joystick Intr $15
Posted: Thu Jan 16, 2020 3:13 am
by Chuckphd53
optimized if fine,
Re: Joystick Intr $15
Posted: Thu Jan 16, 2020 10:29 am
by Trixter
Okay, here's a very small routine from Jordan Knight that returns the X and Y axis on the first joystick. It should work on systems up to about 16 MHz, after that it might return odd numbers. It also returns higher numbers the faster a system you run it on, so you can't just assume the ranges you get on one system will be the same on another system. If you want a more complicated routine that handles more situations, let me know, but for now here is Jordan's code with some slight modifications by me:
Code: Select all
function joyStick1AxisQuick:longint; assembler;
{
Original by Jordan Knight, slight tweaks by Trixter.
Returns:
AX = joystick 1 X axis
DX = joystick 1 Y axis
Use like this:
var
joyX,joyY:integer;
joyPosition:longint absolute joyX;
...
joyPosition:=joystick1Axis;
...then the axis will be stored in joyX and joyY.
}
asm
mov cx,$4ff {from XT BIOS; range 1-1279}
mov dx,defaultstickport
xor ax,ax
mov bx,ax
mov bp,ax
mov di,ax
pushf
cli
out dx,al {fire off one-shots}
@loop:
shr al,1
adc bx,bp {bx:=bx+joy1 xaxis bit}
add di,ax {di:=di+joy1 yaxis bit}
in al,dx {read joystick bits}
and al,$03 {we only care about xaxis bits}
loopnz @loop {if all bits are empty, done reading}
{note: can increase granularity slightly by unrolling @loop 4x}
popf
mov ax,bx
mov dx,di
end;