aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche/joysetup.cpp
blob: 1ebbc4fb663ddda07047ec2a86bc1ab5787b5162 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

/*
 * This code is based on the original source code of Lord Avalot d'Argent version 1.3.
 * Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
 */

/* Avalot joystick setup routines. To be incorporated
                         into Setup2 whenever I get a chance. */
/*#include "Joystick.h"*/
/*#include "Crt.h"*/

namespace Avalanche {

struct joysetup {
            word xmid,ymid,xmin,ymin,xmax,ymax;
            byte centre; /* Size of centre in tenths */
};

joysetup js;
file<joysetup> jf;

boolean detect()
{
 word x,y,xo,yo;
 byte count;
boolean detect_result;
;
 count=0;
 if (joystickpresent) 
 {;
  detect_result=true;
  return detect_result;
 }
 readjoya(xo,yo);
 do {
  if (count<7)  count += 1;   /* Take advantage of "flutter" */
  if (count==6) 
  {;
   output << "The Bios says you don't have a joystick. However, it's often wrong" << NL;
   output << "about such matters. So, do you? If you do, move joystick A to" << NL;
   output << "continue. If you don't, press any key to cancel." << NL;
  }
  readjoya(x,y);
 } while (!((keypressed()) | (x!=xo) || (y!=yo)));
 detect_result=~ keypressed();
return detect_result;
}

void display()
{;
 {;
  gotoxy(20,10); output << "X min: " << js.xmin << "  ";
  gotoxy(20,11); output << "X max: " << js.xmax << "  ";
  gotoxy(20,12); output << "Y min: " << js.ymin << "  ";
  gotoxy(20,13); output << "Y max: " << js.ymax << "  ";
 }
}

void getmaxmin()
{
    word x,y;
;
 output << "Rotate the joystick around in a circle, as far from the centre as it" << NL;
 output << "can get. Then click a button." << NL;
 {;
  js.xmax=0; js.xmin=maxint;
  js.ymax=0; js.ymin=maxint;
 }
 do {
  readjoya(x,y);
  {;
   if (x<js.xmin)  js.xmin=x;
   if (y<js.ymin)  js.ymin=y;
   if (x>js.xmax)  js.xmax=x;
   if (y>js.ymax)  js.ymax=y;
   display();
  }
 } while (!(buttona1 | buttona2));
 do {; } while (!(~ (buttona1 | buttona2)));
 output << NL;
 output << "Thank you. Now please centre your joystick and hit a button." << NL;
 do {; } while (!(buttona1 | buttona2));
            readjoya(js.xmid,js.ymid);
}

int main(int argc, const char* argv[])
{pio_initialize(argc, argv);
;
 textattr=2;
 clrscr;
 output << "Avalot joystick setup routine- by TT. Thanks go to David B. Howorth." << NL;
 output << NL;
 if (detect())  output << "You've got a joystick!" << NL; else return 0;
 getmaxmin();
 do {
  output << "Centring factor\? (3-9)";
  input >> js.centre >> NL;
 } while (!(set::of(range(1,9), eos).has(js.centre)));
 assign(jf,"v:joytmp.dat");
 rewrite(jf); jf << js; close(jf);     /* write it all out to disk. */
return EXIT_SUCCESS;
}

} // End of namespace Avalanche.