2002-12-21 09:35:54 +00:00
|
|
|
#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
|
|
|
|
|
|
|
/*
|
2019-09-27 07:38:51 +00:00
|
|
|
** Link existing drivers this way:
|
2018-03-08 03:05:10 +00:00
|
|
|
**
|
|
|
|
** cl65 -DJOYSTICK_DRIVER=c64_hitjoy_joy -o joy-test.prg joy-test.c
|
|
|
|
**
|
2019-09-27 07:38:51 +00:00
|
|
|
** For testing a new driver, you need to uncomment the declaration below,
|
|
|
|
** and link your driver this way:
|
2018-03-08 03:05:10 +00:00
|
|
|
**
|
|
|
|
** 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;
|
2019-09-27 07:38:51 +00:00
|
|
|
unsigned char i, count;
|
2018-03-06 22:36:11 +00:00
|
|
|
unsigned char Res;
|
|
|
|
|
|
|
|
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
|
2019-09-27 07:38:51 +00:00
|
|
|
cprintf ("OS: %u, %s\r\n", _oserror, _stroserror (_oserror));
|
2014-05-30 21:38:27 +00:00
|
|
|
#endif
|
2019-09-27 07:38:51 +00:00
|
|
|
return 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__)
|
2019-09-27 07:38:51 +00:00
|
|
|
cprintf ("JOYSTICKS: %u.", count);
|
2014-05-30 21:38:27 +00:00
|
|
|
#else
|
2019-09-27 07:38:51 +00:00
|
|
|
cprintf ("Driver supports %u joystick%s", count, count == 1 ? "." : "s.");
|
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) {
|
|
|
|
j = joy_read (i);
|
2019-09-27 07:38:51 +00:00
|
|
|
#if defined(__NES__) || defined(__CX16__)
|
|
|
|
/* two lines for each device */
|
|
|
|
gotoxy (0, i * 2 +1);
|
|
|
|
cprintf ("%2u:%-6s%-6s%-6s%-6s\r\n"
|
|
|
|
" %-6s%-6s%-6s%-6s $%02X",
|
2014-05-30 21:38:27 +00:00
|
|
|
i,
|
2019-09-27 07:38:51 +00:00
|
|
|
JOY_UP(j) ? " up " : " ---- ",
|
|
|
|
JOY_DOWN(j) ? " down " : " ---- ",
|
|
|
|
JOY_LEFT(j) ? " left " : " ---- ",
|
|
|
|
JOY_RIGHT(j) ? " right" : " ---- ",
|
|
|
|
JOY_BTN_1(j) ? "btn A " : " ---- ",
|
|
|
|
JOY_BTN_2(j) ? "btn B " : " ---- ",
|
|
|
|
JOY_BTN_3(j) ? "select" : " ---- ",
|
|
|
|
JOY_BTN_4(j) ? " start" : " ---- ",
|
|
|
|
j);
|
2014-05-30 21:38:27 +00:00
|
|
|
#else
|
2019-09-27 07:38:51 +00:00
|
|
|
/* one line for each device */
|
|
|
|
gotoxy (0, i + 1);
|
|
|
|
# if defined(__ATARI5200__) || defined(__CREATIVISION__)
|
|
|
|
cprintf ("%1u:%-3s%-3s%-3s%-3s%-3s %02X",
|
2013-05-09 11:56:54 +00:00
|
|
|
i,
|
2019-09-27 07:38:51 +00:00
|
|
|
JOY_UP(j) ? " U " : " - ",
|
|
|
|
JOY_DOWN(j) ? " D " : " - ",
|
|
|
|
JOY_LEFT(j) ? " L " : " - ",
|
|
|
|
JOY_RIGHT(j) ? " R " : " - ",
|
|
|
|
JOY_BTN_1(j) ? " 1 " : " - ",
|
|
|
|
j);
|
|
|
|
# else
|
|
|
|
cprintf ("%2u: %-6s%-6s%-6s%-6s%-6s $%02X",
|
|
|
|
i,
|
|
|
|
JOY_UP(j) ? " up " : " ---- ",
|
|
|
|
JOY_DOWN(j) ? " down " : " ---- ",
|
|
|
|
JOY_LEFT(j) ? " left " : " ---- ",
|
|
|
|
JOY_RIGHT(j) ? "right " : " ---- ",
|
|
|
|
JOY_BTN_1(j) ? "button" : " ---- ",
|
|
|
|
j);
|
|
|
|
# endif
|
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
|
|
|
|
2019-09-27 07:38:51 +00:00
|
|
|
/* Show any pressed keys; so that we can verify that the keyboard is working. */
|
|
|
|
if (kbhit ()) {
|
|
|
|
#if defined(__NES__) || defined(__CX16__)
|
|
|
|
gotoxy (1, i * 2 + 2);
|
|
|
|
#else
|
|
|
|
gotoxy (1, i + 2);
|
|
|
|
#endif
|
|
|
|
cprintf ("keyboard: $%02X", cgetc ());
|
|
|
|
}
|
2002-12-21 09:35:54 +00:00
|
|
|
}
|
2019-09-27 07:38:51 +00:00
|
|
|
return EXIT_SUCCESS;
|
2002-12-21 09:35:54 +00:00
|
|
|
}
|