home *** CD-ROM | disk | FTP | other *** search
- program JoyDemo3;
-
- {
- Author: David Howorth
- Last updated: March 29, 1987
- Application: A demonstration of procedure ReadJoy, a procedure for
- reading the joystick, using variable parameters. Shows
- how to use the joystick as a POSITION indicator.
- }
- {$C-}
- { Above compiler directive necessary so that 'keypressed' function works
- properly. Also speeds up screen output. }
-
- var
- ch : char;
- JoyX,
- JoyY,
- Dummy : integer;
- XDivisor,
- YDivisor : integer;
-
- {$I READJOY.INC}
- {$I BUTTONS.INC}
-
- {--------------------------------------}
-
- procedure FatCursor(Fat : boolean);
-
- var
- Reg : record
- ax,bx,cx,dx,bp,si,di,ds,es,flags : integer;
- end;
-
- {----------------}
-
- function MonochromeScreen : boolean;
-
- begin
- MonochromeScreen := (mem[0:$449] = 7);
- end; { function MonochromeScreen }
-
- {----------------}
-
- begin { procedure FatCursor }
- if Fat
- then if MonochromeScreen
- then Reg.cx := $000D
- else Reg.cx := $0007
- else if MonochromeScreen
- then Reg.cx := $0C0D
- else Reg.cx := $0607;
- Reg.ax := $0100;
- intr($10,Reg);
- end; { procedure FatCursor }
-
- {--------------------------------------}
-
- procedure Initialize;
-
- var
- LowX,
- LowY,
- HighX,
- HighY : integer;
-
- {----------------}
-
- procedure CalibrateJoystick;
-
- begin
- writeln(' JOYSTICK DEMONSTRATION NUMBER 3');
- writeln;
- writeln(' (Joystick as position indicator)');
- gotoxy(1,7);
- writeln('You may want to try this demo with the joystick unlocked.');
- gotoxy(1,9);
- writeln('Move joystick to upper-left corner and press one of its buttons.');
- repeat until ButtonA1 or ButtonA2;
- ReadJoy(LowX,LowY,Dummy,Dummy);
- writeln('Move joystick to lower-right corner and press one of its buttons.');
- delay(300);
-
- { Note this delay. You have to give the joystick button a chance to settle
- down before you test it again. }
-
- repeat until ButtonA1 or ButtonA2;
- ReadJoy(HighX,HighY,Dummy,Dummy);
- XDivisor := (HighX div 80) + 1;
- YDivisor := (HighY div 25) + 1;
- gotoxy(1,15);
- writeln('Once the demonstration begins, you may end it by');
- writeln('pressing one of the joystick buttons.');
- delay(2000);
- writeln;
- writeln('Now press one of the buttons to begin.');
- repeat until ButtonA1 or ButtonA2;
- end; { procedure CalibrateJoystick }
-
- {----------------}
-
- procedure Box(x1,y1,x2,y2 : integer);
-
- var
- i : integer;
-
- begin
- gotoXY(x1,y1);
- write(char(218));
- for i := x1 + 1 to x2 - 1 do write(char(196));
- write(char(191));
- for i := y1 + 1 to y2 - 1 do
- begin
- gotoXY(x1,i);
- write(char(179));
- gotoXY(x2,i);
- write(char(179));
- end;
- gotoXY(x1,y2);
- write(char(192));
- for i := x1 + 1 to x2 - 1 do write(char(196));
- write(char(217));
- end; { procedure Box }
-
- {----------------}
-
- begin { procedure Initialize }
- clrscr;
- CalibrateJoystick;
- clrscr;
- LowX := (LowX div XDivisor) - 1;
- if LowX < 1 then LowX := 1;
- HighX := (HighX div XDivisor) + 1;
- if HighX > 80 then HighX := 80;
- LowY := (LowY div YDivisor) - 1;
- if LowY < 1 then LowY := 1;
- HighY := (HighY div YDivisor) + 1;
- if HighY > 25 then HighY := 25;
- Box(LowX,LowY,HighX,HighY);
- FatCursor(true);
- while keypressed do read(kbd,ch); { empty keyboard buffer }
- end; { procedure Initialize }
-
- {--------------------------------------}
-
- procedure Abort;
-
- begin
- FatCursor(false);
- clrscr;
- end;
-
- {--------------------------------------}
-
- begin { main program }
- Initialize;
- repeat
- ReadJoy(JoyX,JoyY,Dummy,Dummy);
- gotoxy((JoyX div XDivisor),(JoyY div YDivisor));
- until ButtonA1 or ButtonA2 or keypressed;
- Abort;
- end.