2016-12-05 10:02:29 -07:00
|
|
|
/*
|
2024-06-15 09:01:19 -06:00
|
|
|
Copyright 2016-2024 melonDS team
|
2016-12-05 10:02:29 -07:00
|
|
|
|
|
|
|
This file is part of melonDS.
|
|
|
|
|
|
|
|
melonDS is free software: you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free
|
|
|
|
Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
melonDS 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 for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with melonDS. If not, see http://www.gnu.org/licenses/.
|
|
|
|
*/
|
|
|
|
|
2016-11-24 10:31:49 -07:00
|
|
|
#include "ARM.h"
|
2023-03-23 11:04:38 -06:00
|
|
|
#include "Platform.h"
|
2016-11-24 10:31:49 -07:00
|
|
|
|
2023-11-25 10:32:09 -07:00
|
|
|
namespace melonDS::ARMInterpreter
|
|
|
|
{
|
2023-03-23 11:04:38 -06:00
|
|
|
using Platform::Log;
|
|
|
|
using Platform::LogLevel;
|
2016-11-24 10:31:49 -07:00
|
|
|
|
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void A_B(ARM* cpu)
|
2016-11-24 10:31:49 -07:00
|
|
|
{
|
|
|
|
s32 offset = (s32)(cpu->CurInstr << 8) >> 6;
|
|
|
|
cpu->JumpTo(cpu->R[15] + offset);
|
|
|
|
}
|
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void A_BL(ARM* cpu)
|
2016-11-24 10:31:49 -07:00
|
|
|
{
|
|
|
|
s32 offset = (s32)(cpu->CurInstr << 8) >> 6;
|
|
|
|
cpu->R[14] = cpu->R[15] - 4;
|
|
|
|
cpu->JumpTo(cpu->R[15] + offset);
|
|
|
|
}
|
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void A_BLX_IMM(ARM* cpu)
|
2016-11-24 16:08:53 -07:00
|
|
|
{
|
|
|
|
s32 offset = (s32)(cpu->CurInstr << 8) >> 6;
|
|
|
|
if (cpu->CurInstr & 0x01000000) offset += 2;
|
|
|
|
cpu->R[14] = cpu->R[15] - 4;
|
|
|
|
cpu->JumpTo(cpu->R[15] + offset + 1);
|
|
|
|
}
|
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void A_BX(ARM* cpu)
|
2016-12-02 20:05:23 -07:00
|
|
|
{
|
|
|
|
cpu->JumpTo(cpu->R[cpu->CurInstr & 0xF]);
|
|
|
|
}
|
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void A_BLX_REG(ARM* cpu)
|
2016-12-02 20:05:23 -07:00
|
|
|
{
|
|
|
|
u32 lr = cpu->R[15] - 4;
|
|
|
|
cpu->JumpTo(cpu->R[cpu->CurInstr & 0xF]);
|
|
|
|
cpu->R[14] = lr;
|
|
|
|
}
|
|
|
|
|
2016-11-24 10:31:49 -07:00
|
|
|
|
2016-12-02 19:10:26 -07:00
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void T_BCOND(ARM* cpu)
|
2016-12-02 19:10:26 -07:00
|
|
|
{
|
|
|
|
if (cpu->CheckCondition((cpu->CurInstr >> 8) & 0xF))
|
|
|
|
{
|
|
|
|
s32 offset = (s32)(cpu->CurInstr << 24) >> 23;
|
|
|
|
cpu->JumpTo(cpu->R[15] + offset + 1);
|
|
|
|
}
|
2018-12-04 09:54:10 -07:00
|
|
|
else
|
|
|
|
cpu->AddCycles_C();
|
2016-12-02 19:10:26 -07:00
|
|
|
}
|
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void T_BX(ARM* cpu)
|
2016-12-02 20:05:23 -07:00
|
|
|
{
|
|
|
|
cpu->JumpTo(cpu->R[(cpu->CurInstr >> 3) & 0xF]);
|
|
|
|
}
|
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void T_BLX_REG(ARM* cpu)
|
2016-12-02 20:05:23 -07:00
|
|
|
{
|
|
|
|
if (cpu->Num==1)
|
|
|
|
{
|
2023-03-23 11:04:38 -06:00
|
|
|
Log(LogLevel::Warn, "!! THUMB BLX_REG ON ARM7\n");
|
2017-01-30 10:36:11 -07:00
|
|
|
return;
|
2016-12-02 20:05:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 lr = cpu->R[15] - 1;
|
|
|
|
cpu->JumpTo(cpu->R[(cpu->CurInstr >> 3) & 0xF]);
|
|
|
|
cpu->R[14] = lr;
|
|
|
|
}
|
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void T_B(ARM* cpu)
|
2016-12-03 09:58:24 -07:00
|
|
|
{
|
|
|
|
s32 offset = (s32)((cpu->CurInstr & 0x7FF) << 21) >> 20;
|
|
|
|
cpu->JumpTo(cpu->R[15] + offset + 1);
|
|
|
|
}
|
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void T_BL_LONG_1(ARM* cpu)
|
2016-12-03 07:15:34 -07:00
|
|
|
{
|
|
|
|
s32 offset = (s32)((cpu->CurInstr & 0x7FF) << 21) >> 9;
|
|
|
|
cpu->R[14] = cpu->R[15] + offset;
|
2018-12-04 09:54:10 -07:00
|
|
|
cpu->AddCycles_C();
|
2016-12-03 07:15:34 -07:00
|
|
|
}
|
|
|
|
|
2017-01-30 10:36:11 -07:00
|
|
|
void T_BL_LONG_2(ARM* cpu)
|
2016-12-03 07:15:34 -07:00
|
|
|
{
|
|
|
|
s32 offset = (cpu->CurInstr & 0x7FF) << 1;
|
|
|
|
u32 pc = cpu->R[14] + offset;
|
|
|
|
cpu->R[14] = (cpu->R[15] - 2) | 1;
|
|
|
|
|
|
|
|
if ((cpu->Num==1) || (cpu->CurInstr & (1<<12)))
|
|
|
|
pc |= 1;
|
|
|
|
|
|
|
|
cpu->JumpTo(pc);
|
|
|
|
}
|
|
|
|
|
2016-12-02 19:10:26 -07:00
|
|
|
|
|
|
|
|
2016-11-24 10:31:49 -07:00
|
|
|
}
|
|
|
|
|