Skip to content

Commit 9c5ed6a

Browse files
author
aquanull
committed
This shall fix some input problems during GB white screen period.
1 parent 18eaae6 commit 9c5ed6a

File tree

4 files changed

+130
-108
lines changed

4 files changed

+130
-108
lines changed

src/gb/V7/GB.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,7 +3169,7 @@ static void gbDrawPixLine()
31693169
}
31703170
}
31713171

3172-
static void gbGetUserInput()
3172+
static inline void gbGetUserInput()
31733173
{
31743174
// update joystick information
31753175
systemReadJoypads();
@@ -3207,15 +3207,27 @@ static void gbGetUserInput()
32073207
speedup = (extButtons & 1) != 0;
32083208
}
32093209

3210-
static void gbFrameBoundaryWork()
3210+
static inline void gbBeforeEmulation()
32113211
{
3212-
//gbGetUserInput();
3213-
3214-
bool sensor = (gbRom[0x147] == 0x22);
3215-
if (sensor)
3212+
if (newFrame)
32163213
{
3217-
// systemUpdateMotionSensor();
3214+
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
3215+
3216+
gbGetUserInput();
3217+
3218+
if (gbRom[0x147] == 0x22)
3219+
{
3220+
//systemUpdateMotionSensor();
3221+
}
3222+
3223+
VBAMovieResetIfRequested();
3224+
3225+
newFrame = false;
32183226
}
3227+
}
3228+
3229+
static inline void gbFrameBoundaryWork()
3230+
{
32193231
if (!gbSgbMask)
32203232
{
32213233
if (gbBorderOn)
@@ -3227,24 +3239,15 @@ static void gbFrameBoundaryWork()
32273239

32283240
void gbEmulate(int ticksToStop)
32293241
{
3242+
gbBeforeEmulation();
3243+
32303244
gbRegister tempRegister;
32313245
u8 tempValue;
32323246
s8 offset;
32333247

32343248
int gbClockTicks = 0;
32353249
gbDmaTicks = 0;
32363250

3237-
if (newFrame)
3238-
{
3239-
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
3240-
3241-
gbGetUserInput();
3242-
3243-
VBAMovieResetIfRequested();
3244-
3245-
newFrame = false;
3246-
}
3247-
32483251
for (;;)
32493252
{
32503253
#ifndef FINAL_VERSION

src/gb/V8/GB.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4981,7 +4981,7 @@ static void gbDrawPixLine()
49814981
}
49824982
}
49834983

4984-
static void gbGetUserInput()
4984+
static inline void gbGetUserInput()
49854985
{
49864986
// update joystick information
49874987
systemReadJoypads();
@@ -5016,15 +5016,27 @@ static void gbGetUserInput()
50165016
speedup = (extButtons & 1) != 0;
50175017
}
50185018

5019-
static void gbFrameBoundaryWork()
5019+
static inline void gbBeforeEmulation()
50205020
{
5021-
//gbGetUserInput();
5022-
5023-
bool sensor = (gbRom[0x147] == 0x22);
5024-
if (sensor)
5021+
if (newFrame)
50255022
{
5026-
// systemUpdateMotionSensor();
5023+
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
5024+
5025+
gbGetUserInput();
5026+
5027+
if (gbRom[0x147] == 0x22)
5028+
{
5029+
//systemUpdateMotionSensor();
5030+
}
5031+
5032+
VBAMovieResetIfRequested();
5033+
5034+
newFrame = false;
50275035
}
5036+
}
5037+
5038+
static inline void gbFrameBoundaryWork()
5039+
{
50285040
if (!gbSgbMask)
50295041
{
50305042
if (gbBorderOn)
@@ -5036,6 +5048,8 @@ static void gbFrameBoundaryWork()
50365048

50375049
void gbEmulate(int ticksToStop)
50385050
{
5051+
gbBeforeEmulation();
5052+
50395053
gbRegister tempRegister;
50405054
u8 tempValue;
50415055
s8 offset;
@@ -5047,17 +5061,6 @@ void gbEmulate(int ticksToStop)
50475061
int opcode2 = 0;
50485062
bool execute = false;
50495063

5050-
if (newFrame)
5051-
{
5052-
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
5053-
5054-
gbGetUserInput();
5055-
5056-
VBAMovieResetIfRequested();
5057-
5058-
newFrame = false;
5059-
}
5060-
50615064
for (;;)
50625065
{
50635066
#ifndef FINAL_VERSION
@@ -5637,6 +5640,7 @@ void gbEmulate(int ticksToStop)
56375640
}
56385641
else if (register_LY == 144)
56395642
{
5643+
gbBeforeEmulation();
56405644
gbFrameBoundaryWork();
56415645
}
56425646
}
@@ -5861,8 +5865,7 @@ void gbEmulate(int ticksToStop)
58615865
++stopCounter;
58625866
if (gbV20GBFrameTimingHackTemp && stopCounter % 64 == 0)
58635867
{
5864-
gbGetUserInput();
5865-
VBAMovieResetIfRequested();
5868+
gbBeforeEmulation();
58665869
gbFrameBoundaryWork();
58675870
}
58685871
}

src/gba/V7/GBA.cpp

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3601,47 +3601,64 @@ static inline void CPUDrawPixLine()
36013601
}
36023602
}
36033603

3604-
static void CPUGetUserInput()
3604+
static inline u32 CPUGetUserInput()
36053605
{
36063606
// update joystick information
36073607
systemReadJoypads();
36083608

36093609
u32 joy = systemGetJoypad(0, cpuEEPROMSensorEnabled);
3610-
//if (cpuEEPROMSensorEnabled)
3611-
//systemUpdateMotionSensor(0);
36123610

36133611
P1 = 0x03FF ^ (joy & 0x3FF);
36143612
UPDATE_REG(0x130, P1);
3615-
u16 P1CNT = READ16LE(((u16 *)&ioMem[0x132]));
36163613

3617-
// this seems wrong, but there are cases where the game
3618-
// can enter the stop state without requesting an IRQ from
3619-
// the joypad.
3620-
// FIXME: where is the right place???
3621-
if ((P1CNT & 0x4000) || stopState)
3614+
// HACK: some special "buttons"
3615+
extButtons = (joy >> 18);
3616+
speedup = (extButtons & 1) != 0;
3617+
3618+
return joy;
3619+
}
3620+
3621+
static inline void CPUBeforeEmulation()
3622+
{
3623+
if (newFrame)
36223624
{
3623-
u16 p1 = (0x3FF ^ P1) & 0x3FF;
3624-
if (P1CNT & 0x8000)
3625+
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
3626+
3627+
u32 joy = CPUGetUserInput();
3628+
3629+
// this seems wrong, but there are cases where the game
3630+
// can enter the stop state without requesting an IRQ from
3631+
// the joypad.
3632+
// FIXME: where is the right place???
3633+
u16 P1CNT = READ16LE(((u16 *)&ioMem[0x132]));
3634+
if ((P1CNT & 0x4000) || stopState)
36253635
{
3626-
if (p1 == (P1CNT & 0x3FF))
3636+
u16 p1 = (0x3FF ^ P1) & 0x3FF;
3637+
if (P1CNT & 0x8000)
36273638
{
3628-
IF |= 0x1000;
3629-
UPDATE_REG(0x202, IF);
3639+
if (p1 == (P1CNT & 0x3FF))
3640+
{
3641+
IF |= 0x1000;
3642+
UPDATE_REG(0x202, IF);
3643+
}
36303644
}
3631-
}
3632-
else
3633-
{
3634-
if (p1 & P1CNT)
3645+
else
36353646
{
3636-
IF |= 0x1000;
3637-
UPDATE_REG(0x202, IF);
3647+
if (p1 & P1CNT)
3648+
{
3649+
IF |= 0x1000;
3650+
UPDATE_REG(0x202, IF);
3651+
}
36383652
}
36393653
}
3640-
}
36413654

3642-
// HACK: some special "buttons"
3643-
extButtons = (joy >> 18);
3644-
speedup = (extButtons & 1) != 0;
3655+
//if (cpuEEPROMSensorEnabled)
3656+
//systemUpdateMotionSensor(0);
3657+
3658+
VBAMovieResetIfRequested();
3659+
3660+
newFrame = false;
3661+
}
36453662
}
36463663

