Thread: [cc65-devel] Keyboard and joystick reading problem
cc65 - a freeware C compiler for 6502 based systems
Brought to you by:
gpz
|
From: Janne P. <jan...@su...> - 2016-06-16 05:02:55
|
Hello, I have a Commodore Plus/4 program where I need to react to key presses while reading a joystick. Is it possible? I can read the keyboard with kbhit() and cgetc() functions but as soon as I call read_joy() function to read the joystick status, the keyboard reading part stops to work: I receive multiple key presses and wrong characters. The read_joy() function returns valid status information, except it doesn't register fire button. -- Janne Peräaho |
|
From: Jeremy S. <je...@de...> - 2016-06-16 22:32:28
|
Janne Peräaho wrote: >Hello, > >I have a Commodore Plus/4 program where I need to react to key presses >while reading a joystick. Is it possible? > > I remember the game Mercenary on the C64 could read from keyboard and joystick. Sadly, I can't remember how it was done now. VIC chip I think, not sure about +4. Cheers, Jeremy. |
|
From: Marc 'B. R. <ma...@ri...> - 2016-06-16 23:30:31
Attachments:
signature.asc
|
On 16/06/16 06:46, Janne Peräaho wrote:
> I can read the keyboard with kbhit() and cgetc() functions but as soon
> as I call read_joy() function to read the joystick status, the keyboard
> reading part stops to work: I receive multiple key presses and wrong
> characters.
>
> The read_joy() function returns valid status information, except it
> doesn't register fire button.
Although the conflict of at least one joystick port with the keyboard
might be normal (as on a C64), there seems to be something wrong with
the driver for the plus4. The following program shows odd behaviour on
VICE's xplus4:
#include <stdint.h>
#include <conio.h>
#include <joystick.h>
#ifdef __PLUS4__
#define JOY_DRIVER (plus4_stdjoy_joy)
#endif
#ifdef __C64__
#define JOY_DRIVER (c64_stdjoy_joy)
#endif
extern void JOY_DRIVER[];
int main(void) {
uint8_t joystick_count;
uint8_t i, mask;
uint8_t joy_state;
if (joy_install(JOY_DRIVER) != JOY_ERR_OK) {
return 1;
}
joystick_count = joy_count();
clrscr();
for (;;) {
gotoxy(0, 0);
cprintf("key: ");
if (kbhit()) {
cprintf("%3u", cgetc());
}
cputs("\r\n");
for (i = 0; i < joystick_count; ++i) {
joy_state = joy_read(i);
cprintf("joy #%u: ", i + 1);
for (mask = 128; mask; mask >>= 1) {
cputc((joy_state & mask) ? '1' : '0');
}
cputs("\r\n");
}
}
}
It shows two joysticks but both react simultaneously with a joystick in
port #1 for the directions and not at all with a joystick in port #2.
Button presses on a joystick aren't recognized at all in both ports.
The same program compiled for C64 works fine on VICE's x64 and a real
bread box.
Ciao,
Marc 'BlackJack' Rintsch
--
Incorrect documentation is often worse than no documentation.
-- Bertrand Meyer
|
|
From: <gr...@gm...> - 2016-06-16 23:38:42
|
On Friday 17 June 2016, 01:30:14 Marc 'BlackJack' Rintsch <ma...@ri...> wrote: > On 16/06/16 06:46, Janne Peräaho wrote: > > I can read the keyboard with kbhit() and cgetc() functions but as soon > > as I call read_joy() function to read the joystick status, the keyboard > > reading part stops to work: I receive multiple key presses and wrong > > characters. > > > > The read_joy() function returns valid status information, except it > > doesn't register fire button. > > Although the conflict of at least one joystick port with the keyboard > might be normal (as on a C64), there seems to be something wrong with > the driver for the plus4. The following program shows odd behaviour on > VICE's xplus4: [snip] better confirm it on a real plus4 - i wouldnt trust xplus4 for anything, its really very broken (and its almost completely untested too). -- http://www.hitmen-console.org http://magicdisk.untergrund.net http://www.pokefinder.org http://ar.pokefinder.org It doesn't matter who votes. What matters is who counts the votes. <Josef Stalin> |
|
From: Marc 'B. R. <ma...@ri...> - 2016-06-16 23:56:43
Attachments:
signature.asc
|
On 17/06/16 01:38, gr...@gm... wrote:
> On Friday 17 June 2016, 01:30:14 Marc 'BlackJack' Rintsch <ma...@ri...>
> wrote:
>> On 16/06/16 06:46, Janne Peräaho wrote:
>> […] The following program shows odd behaviour on VICE's xplus4:
> [snip]
>
> better confirm it on a real plus4 - i wouldnt trust xplus4 for anything, its
> really very broken (and its almost completely untested too).
I would if I had one. :-)
But the following BASIC program works for both joystick ports and also
recognises joystick button presses in xplus4:
5 print"{CLR}"
10 print joy(1)
20 print joy(2)
30 goto 5
Which makes a problem with cc65's driver at least a little bit more
plausible.
Ciao,
Marc 'BlackJack' Rintsch
--
“Digital files cannot be made uncopyable,
any more than water can be made not wet.”
-- Bruce Schneier
|
|
From: Janne P. <jan...@su...> - 2016-06-17 12:07:31
|
17.6.2016, 2.38, gr...@gm... wrote: > On Friday 17 June 2016, 01:30:14 Marc 'BlackJack' Rintsch > <ma...@ri...> wrote: >> >> Although the conflict of at least one joystick port with the >> keyboard might be normal (as on a C64), there seems to be something >> wrong with the driver for the plus4. The following program shows >> odd behaviour on VICE's xplus4: > [snip] > > better confirm it on a real plus4 - i wouldnt trust xplus4 for > anything, its really very broken (and its almost completely untested > too). I did some testing with a real hardware and I can confirm Marc's findings: > It shows two joysticks but both react simultaneously with a joystick > in port #1 for the directions and not at all with a joystick in port > #2. Button presses on a joystick aren't recognized at all in both > ports. kbhit() also reacts to joystick movement which shouldn't happen in my opinion. Pressing repeatable (and fast) one of these keys appear as joystick movement: Z, A, W, R, Y, I, P, £, *, control, D, G, J, L, return, B, M, dot, esc, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, home, and del. In other words, nearly all key presses are detected as joystick movement. -- Janne Peräaho |