Weird Joystick behaviour
Posted: Fri Jun 16, 2023 4:00 am
Can anyone explain this behaviour?
My previous version used an asm file that was merged into my C code. Since I needed to rewrite my linked list procedures, I thought I would try to do the asm functions inline in C rather than exporting from a separate asm file. But, I'm not very conversant with the syntax.
Anyway, I had a similar quirk in both versions:
If you see, I have to call Read_Joystick() an extra time. If I don't, the first read doesn't process.
This caused me no end of frustration in both versions when I was trying to get the joystick working initially,
since my initial tests called the joystick only once for the joystick I was trying to test and get working, (either
0 for keyboard, or 1 or 2 for physical sticks.)
Calling it only once for any joystick reads nothing.
Calling multiple, the first joystick called doesn't register. No matter what order I put them in, the first one is the
one that doesn't work.
Also, if I turn on the mouse first, a single joystick call works.
(I included a mouse test near the end of read_joystick just so I could shut down the program when joystick
wasn't working.)
My previous version used an asm file that was merged into my C code. Since I needed to rewrite my linked list procedures, I thought I would try to do the asm functions inline in C rather than exporting from a separate asm file. But, I'm not very conversant with the syntax.
Anyway, I had a similar quirk in both versions:
If you see, I have to call Read_Joystick() an extra time. If I don't, the first read doesn't process.
This caused me no end of frustration in both versions when I was trying to get the joystick working initially,
since my initial tests called the joystick only once for the joystick I was trying to test and get working, (either
0 for keyboard, or 1 or 2 for physical sticks.)
Calling it only once for any joystick reads nothing.
Calling multiple, the first joystick called doesn't register. No matter what order I put them in, the first one is the
one that doesn't work.
Also, if I turn on the mouse first, a single joystick call works.
(I included a mouse test near the end of read_joystick just so I could shut down the program when joystick
wasn't working.)
Code: Select all
/*****************Main Program Start*********************************/
void main(void){
Init_IRQ();
x = 0; y = 0; z = 0;
counter1 = 0; counter2 = 0; counter3 = 0;
Init_Memory_A();
keys = 0;
while (keys == 0){
while (vsync_set == 0){
counter2++;
}
vsync_set = 0;
counter1++;
Read_Joystick(0);
Read_Joystick(0);
Read_Joystick(1);
Read_Joystick(2);
}
Restore_IRQ();
}
void Read_Joystick(unsigned char stick){
temp = stick;
__asm__ ("lda %v",temp); // load a with joystick #
__asm__ ("jsr %w",JOYSTICK_GET);
__asm__ ("sta %v",joy_keys0);
__asm__ ("stx %v",joy_keys1);
__asm__ ("sty %v",joy_present);
if (joy_present != 0xFF){
if ((joy_keys0 & 0x20) == 0){keys = 1;}
//if (joy_keys0 != 0xFF){keys = 1;}
}
//mouse test
__asm__ ("ldx #$22");
__asm__ ("jsr %w",MOUSE_GET);
__asm__ ("sta %v",temp);
if ((temp & 1) == 1){keys = 1;}
}
/*****************End Main Program********************************/