Hi again.
I have a doubt about gamepad input Reading.
I coded a Little handler thad reads the controller.
It Works fine on the emulator, but on real hardware button C Works as button START.
Does gamepads Works different on different countries or something like that?
Thanks for your help.
Gamepads input reading.
Moderator: BigEvilCorporation
How do you read the controller status ? Using a library or with you own code accessing the I/O ports ?
C and START (resp. B and A) buttons are multiplexed on the gamepad, which means you can only read one of the two at one time.
You need to tell the gamepad which one it should return by writing first $40 or $00 to the controller port before reading it.
By default, it seems it is initialized to $40 and will always return B&C buttons on real hardware but some emulators might have it initialized to $00 instead (and therefore return A&START buttons by default).
On real hardware, you also need to wait some delay between the write to the control port and the read, to give time to the gamepad to change his output. This delay is not required on emulators since the gamepad timings are generally not emulated.
C and START (resp. B and A) buttons are multiplexed on the gamepad, which means you can only read one of the two at one time.
You need to tell the gamepad which one it should return by writing first $40 or $00 to the controller port before reading it.
By default, it seems it is initialized to $40 and will always return B&C buttons on real hardware but some emulators might have it initialized to $00 instead (and therefore return A&START buttons by default).
On real hardware, you also need to wait some delay between the write to the control port and the read, to give time to the gamepad to change his output. This delay is not required on emulators since the gamepad timings are generally not emulated.
¡Thanks for the tip!
Im doing it by myself.
This is my gamepad reading routine. I'm trying to read the 6 button gamepad too.
I think i ll read again the gamepads i/o documentation and repeat this code. Maybe i'm just forgetting something.
Investigating a little i'm pretty sure the problem is that i'm not writting nothing to control register.
I missed to write #$40 to control ports.
After adding this lines to the code, it worked fine. I dont have 6 button controller for testing but now START and ABC works fine
Im doing it by myself.
This is my gamepad reading routine. I'm trying to read the 6 button gamepad too.
I think i ll read again the gamepads i/o documentation and repeat this code. Maybe i'm just forgetting something.
Investigating a little i'm pretty sure the problem is that i'm not writting nothing to control register.
Code: Select all
move.b #$00, pad_data_a
move.b #$00, pad_data_b
NOP
NOP
NOP
NOP
move.b pad_data_a, d0 ; read first byte
move.b pad_data_b, d1
rol.w #$8, d0 ; shift up
rol.w #$8, d1
move.b #$40, pad_data_a ; read next
move.b #$40, pad_data_b
move.b pad_data_a, d0
move.b pad_data_b, d1
move.b #$00, pad_data_a ; place 0 again
move.b #$00, pad_data_b ;
rol.l #$8, d0 ; shift again
rol.l #$8, d1
move.b #$40, pad_data_a ;repeat the process for 6 button gamepad
move.b #$40, pad_data_b
NOP
NOP
NOP
NOP
move.b #$00, pad_data_a
move.b #$00, pad_data_b
NOP
NOP
NOP
NOP
move.b #$40, pad_data_a
move.b #$40, pad_data_b
NOP
NOP
NOP
NOP
move.b pad_data_a,d0 ;read the extra buttons.
move.b pad_data_b,d1
move.b #$00, pad_data_a ;<-Cant remember why i did this
move.b #$00, pad_data_b ;<-right now when reading is done
MOVE.L D0,$00FF0008 ;Saving in memory buttons
MOVE.L D1,$00FF000C ;
After adding this lines to the code, it worked fine. I dont have 6 button controller for testing but now START and ABC works fine
Code: Select all
move.b #$40,control_pa
move.b #$40,control_pb