36473664
static inline void CPUFrameBoundaryWork()
@@ -3655,6 +3672,8 @@ static inline void CPUFrameBoundaryWork()
36553672

36563673
void CPULoop(int _ticks)
36573674
{
3675+
CPUBeforeEmulation();
3676+
36583677
int32 ticks = _ticks;
36593678
int32 clockTicks;
36603679
int32 cpuNextEvent = 0;
@@ -3678,17 +3697,6 @@ void CPULoop(int _ticks)
36783697
cpuSavedTicks = 5;
36793698
}
36803699

3681-
if (newFrame)
3682-
{
3683-
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
3684-
3685-
CPUGetUserInput();
3686-
3687-
VBAMovieResetIfRequested();
3688-
3689-
newFrame = false;
3690-
}
3691-
36923700
for (;;)
36933701
{
36943702
#ifndef FINAL_VERSION

src/gba/V8/GBA.cpp

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3734,47 +3734,64 @@ static inline void CPUDrawPixLine()
37343734
}
37353735
}
37363736

3737-
static void CPUGetUserInput()
3737+
static inline u32 CPUGetUserInput()
37383738
{
37393739
// update joystick information
37403740
systemReadJoypads();
37413741

37423742
u32 joy = systemGetJoypad(0, cpuEEPROMSensorEnabled);
3743-
//if (cpuEEPROMSensorEnabled)
3744-
//systemUpdateMotionSensor(0);
37453743

37463744
P1 = 0x03FF ^ (joy & 0x3FF);
37473745
UPDATE_REG(0x130, P1);
3748-
u16 P1CNT = READ16LE(((u16 *)&ioMem[0x132]));
37493746

3750-
// this seems wrong, but there are cases where the game
3751-
// can enter the stop state without requesting an IRQ from
3752-
// the joypad.
3753-
// FIXME: where is the right place???
3754-
if ((P1CNT & 0x4000) || stopState)
3747+
// HACK: some special "buttons"
3748+
extButtons = (joy >> 18);
3749+
speedup = (extButtons & 1) != 0;
3750+
3751+
return joy;
3752+
}
3753+
3754+
static inline void CPUBeforeEmulation()
3755+
{
3756+
if (newFrame)
37553757
{
3756-
u16 p1 = (0x3FF ^ P1) & 0x3FF;
3757-
if (P1CNT & 0x8000)
3758+
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
3759+
3760+
u32 joy = CPUGetUserInput();
3761+
3762+
// this seems wrong, but there are cases where the game
3763+
// can enter the stop state without requesting an IRQ from
3764+
// the joypad.
3765+
// FIXME: where is the right place???
3766+
u16 P1CNT = READ16LE(((u16 *)&ioMem[0x132]));
3767+
if ((P1CNT & 0x4000) || stopState)
37583768
{
3759-
if (p1 == (P1CNT & 0x3FF))
3769+
u16 p1 = (0x3FF ^ P1) & 0x3FF;
3770+
if (P1CNT & 0x8000)
37603771
{
3761-
IF |= 0x1000;
3762-
UPDATE_REG(0x202, IF);
3772+
if (p1 == (P1CNT & 0x3FF))
3773+
{
3774+
IF |= 0x1000;
3775+
UPDATE_REG(0x202, IF);
3776+
}
37633777
}
3764-
}
3765-
else
3766-
{
3767-
if (p1 & P1CNT)
3778+
else
37683779
{
3769-
IF |= 0x1000;
3770-
UPDATE_REG(0x202, IF);
3780+
if (p1 & P1CNT)
3781+
{
3782+
IF |= 0x1000;
3783+
UPDATE_REG(0x202, IF);
3784+
}
37713785
}
37723786
}
3773-
}
37743787

3775-
// HACK: some special "buttons"
3776-
extButtons = (joy >> 18);
3777-
speedup = (extButtons & 1) != 0;
3788+
//if (cpuEEPROMSensorEnabled)
3789+
//systemUpdateMotionSensor(0);
3790+
3791+
VBAMovieResetIfRequested();
3792+
3793+
newFrame = false;
3794+
}
37783795
}
37793796

37803797
static inline void CPUFrameBoundaryWork()
@@ -3788,6 +3805,8 @@ static inline void CPUFrameBoundaryWork()
37883805

37893806
void CPULoop(int _ticks)
37903807
{
3808+
CPUBeforeEmulation();
3809+
37913810
int32 ticks = _ticks;
37923811
int32 clockTicks;
37933812
int32 timerOverflow = 0;
@@ -3803,17 +3822,6 @@ void CPULoop(int _ticks)
38033822
cpuBreakLoop = false;
38043823
#endif
38053824

3806-
if (newFrame)
3807-
{
3808-
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
3809-
3810-
CPUGetUserInput();
3811-
3812-
VBAMovieResetIfRequested();
3813-
3814-
newFrame = false;
3815-
}
3816-
38173825
for (;;)
38183826
{
38193827
#ifndef FINAL_VERSION

0 commit comments

Comments
 (0)