Skip to content

Commit

Permalink
commit 150
Browse files Browse the repository at this point in the history
  • Loading branch information
alyosha-tas committed Aug 28, 2023
1 parent deff225 commit b74c6c7
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 184 deletions.
Binary file modified Assets/dll/GBAHawk.dll
Binary file not shown.
30 changes: 15 additions & 15 deletions libHawk/GBAHawk/GBA_System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2630,14 +2630,22 @@ namespace GBAHawk
// if not enabled, finish current fetch
if (pre_Run)
{
if ((pre_Fetch_Cnt != 0) || ((cpu_Regs[15] >= 0x08000000) && (cpu_Regs[15] < 0x0E000000)))
if ((cpu_Regs[15] >= 0x08000000) && (cpu_Regs[15] < 0x0E000000))
{
if (pre_Fetch_Cnt == 0)
{
if ((cpu_Instr_Type >= 42) && !pre_Seq_Access) {} // cannot start an access on the internal cycles of an instruction
else if (pre_Buffer_Cnt == 8) {} // don't start a read if buffer is full
else
{
if (pre_Previous_Thumb != cpu_Thumb_Mode)
{
pre_Check_Addr = 0;
pre_Buffer_Cnt = 0;
}

pre_Previous_Thumb = cpu_Thumb_Mode;

pre_Fetch_Wait = 1;

if (pre_Read_Addr < 0x0A000000)
Expand Down Expand Up @@ -2688,6 +2696,12 @@ namespace GBAHawk
}
}
}
else
{
pre_Buffer_Cnt = 0;
pre_Fetch_Cnt = 0;
pre_Check_Addr = 0;
}
}

#pragma endregion
Expand Down Expand Up @@ -3730,13 +3744,6 @@ namespace GBAHawk
// 32 bit fetch regardless of mode
cpu_Fetch_Wait = Wait_State_Access_32(cpu_Temp_Addr, cpu_Seq_Access);

if ((cpu_Multi_List_Ptr != 0) && (cpu_Temp_Addr == 0x08000000))
{
// special glitch case for prefetcher
pre_Buffer_Cnt = 0;
pre_Check_Addr = pre_Read_Addr;
}

cpu_IRQ_Input_Use = cpu_IRQ_Input;
}

Expand Down Expand Up @@ -4518,13 +4525,6 @@ namespace GBAHawk
// 32 bit fetch regardless of mode
cpu_Fetch_Wait = Wait_State_Access_32(cpu_Temp_Addr, cpu_Seq_Access);

if ((cpu_Multi_List_Ptr != 0) && (cpu_Temp_Addr == 0x08000000))
{
// special glitch case for prefetcher
pre_Buffer_Cnt = 0;
pre_Check_Addr = pre_Read_Addr;
}

cpu_IRQ_Input_Use = cpu_IRQ_Input;
}

Expand Down
100 changes: 24 additions & 76 deletions libHawk/GBAHawk/GBA_System.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ namespace GBAHawk

bool pre_Force_Non_Seq;

bool pre_Previous_Thumb;

uint32_t pre_Read_Addr, pre_Check_Addr;
uint32_t pre_Buffer_Cnt;

Expand Down Expand Up @@ -309,6 +311,8 @@ namespace GBAHawk
pre_Run = pre_Enable = pre_Seq_Access = false;

pre_Force_Non_Seq = false;

pre_Previous_Thumb = false;
}

void On_VBlank()
Expand Down Expand Up @@ -5124,24 +5128,15 @@ namespace GBAHawk
{
// lose 1 cycle if prefetcher is holding the bus
wait_ret += 1;

// additionally, the prefetch value is not added to the buffer
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}

//abandon the prefetcher current fetch
//abandon the prefetcher current fetch and reset
pre_Fetch_Cnt = 0;
pre_Seq_Access = false;
pre_Fetch_Cnt_Inc = 0;
pre_Run = pre_Enable;

// if the fetch was in ARM mode, discard the whole thing if only part was fetched
if (!cpu_Thumb_Mode && ((pre_Buffer_Cnt & 1) != 0))
{
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}
pre_Buffer_Cnt = 0;
pre_Check_Addr = 0;
}
}
else if (addr >= 0x05000000)
Expand Down Expand Up @@ -5248,24 +5243,15 @@ namespace GBAHawk
{
// lose 1 cycle if prefetcher is holding the bus
wait_ret += 1;

// additionally, the prefetch value is not added to the buffer
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}

