dev_4VirtualNes #23

Merged
sin365 merged 35 commits from dev_4VirtualNes into master 2024-08-05 17:49:44 +08:00
3 changed files with 83 additions and 0 deletions
Showing only changes of commit d7846c7182 - Show all commits

View File

@ -78,6 +78,7 @@ namespace VirtualNes.Core
public static Mapper CreateMapper(NES parent, int no) public static Mapper CreateMapper(NES parent, int no)
{ {
//todo : 实现加载mapper
switch (no) switch (no)
{ {
default: default:

View File

@ -8,6 +8,8 @@ namespace VirtualNes.Core
{ {
public class NES public class NES
{ {
public const int FETCH_CYCLES = 8;
public CPU cpu; public CPU cpu;
public PPU ppu; public PPU ppu;
public APU apu; public APU apu;
@ -181,7 +183,25 @@ namespace VirtualNes.Core
if (RenderMethod < EnumRenderMethod.POST_RENDER) if (RenderMethod < EnumRenderMethod.POST_RENDER)
{ {
EmulationCPU(nescfg.ScanlineCycles); EmulationCPU(nescfg.ScanlineCycles);
ppu.FrameStart();
ppu.ScanlineNext();
mapper.HSync(scanline);
ppu.ScanlineStart();
} }
else
{
EmulationCPU(nescfg.HDrawCycles);
ppu.FrameStart();
ppu.ScanlineNext();
mapper.HSync(scanline);
EmulationCPU(FETCH_CYCLES * 32);
ppu.ScanlineStart();
EmulationCPU(FETCH_CYCLES * 10 + nescfg.ScanlineEndCycles);
}
}
else if (scanline < 240)
{
} }
} }
} }

View File

@ -363,6 +363,68 @@ namespace VirtualNes.Core
MemoryUtility.memset(lpColormode, 0, (int)(Screen.SCREEN_HEIGHT)); MemoryUtility.memset(lpColormode, 0, (int)(Screen.SCREEN_HEIGHT));
} }
internal void FrameStart()
{
if ((MMU.PPUREG[1] & (PPU_SPDISP_BIT | PPU_BGDISP_BIT)) != 0)
{
MMU.loopy_v = MMU.loopy_t;
loopy_shift = MMU.loopy_x;
loopy_y = (ushort)((MMU.loopy_v & 0x7000) >> 12);
}
if (lpScreen != null)
{
MemoryUtility.memset(lpScreen, 0x3F, (int)Screen.SCREEN_WIDTH);
}
if (lpColormode != null)
{
lpColormode[0] = 0;
}
}
internal void ScanlineNext()
{
if ((MMU.PPUREG[1] & (PPU_BGDISP_BIT | PPU_SPDISP_BIT)) != 0)
{
if ((MMU.loopy_v & 0x7000) == 0x7000)
{
MMU.loopy_v &= 0x8FFF;
if ((MMU.loopy_v & 0x03E0) == 0x03A0)
{
MMU.loopy_v ^= 0x0800;
MMU.loopy_v &= 0xFC1F;
}
else
{
if ((MMU.loopy_v & 0x03E0) == 0x03E0)
{
MMU.loopy_v &= 0xFC1F;
}
else
{
MMU.loopy_v += 0x0020;
}
}
}
else
{
MMU.loopy_v += 0x1000;
}
loopy_y = (ushort)((MMU.loopy_v & 0x7000) >> 12);
}
}
internal void ScanlineStart()
{
if ((MMU.PPUREG[1] & (PPU_BGDISP_BIT | PPU_SPDISP_BIT)) != 0)
{
MMU.loopy_v = (ushort)((MMU.loopy_v & 0xFBE0) | (MMU.loopy_t & 0x041F));
loopy_shift = MMU.loopy_x;
loopy_y = (ushort)((MMU.loopy_v & 0x7000) >> 12);
nes.mapper.PPU_Latch((ushort)(0x2000 + (MMU.loopy_v & 0x0FFF)));
}
}
private enum Screen private enum Screen
{ {
SCREEN_WIDTH = 256 + 16, SCREEN_WIDTH = 256 + 16,