libgambatte: joypad irq findings.

This commit is contained in:
sinamas 2014-07-22 02:50:34 +02:00
parent c1c13f9cbc
commit d8bb275e5e
5 changed files with 336 additions and 68 deletions

View File

@ -1,21 +1,22 @@
/***************************************************************************
* Copyright (C) 2007 by Sindre Aamås *
* sinamas@users.sourceforge.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License version 2 as *
* published by the Free Software Foundation. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License version 2 for more details. *
* *
* You should have received a copy of the GNU General Public License *
* version 2 along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
//
// Copyright (C) 2007 by Sindre Aamås
// sinamas@users.sourceforge.net
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License version 2 for more details.
//
// You should have received a copy of the GNU General Public License
// version 2 along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#include "cpu.h"
#include "memory.h"
#include "savestate.h"
@ -487,6 +488,7 @@ void CPU::loadState(SaveState const &state) {
void CPU::process(unsigned long const cycles) {
mem_.setEndtime(cycleCounter_, cycles);
mem_.updateInput();
unsigned char a = a_;
unsigned long cycleCounter = cycleCounter_;

View File

@ -1,21 +1,22 @@
/***************************************************************************
* Copyright (C) 2007 by Sindre Aamås *
* sinamas@users.sourceforge.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License version 2 as *
* published by the Free Software Foundation. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License version 2 for more details. *
* *
* You should have received a copy of the GNU General Public License *
* version 2 along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
//
// Copyright (C) 2007 by Sindre Aamås
// sinamas@users.sourceforge.net
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License version 2 for more details.
//
// You should have received a copy of the GNU General Public License
// version 2 along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#include "memory.h"
#include "inputgetter.h"
#include "savestate.h"
@ -371,21 +372,22 @@ unsigned long Memory::resetCounters(unsigned long cc) {
}
void Memory::updateInput() {
unsigned button = 0xFF;
unsigned dpad = 0xFF;
unsigned state = 0xF;
if (getInput_) {
unsigned is = (*getInput_)();
button ^= is & 0x0F;
dpad ^= is >> 4 & 0x0F;
if ((ioamhram_[0x100] & 0x30) != 0x30 && getInput_) {
unsigned input = (*getInput_)();
unsigned dpad_state = ~input >> 4;
unsigned button_state = ~input;
if (!(ioamhram_[0x100] & 0x10))
state &= dpad_state;
if (!(ioamhram_[0x100] & 0x20))
state &= button_state;
}
ioamhram_[0x100] |= 0xF;
if (state != 0xF && (ioamhram_[0x100] & 0xF) == 0xF)
intreq_.flagIrq(0x10);
if (!(ioamhram_[0x100] & 0x10))
ioamhram_[0x100] &= dpad;
if (!(ioamhram_[0x100] & 0x20))
ioamhram_[0x100] &= button;
ioamhram_[0x100] = (ioamhram_[0x100] & -0x10) | state;
}
void Memory::updateOamDma(unsigned long const cc) {
@ -591,8 +593,12 @@ void Memory::nontrivial_ff_write(unsigned const p, unsigned data, unsigned long
switch (p & 0xFF) {
case 0x00:
data = (ioamhram_[0x100] & 0xCF) | (data & 0xF0);
break;
if ((data ^ ioamhram_[0x100]) & 0x30) {
ioamhram_[0x100] = (ioamhram_[0x100] & ~0x30u) | (data & 0x30);
updateInput();
}
return;
case 0x01:
updateSerial(cc);
break;

View File

@ -1,21 +1,22 @@
/***************************************************************************
* Copyright (C) 2007 by Sindre Aamås *
* sinamas@users.sourceforge.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License version 2 as *
* published by the Free Software Foundation. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License version 2 for more details. *
* *
* You should have received a copy of the GNU General Public License *
* version 2 along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
//
// Copyright (C) 2007 by Sindre Aamås
// sinamas@users.sourceforge.net
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License version 2 for more details.
//
// You should have received a copy of the GNU General Public License
// version 2 along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#ifndef MEMORY_H
#define MEMORY_H
@ -107,6 +108,7 @@ public:
void setGameGenie(std::string const &codes) { cart_.setGameGenie(codes); }
void setGameShark(std::string const &codes) { interrupter_.setGameShark(codes); }
void updateInput();
private:
Cartridge cart_;
@ -125,7 +127,6 @@ private:
unsigned char serialCnt_;
bool blanklcd_;
void updateInput();
void decEventCycles(IntEventId eventId, unsigned long dec);
void oamDmaInitSetup();
void updateOamDma(unsigned long cycleCounter);

View File

@ -0,0 +1,120 @@
.size 8000
.text@60
pop af
ldff a, (80)
inc a
ldff(80), a
ei
jp lprint
.text@100
jp lbegin
.data@143
80
.text@150
lbegin:
ld b, 90
call lwaitly_b
xor a, a
ldff(40), a
ld bc, 7a00
ld hl, 8000
ld d, 00
lbegin_copytiles:
ld a, (bc)
inc bc
ld(hl++), a
dec d
jrnz lbegin_copytiles
xor a, a
ld(9800), a
ld(9801), a
ld a, c0
ldff(47), a
ld a, 80
ldff(68), a
ld a, ff
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
xor a, a
ldff(69), a
ldff(69), a
ldff(43), a
ld a, 91
ldff(40), a
ld a, 10
ldff(ff), a
xor a, a
ldff(00), a
ldff(0f), a
ldff(80), a
ei
jp lprint
.text@7000
lprint:
ld b, 90
lprint_waitly90:
ldff a, (44)
cmp a, b
jrnz lprint_waitly90
ldff a, (80)
rrca
rrca
rrca
rrca
and a, 0f
ld(9800), a
ldff a, (80)
and a, 0f
ld(9801), a
halt
.text@7400
lwaitly_b:
ldff a, (44)
cmp a, b
jrnz lwaitly_b
ret
.data@7a00
00 00 7f 7f 41 41 41 41
41 41 41 41 41 41 7f 7f
00 00 08 08 08 08 08 08
08 08 08 08 08 08 08 08
00 00 7f 7f 01 01 01 01
7f 7f 40 40 40 40 7f 7f
00 00 7f 7f 01 01 01 01
3f 3f 01 01 01 01 7f 7f
00 00 41 41 41 41 41 41
7f 7f 01 01 01 01 01 01
00 00 7f 7f 40 40 40 40
7e 7e 01 01 01 01 7e 7e
00 00 7f 7f 40 40 40 40
7f 7f 41 41 41 41 7f 7f
00 00 7f 7f 01 01 02 02
04 04 08 08 10 10 10 10
00 00 3e 3e 41 41 41 41
3e 3e 41 41 41 41 3e 3e
00 00 7f 7f 41 41 41 41
7f 7f 01 01 01 01 7f 7f
00 00 08 08 22 22 41 41
7f 7f 41 41 41 41 41 41
00 00 7e 7e 41 41 41 41
7e 7e 41 41 41 41 7e 7e
00 00 3e 3e 41 41 40 40
40 40 40 40 41 41 3e 3e
00 00 7e 7e 41 41 41 41
41 41 41 41 41 41 7e 7e
00 00 7f 7f 40 40 40 40
7f 7f 40 40 40 40 7f 7f
00 00 7f 7f 40 40 40 40
7f 7f 40 40 40 40 40 40

View File

@ -0,0 +1,139 @@
.size 8000
.text@60
pop af
ldff a, (80)
inc a
ldff(80), a
ei
jp lprint
.text@100
jp lbegin
.data@143
80
.text@150
lbegin:
ld b, 90
call lwaitly_b
xor a, a
ldff(40), a
ld bc, 7a00
ld hl, 8000
ld d, 00
lbegin_copytiles:
ld a, (bc)
inc bc
ld(hl++), a
dec d
jrnz lbegin_copytiles
xor a, a
ld(9800), a
ld(9801), a
ld a, c0
ldff(47), a
ld a, 80
ldff(68), a
ld a, ff
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
xor a, a
ldff(69), a
ldff(69), a
ldff(43), a
ld a, 91
ldff(40), a
ld a, 10
ldff(00), a
ldff(ff), a
xor a, a
ldff(0f), a
ldff(80), a
ldff(81), a
ei
jp lprint
.text@7000
lprint:
ld b, 90
lprint_waitly90:
ldff a, (44)
cmp a, b
jrnz lprint_waitly90
ldff a, (80)
rrca
rrca
rrca
rrca
and a, 0f
ld(9800), a
ldff a, (80)
and a, 0f
ld(9801), a
ldff a, (00)
ld b, a
rrca
rrca
rrca
rrca
and a, 0f
ld(9802), a
ld a, b
and a, 0f
ld(9803), a
ldff a, (81)
inc a
ldff(81), a
jrnz lprint
ld a, b
xor a, 30
ldff(00), a
jr lprint
.text@7400
lwaitly_b:
ldff a, (44)
cmp a, b
jrnz lwaitly_b
ret
.data@7a00
00 00 7f 7f 41 41 41 41
41 41 41 41 41 41 7f 7f
00 00 08 08 08 08 08 08
08 08 08 08 08 08 08 08
00 00 7f 7f 01 01 01 01
7f 7f 40 40 40 40 7f 7f
00 00 7f 7f 01 01 01 01
3f 3f 01 01 01 01 7f 7f
00 00 41 41 41 41 41 41
7f 7f 01 01 01 01 01 01
00 00 7f 7f 40 40 40 40
7e 7e 01 01 01 01 7e 7e
00 00 7f 7f 40 40 40 40
7f 7f 41 41 41 41 7f 7f
00 00 7f 7f 01 01 02 02
04 04 08 08 10 10 10 10
00 00 3e 3e 41 41 41 41
3e 3e 41 41 41 41 3e 3e
00 00 7f 7f 41 41 41 41
7f 7f 01 01 01 01 7f 7f
00 00 08 08 22 22 41 41
7f 7f 41 41 41 41 41 41
00 00 7e 7e 41 41 41 41
7e 7e 41 41 41 41 7e 7e
00 00 3e 3e 41 41 40 40
40 40 40 40 41 41 3e 3e
00 00 7e 7e 41 41 41 41
41 41 41 41 41 41 7e 7e
00 00 7f 7f 40 40 40 40
7f 7f 40 40 40 40 7f 7f
00 00 7f 7f 40 40 40 40
7f 7f 40 40 40 40 40 40