//abandon the prefetcher current fetch
//abandon the prefetcher current fetch and reset
pre_Fetch_Cnt = 0;
pre_Seq_Access = false;
pre_Fetch_Cnt_Inc = 0;
pre_Run = pre_Enable;

// if the fetch was in ARM mode, discard the whole thing if only part was fetched
if (!cpu_Thumb_Mode && ((pre_Buffer_Cnt & 1) != 0))
{
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}
pre_Buffer_Cnt = 0;
pre_Check_Addr = 0;
}
}
else if (addr >= 0x05000000)
Expand Down Expand Up @@ -5372,24 +5358,15 @@ namespace GBAHawk
{
// lose 1 cycle if prefetcher is holding the bus
wait_ret += 1;

// additionally, the prefetch value is not added to the buffer
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}

//abandon the prefetcher current fetch
//abandon the prefetcher current fetch and reset
pre_Fetch_Cnt = 0;
pre_Seq_Access = false;
pre_Fetch_Cnt_Inc = 0;
pre_Run = pre_Enable;

// if the fetch was in ARM mode, discard the whole thing if only part was fetched
if (!cpu_Thumb_Mode && ((pre_Buffer_Cnt & 1) != 0))
{
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}
pre_Buffer_Cnt = 0;
pre_Check_Addr = 0;
}
}
else if (addr >= 0x05000000)
Expand Down Expand Up @@ -5529,24 +5506,15 @@ namespace GBAHawk
{
// lose 1 cycle if prefetcher is holding the bus
wait_ret += 1;

// additionally, the prefetch value is not added to the buffer
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}

//abandon the prefetcher current fetch
//abandon the prefetcher current fetch and reset
pre_Fetch_Cnt = 0;
pre_Seq_Access = false;
pre_Fetch_Cnt_Inc = 0;
pre_Run = pre_Enable;

// if the fetch was in ARM mode, discard the whole thing if only part was fetched
if (!cpu_Thumb_Mode && ((pre_Buffer_Cnt & 1) != 0))
{
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}
pre_Buffer_Cnt = 0;
pre_Check_Addr = 0;
}
}
else if (addr >= 0x05000000)
Expand Down Expand Up @@ -5740,24 +5708,15 @@ namespace GBAHawk
{
// lose 1 cycle if prefetcher is holding the bus
wait_ret += 1;

// additionally, the prefetch value is not added to the buffer
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}

//abandon the prefetcher current fetch
//abandon the prefetcher current fetch and reset
pre_Fetch_Cnt = 0;
pre_Seq_Access = false;
pre_Fetch_Cnt_Inc = 0;
pre_Run = pre_Enable;

// if the fetch was in ARM mode, discard the whole thing if only part was fetched
if (!cpu_Thumb_Mode && ((pre_Buffer_Cnt & 1) != 0))
{
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}
pre_Buffer_Cnt = 0;
pre_Check_Addr = 0;
}
}
else if (addr >= 0x05000000)
Expand Down Expand Up @@ -5934,10 +5893,6 @@ namespace GBAHawk
{
// lose 1 cycle if prefetcher is holding the bus
wait_ret += 1;

// additionally, the prefetch value is not added to the buffer
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}

//abandon the prefetcher current fetch and reset the address
Expand All @@ -5958,24 +5913,15 @@ namespace GBAHawk
{
// lose 1 cycle if prefetcher is holding the bus
wait_ret += 1;

// additionally, the prefetch value is not added to the buffer
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}

//abandon the prefetcher current fetch
//abandon the prefetcher current fetch and reset
pre_Fetch_Cnt = 0;
pre_Seq_Access = false;
pre_Fetch_Cnt_Inc = 0;
pre_Run = pre_Enable;

// if the fetch was in ARM mode, discard the whole thing if only part was fetched
if (!cpu_Thumb_Mode && ((pre_Buffer_Cnt & 1) != 0))
{
pre_Buffer_Cnt -= 1;
pre_Read_Addr -= 2;
}
pre_Buffer_Cnt = 0;
pre_Check_Addr = 0;
}
}
else if (addr >= 0x05000000)
Expand Down Expand Up @@ -13026,6 +12972,7 @@ namespace GBAHawk
saver = bool_saver(pre_Enable, saver);
saver = bool_saver(pre_Seq_Access, saver);
saver = bool_saver(pre_Force_Non_Seq, saver);
saver = bool_saver(pre_Previous_Thumb, saver);

