2002-12-21 09:35:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <joystick.h>
|
|
|
|
|
2014-06-02 06:41:35 +00:00
|
|
|
#ifdef JOYSTICK_DRIVER
|
|
|
|
|
2014-06-01 17:17:02 +00:00
|
|
|
/* A statically linked driver was named on the compiler's command line.
|
|
|
|
** Make sure that it is used instead of a dynamic one.
|
|
|
|
*/
|
|
|
|
# undef DYN_DRV
|
|
|
|
# define DYN_DRV 0
|
2018-03-06 22:36:11 +00:00
|
|
|
|
|
|
|
/*
|
2018-03-08 03:05:10 +00:00
|
|
|
** link existing drivers like this:
|
|
|
|
**
|
|
|
|
** cl65 -DJOYSTICK_DRIVER=c64_hitjoy_joy -o joy-test.prg joy-test.c
|
|
|
|
**
|
|
|
|
** for testing a new driver you will have to uncomment the define below, and
|
|
|
|
** link your driver like this:
|
|
|
|
**
|
|
|
|
** co65 ../../target/c64/drv/joy/c64-hitjoy.joy -o hitjoy.s --code-label _hitjoy
|
|
|
|
** cl65 -DJOYSTICK_DRIVER=hitjoy -o joy-test.prg joy-test.c hitjoy.s
|
|
|
|
**
|
2018-03-06 22:36:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* extern char JOYSTICK_DRIVER; */
|
|
|
|
|
2014-06-02 06:41:35 +00:00
|
|
|
#else
|
2014-06-01 17:17:02 +00:00
|
|
|
|
2014-06-02 06:41:35 +00:00
|
|
|
/* Use a dynamically loaded driver, by default. */
|
|
|
|
# ifndef DYN_DRV
|
|
|
|
# define DYN_DRV 1
|
|
|
|
# endif
|
2014-05-30 21:38:27 +00:00
|
|
|
#endif
|
|
|
|
|
2002-12-21 09:35:54 +00:00
|
|
|
|
|
|
|
int main (void)
|
|
|
|
{
|
|
|
|
unsigned char j;
|
|
|
|
unsigned char count;
|
|
|
|
unsigned char i;
|
2018-03-06 22:36:11 +00:00
|
|
|
unsigned char Res;
|
2018-03-06 23:19:14 +00:00
|
|
|
unsigned char ch, kb;
|
2018-03-06 22:36:11 +00:00
|
|
|
|
|
|
|
clrscr ();
|
2002-12-21 09:35:54 +00:00
|
|
|
|
2014-06-01 17:17:02 +00:00
|
|
|
#if DYN_DRV
|
2018-03-06 22:36:11 +00:00
|
|
|
Res = joy_load_driver (joy_stddrv);
|
2014-06-02 06:41:35 +00:00
|
|
|
#elif defined(JOYSTICK_DRIVER)
|
2018-03-06 22:36:11 +00:00
|
|
|
Res = joy_install (&JOYSTICK_DRIVER);
|
2014-06-01 17:17:02 +00:00
|
|
|
#else
|
2018-03-06 22:36:11 +00:00
|
|
|
Res = joy_install (&joy_static_stddrv);
|
2009-01-06 17:44:20 +00:00
|
|
|
#endif
|
2014-06-01 17:17:02 +00:00
|
|
|
|
2002-12-21 09:35:54 +00:00
|
|
|
if (Res != JOY_ERR_OK) {
|
2013-05-09 11:56:54 +00:00
|
|
|
cprintf ("Error in joy_load_driver: %u\r\n", Res);
|
2014-06-02 06:41:35 +00:00
|
|
|
#if DYN_DRV
|
2002-12-21 09:35:54 +00:00
|
|
|
cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror));
|
2014-05-30 21:38:27 +00:00
|
|
|
#endif
|
2013-05-09 11:56:54 +00:00
|
|
|
exit (EXIT_FAILURE);
|
2002-12-21 09:35:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
count = joy_count ();
|
2017-02-15 14:45:49 +00:00
|
|
|
#if defined(__ATARI5200__) || defined(__CREATIVISION__)
|
2014-05-30 21:38:27 +00:00
|
|
|
cprintf ("JOYSTICKS: %d", count);
|
|
|
|
#else
|
2002-12-21 09:35:54 +00:00
|
|
|
cprintf ("Driver supports %d joystick(s)", count);
|
2014-05-30 21:38:27 +00:00
|
|
|
#endif
|
2002-12-21 09:35:54 +00:00
|
|
|
while (1) {
|
2013-05-09 11:56:54 +00:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
gotoxy (0, i+1);
|
|
|
|
j = joy_read (i);
|
2017-02-15 14:45:49 +00:00
|
|
|
#if defined(__ATARI5200__) || defined(__CREATIVISION__)
|
2018-03-06 22:36:11 +00:00
|
|
|
cprintf ("%1d:%-3s%-3s%-3s%-3s%-3s %02x",
|
2014-05-30 21:38:27 +00:00
|
|
|
i,
|
2017-08-19 17:11:28 +00:00
|
|
|
JOY_UP(j)? " U " : " - ",
|
|
|
|
JOY_DOWN(j)? " D " : " - ",
|
|
|
|
JOY_LEFT(j)? " L " : " - ",
|
|
|
|
JOY_RIGHT(j)? " R " : " - ",
|
2018-03-06 22:36:11 +00:00
|
|
|
JOY_BTN_1(j)? " 1 " : " - ", j);
|
2014-05-30 21:38:27 +00:00
|
|
|
#else
|
2018-03-06 22:36:11 +00:00
|
|
|
cprintf ("%2d: %-6s%-6s%-6s%-6s%-6s %02x",
|
2013-05-09 11:56:54 +00:00
|
|
|
i,
|
2017-08-19 17:11:28 +00:00
|
|
|
JOY_UP(j)? " up " : " ---- ",
|
|
|
|
JOY_DOWN(j)? " down " : " ---- ",
|
|
|
|
JOY_LEFT(j)? " left " : " ---- ",
|
|
|
|
JOY_RIGHT(j)? "right " : " ---- ",
|
2018-03-06 22:36:11 +00:00
|
|
|
JOY_BTN_1(j)? "button" : " ---- ", j);
|
2014-05-30 21:38:27 +00:00
|
|
|
#endif
|
2013-05-09 11:56:54 +00:00
|
|
|
}
|
2018-03-06 23:19:14 +00:00
|
|
|
|
|
|
|
/* show pressed key, so we can verify keyboard is working */
|
2018-03-08 03:05:10 +00:00
|
|
|
kb = kbhit ();
|
|
|
|
ch = kb ? cgetc () : ' ';
|
2018-03-06 23:19:14 +00:00
|
|
|
gotoxy (1, i+2);
|
2018-03-08 03:05:10 +00:00
|
|
|
revers (kb);
|
|
|
|
cprintf ("kbd: %c", ch);
|
|
|
|
revers (0);
|
2002-12-21 09:35:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|