bobonis / gb_emu

GNU General Public License v2.0
3 stars 0 forks source link

Input #80

Closed alam-R closed 8 years ago

alam-R commented 8 years ago

1.

Is Joypad Interrupt really useless? (because right now its implementation is in alpha stage)

SDL Poll event will not flush sdl's events. So KEY_UP is executed in every execute() cycle until a new event arrives.

3.

We have to consider also the cases where both directional and select keys are needed!!(really wtf?)

unsigned char inputReadKeys(){

unsigned char joypad_state = memory[0xFF00];

if ((joypad_state & 0x10) == 0 ){                   //Bit 4: Direction Keys selected
joypad_state = joypad_state | (joypad & 0x0F);  //Get 4 lower bits that represent direction keys
}
else if ((joypad_state & 0x20) == 0 ){                    //Bit 5: Standard keys selected
joypad_state = joypad_state | ((joypad & 0xF0) >> 4); //Get 4 higher bits that represent button keys
}
else{
printf(PRINT_RED "[DEBUG] Both direction and Standard" PRINT_RESET"\n");
joypad_state = joypad_state | (joypad & 0x0F);
}
return joypad_state;

After that dragonball is working... BUT it is not fully functional, the real question is: Can input affect let's say a sprite?

bobonis commented 8 years ago

Hm, you may be right about this, but I need to find some time to read the documentation, but I'm quite sure that we do need the interrupt. About SDL events, the plan is to dump SDL in favour of GTK ;)

bobonis commented 8 years ago

I tried to study the documentation about the joypad signal and you were correct about the interrupt handling. I think I've implemented it correctly now but DragonBall is refusing to start. If you keep the start button pressed from bios, it goes to the next screen but then nothing...

Here a snippet of the code from Antonio when reading the joypad.

        u32 p1_reg = mem->IO_Ports[P1_REG-0xFF00];
        int Keys = GB_Input_Get(0);
        if((p1_reg & (1<<5)) == 0) //A-B-SEL-STA
        {
            result |= (Keys & KEY_A) ? JOY_A : 0;
            result |= (Keys & KEY_B) ? JOY_B : 0;
            result |= (Keys & KEY_SELECT) ? JOY_SELECT : 0;
            result |= (Keys & KEY_START) ? JOY_START : 0;
        }
        if((p1_reg & (1<<4)) == 0) //PAD
        {
            result |= (Keys & KEY_UP) ? JOY_UP : 0;
            result |= (Keys & KEY_DOWN) ? JOY_DOWN : 0;
            result |= (Keys & KEY_LEFT) ? JOY_LEFT : 0;
            result |= (Keys & KEY_RIGHT) ? JOY_RIGHT : 0;
        }

        result = (~result) & 0x0F;
        result |= p1_reg & 0xF0;
        result |= 0xC0;

        mem->IO_Ports[P1_REG-0xFF00] = result;

I'm afraid that the problem lays somewhere else. All the distorted graphics before the start screen might be an indication that we reach the start screen with wrong data.

Please go through the input code for a deskcheck and try adding some comments!

alam-R commented 8 years ago

Of course I'll check it!

Before that, have you checked this piece of code? Have you tried it? `unsigned char inputReadKeys(){

unsigned char joypad_state = memory[0xFF00];

if ((joypad_state & 0x10) == 0 ){ //Bit 4: Direction Keys selected joypad_state = joypad_state | (joypad & 0x0F); //Get 4 lower bits that represent direction keys } else if ((joypad_state & 0x20) == 0 ){ //Bit 5: Standard keys selected joypad_state = joypad_state | ((joypad & 0xF0) >> 4); //Get 4 higher bits that represent button keys } else{ printf(PRINT_RED "[DEBUG] Both direction and Standard" PRINT_RESET"\n"); joypad_state = joypad_state | (joypad & 0x0F); } return joypad_state;`

bobonis commented 8 years ago

Yeap! It works but this is a workaround. If Bits 4 and 5 are not selected, the register should return no key presses.

alam-R commented 8 years ago

My point is that perhaps joypad_state has to include joypad also in case both bits 4-5 are 0, it is the initial state of FF00 after all...

(I''ll provide my feedback as soon as I check the new input :))

bobonis commented 8 years ago

I think it's fixed now! Dragon Ball goes past start screen!

alam-R commented 8 years ago

Let's consider it closed!