saver = int_saver(pre_Read_Addr, saver);
saver = int_saver(pre_Check_Addr, saver);
Expand Down Expand Up @@ -13117,6 +13064,7 @@ namespace GBAHawk
loader = bool_loader(&pre_Enable, loader);
loader = bool_loader(&pre_Seq_Access, loader);
loader = bool_loader(&pre_Force_Non_Seq, loader);
loader = bool_loader(&pre_Previous_Thumb, loader);

loader = int_loader(&pre_Read_Addr, loader);
loader = int_loader(&pre_Check_Addr, loader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,13 +809,6 @@ public void cpu_Tick()
// 32 bit fetch regardless of mode
cpu_Fetch_Wait = Wait_State_Access_32(cpu_Temp_Addr, cpu_Seq_Access);

if ((cpu_Multi_List_Ptr != 0) && (cpu_Temp_Addr == 0x08000000))
{
// special glitch case for prefetcher
pre_Buffer_Cnt = 0;
pre_Check_Addr = pre_Read_Addr;
}

cpu_IRQ_Input_Use = cpu_IRQ_Input;
}

Expand Down Expand Up @@ -1597,13 +1590,6 @@ public void cpu_Tick()
// 32 bit fetch regardless of mode
cpu_Fetch_Wait = Wait_State_Access_32(cpu_Temp_Addr, cpu_Seq_Access);

if ((cpu_Multi_List_Ptr != 0) && (cpu_Temp_Addr == 0x08000000))
{
// special glitch case for prefetcher
pre_Buffer_Cnt = 0;
pre_Check_Addr = pre_Read_Addr;
}

cpu_IRQ_Input_Use = cpu_IRQ_Input;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public partial class GBAHawk_Debug

public bool pre_Force_Non_Seq;

public bool pre_Previous_Thumb;

public void pre_Reg_Write(ushort value)
{
if (!pre_Enable && ((value & 0x4000) == 0x4000))
Expand Down Expand Up @@ -84,12 +86,24 @@ public void pre_Tick()
// if not enabled, finish current fetch
if (pre_Run)
{
if ((pre_Fetch_Cnt != 0) || ((cpu_Regs[15] >= 0x08000000) && (cpu_Regs[15] < 0x0E000000)))
if ((cpu_Regs[15] >= 0x08000000) && (cpu_Regs[15] < 0x0E000000))
{
if (pre_Fetch_Cnt == 0)
{
if ((cpu_Instr_Type >= 42) && !pre_Seq_Access) { return; } // cannot start an access on the internal cycles of an instruction
if (pre_Buffer_Cnt == 8) { return; } // don't start a read if buffer is full
// cannot start an access on the internal cycles of an instruction
if ((cpu_Instr_Type >= 42) && !pre_Seq_Access) { return; }

// don't start a read if buffer is full
if (pre_Buffer_Cnt >= 8) { return; }

if (pre_Previous_Thumb != cpu_Thumb_Mode)
{
pre_Check_Addr = 0;
pre_Buffer_Cnt = 0;
pre_Seq_Access = false;
}

pre_Previous_Thumb = cpu_Thumb_Mode;

pre_Fetch_Wait = 1;

Expand Down Expand Up @@ -124,6 +138,13 @@ public void pre_Tick()
if (!pre_Enable) { pre_Run = false; }
}
}
else
{
pre_Buffer_Cnt = 0;
pre_Fetch_Cnt = 0;
pre_Check_Addr = 0;
pre_Seq_Access = false;
}
}
}

Expand All @@ -140,6 +161,8 @@ public void pre_Reset()
pre_Run = pre_Enable = pre_Seq_Access = false;

pre_Force_Non_Seq = false;

pre_Previous_Thumb = false;
}

public void pre_SyncState(Serializer ser)
Expand All @@ -152,6 +175,7 @@ public void pre_SyncState(Serializer ser)
ser.Sync(nameof(pre_Fetch_Wait), ref pre_Fetch_Wait);
ser.Sync(nameof(pre_Fetch_Cnt_Inc), ref pre_Fetch_Cnt_Inc);
ser.Sync(nameof(pre_Cycle_Glitch), ref pre_Cycle_Glitch);
ser.Sync(nameof(pre_Previous_Thumb), ref pre_Previous_Thumb);

ser.Sync(nameof(pre_Run), ref pre_Run);
ser.Sync(nameof(pre_Enable), ref pre_Enable);
Expand Down
Loading

0 comments on commit b74c6c7

Please sign in to comment.