ROMDB提交,Mapper修復

This commit is contained in:
ALIENJACK\alien 2024-08-06 13:49:24 +08:00
parent c7f32874ae
commit e4da00136d
31 changed files with 22702 additions and 1450 deletions

3
.gitignore vendored
View File

@ -14,3 +14,6 @@
/AxibugEmuOnline.Client/ProjectSettings/AutoStreamingSettings.asset /AxibugEmuOnline.Client/ProjectSettings/AutoStreamingSettings.asset
/AxibugEmuOnline.Client/Logs /AxibugEmuOnline.Client/Logs
/virtuanessrc097-master/save /virtuanessrc097-master/save
/virtuanessrc097-master/.vs
/virtuanessrc097-master/Debug
/virtuanessrc097-master/VirtualNES.ini

File diff suppressed because it is too large Load Diff

View File

@ -3,8 +3,11 @@ using System.Diagnostics;
using UnityEngine; using UnityEngine;
using VirtualNes.Core; using VirtualNes.Core;
public class AudioProvider : MonoBehaviour namespace AxibugEmuOnline.Client
{ {
public class AudioProvider : MonoBehaviour
{
[SerializeField] [SerializeField]
private AudioSource m_as; private AudioSource m_as;
@ -44,4 +47,6 @@ public class AudioProvider : MonoBehaviour
{ {
nes.apu.Process(_buffer, (uint)(Supporter.Config.sound.nRate * Time.deltaTime)); nes.apu.Process(_buffer, (uint)(Supporter.Config.sound.nRate * Time.deltaTime));
} }
}
} }

View File

@ -17,7 +17,7 @@ namespace AxibugEmuOnline.Client
private void Start() private void Start()
{ {
Application.targetFrameRate = 60; Application.targetFrameRate = 60;
StartGame("tstd2.nes"); StartGame("ff1.nes");
} }
public void StartGame(string romName) public void StartGame(string romName)
@ -44,7 +44,6 @@ namespace AxibugEmuOnline.Client
m_nesIns = null; m_nesIns = null;
} }
private void Update() private void Update()
{ {
if (m_nesIns != null) if (m_nesIns != null)

View File

@ -30,7 +30,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 4232056521131536011} m_Father: {fileID: 4232056521131536011}
m_RootOrder: 1 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &9003897287163669553 --- !u!114 &9003897287163669553
MonoBehaviour: MonoBehaviour:
@ -141,6 +141,78 @@ AudioSource:
m_PreInfinity: 2 m_PreInfinity: 2
m_PostInfinity: 2 m_PostInfinity: 2
m_RotationOrder: 4 m_RotationOrder: 4
--- !u!1 &3545890545112170401
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1038087993597378172}
- component: {fileID: 3032498056073774270}
- component: {fileID: 634277252673086327}
m_Layer: 5
m_Name: Viewer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1038087993597378172
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3545890545112170401}
m_LocalRotation: {x: 1, y: 0, z: 0, w: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4232056520494431727}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 180, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 128, y: 256}
m_Pivot: {x: 0, y: 0}
--- !u!222 &3032498056073774270
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3545890545112170401}
m_CullTransparentMesh: 1
--- !u!114 &634277252673086327
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3545890545112170401}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 8400000, guid: ffe34aaf87e4b9942b4c2ac05943d444, type: 2}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!1 &4232056520112715746 --- !u!1 &4232056520112715746
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -168,8 +240,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children: []
- {fileID: 4232056520494431727}
m_Father: {fileID: 4232056521131536011} m_Father: {fileID: 4232056521131536011}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -217,8 +288,9 @@ RectTransform:
m_LocalScale: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0, y: 0, z: 0}
m_Children: m_Children:
- {fileID: 4232056521759880275} - {fileID: 4232056521759880275}
m_Father: {fileID: 4232056520112715745} - {fileID: 1038087993597378172}
m_RootOrder: 0 m_Father: {fileID: 4232056521131536011}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
@ -315,7 +387,9 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 4232056520112715745} - {fileID: 4232056520112715745}
- {fileID: 393435831810118449}
- {fileID: 4785916497946256520} - {fileID: 4785916497946256520}
- {fileID: 4232056520494431727}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -405,3 +479,47 @@ MonoBehaviour:
y: 0 y: 0
width: 1 width: 1
height: 1 height: 1
--- !u!1 &7856060136050839404
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 393435831810118449}
- component: {fileID: 499856625911497759}
m_Layer: 0
m_Name: PatternViewer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &393435831810118449
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7856060136050839404}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4232056521131536011}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &499856625911497759
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7856060136050839404}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c7a50c189f5be5b4ea54de444f8488a0, type: 3}
m_Name:
m_EditorClassIdentifier:
img: {fileID: 634277252673086327}

View File

@ -7,10 +7,18 @@ using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using VirtualNes.Core; using VirtualNes.Core;
namespace AxibugEmuOnline.Client.Assets.Script.NesEmulator namespace AxibugEmuOnline.Client
{ {
public static class PaletteDefine public static class PaletteDefine
{ {
public struct RGBQUAD
{
public byte rgbBlue;
public byte rgbGreen;
public byte rgbRed;
public byte rgbReserved;
}
public class PALBUF public class PALBUF
{ {
public byte r; public byte r;
@ -108,6 +116,33 @@ namespace AxibugEmuOnline.Client.Assets.Script.NesEmulator
new PALBUF(0x00, 0x00, 0x00), new PALBUF(0x00, 0x00, 0x00),
}; };
#region 256
// Color
public static RGBQUAD[][] m_cpPalette = new RGBQUAD[8][]
{
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
};
// Monochrome
public static RGBQUAD[][] m_mpPalette = new RGBQUAD[8][]
{
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
new RGBQUAD[64*2],
};
#endregion
#region #region
// Color // Color
public static uint[][] m_cnPalette = new uint[8][] public static uint[][] m_cnPalette = new uint[8][]
@ -161,6 +196,18 @@ namespace AxibugEmuOnline.Client.Assets.Script.NesEmulator
}; };
#endregion #endregion
public static RGBQUAD[] GetPaletteData()
{
RGBQUAD[] rgb = new RGBQUAD[256];
for (int i = 0; i < 64; i++)
{
rgb[i] = m_cpPalette[0][i];
rgb[i + 0x40] = m_mpPalette[0][i];
}
return rgb;
}
static PaletteDefine() static PaletteDefine()
{ {
int Rbit = 0, Gbit = 0, Bbit = 0; int Rbit = 0, Gbit = 0, Bbit = 0;
@ -186,6 +233,13 @@ namespace AxibugEmuOnline.Client.Assets.Script.NesEmulator
Gs = (uint)(PalConvTbl[j][1] * m_PaletteBuf[i].g * m_nScanlineColor / 100.0f); Gs = (uint)(PalConvTbl[j][1] * m_PaletteBuf[i].g * m_nScanlineColor / 100.0f);
Bs = (uint)(PalConvTbl[j][2] * m_PaletteBuf[i].b * m_nScanlineColor / 100.0f); Bs = (uint)(PalConvTbl[j][2] * m_PaletteBuf[i].b * m_nScanlineColor / 100.0f);
m_cpPalette[j][i + 0x00].rgbRed = (byte)Rn;
m_cpPalette[j][i + 0x00].rgbGreen = (byte)Gn;
m_cpPalette[j][i + 0x00].rgbBlue = (byte)Bn;
m_cpPalette[j][i + 0x40].rgbRed = (byte)Rs;
m_cpPalette[j][i + 0x40].rgbGreen = (byte)Gs;
m_cpPalette[j][i + 0x40].rgbBlue = (byte)Bs;
m_cnPalette[j][i] = ((Rn >> (8 - Rbit)) << Rsft) | ((Gn >> (8 - Gbit)) << Gsft) | ((Bn >> (8 - Bbit)) << Bsft); m_cnPalette[j][i] = ((Rn >> (8 - Rbit)) << Rsft) | ((Gn >> (8 - Gbit)) << Gsft) | ((Bn >> (8 - Bbit)) << Bsft);
m_csPalette[j][i] = ((Rs >> (8 - Rbit)) << Rsft) | ((Gs >> (8 - Gbit)) << Gsft) | ((Bs >> (8 - Bbit)) << Bsft); m_csPalette[j][i] = ((Rs >> (8 - Rbit)) << Rsft) | ((Gs >> (8 - Gbit)) << Gsft) | ((Bs >> (8 - Bbit)) << Bsft);
@ -216,6 +270,13 @@ namespace AxibugEmuOnline.Client.Assets.Script.NesEmulator
if (Gs > 0xFF) Gs = 0xFF; if (Gs > 0xFF) Gs = 0xFF;
if (Bs > 0xFF) Bs = 0xFF; if (Bs > 0xFF) Bs = 0xFF;
m_mpPalette[j][i + 0x00].rgbRed = (byte)Rn;
m_mpPalette[j][i + 0x00].rgbGreen = (byte)Gn;
m_mpPalette[j][i + 0x00].rgbBlue = (byte)Bn;
m_mpPalette[j][i + 0x40].rgbRed = (byte)Rs;
m_mpPalette[j][i + 0x40].rgbGreen = (byte)Gs;
m_mpPalette[j][i + 0x40].rgbBlue = (byte)Bs;
m_mnPalette[j][i] = ((Rn >> (8 - Rbit)) << Rsft) | ((Gn >> (8 - Gbit)) << Gsft) | ((Bn >> (8 - Bbit)) << Bsft); m_mnPalette[j][i] = ((Rn >> (8 - Rbit)) << Rsft) | ((Gn >> (8 - Gbit)) << Gsft) | ((Bn >> (8 - Bbit)) << Bsft);
m_msPalette[j][i] = ((Rs >> (8 - Rbit)) << Rsft) | ((Gs >> (8 - Gbit)) << Gsft) | ((Bs >> (8 - Bbit)) << Bsft); m_msPalette[j][i] = ((Rs >> (8 - Rbit)) << Rsft) | ((Gs >> (8 - Gbit)) << Gsft) | ((Bs >> (8 - Bbit)) << Bsft);
} }

View File

@ -0,0 +1,75 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using VirtualNes;
using static AxibugEmuOnline.Client.PaletteDefine;
namespace AxibugEmuOnline.Client
{
public class PatternViewer : MonoBehaviour
{
public RawImage img;
private Color32[] m_lpPattern = new Color32[128 * 256];
private Texture2D m_texture;
private Dictionary<byte, RGBQUAD> colors = new Dictionary<byte, RGBQUAD>();
private void Awake()
{
m_texture = new Texture2D(128, 256);
}
private void Update()
{
Paint();
}
public void Paint()
{
img.texture = m_texture;
var pal = MMU.SPPAL;
var palette = PaletteDefine.GetPaletteData();
colors[0] = palette[pal[0]];
colors[1] = palette[pal[1]];
colors[2] = palette[pal[2]];
colors[3] = palette[pal[3]];
for (int i = 0; i < 8; i++)
{
var Ptn = MMU.PPU_MEM_BANK[i];
int lpPtn = 0;
for (int p = 0; p < 64; p++)
{
int lpScn = i * 32 * 128 + (p & 15) * 8 + (p / 16) * 8 * 128;
for (int y = 0; y < 8; y++)
{
byte chr_l = Ptn[lpPtn + y];
byte chr_h = Ptn[lpPtn + y + 8];
m_lpPattern[lpScn + 0] = ToColor32(colors, (((chr_h >> 6) & 2) | ((chr_l >> 7) & 1)));
m_lpPattern[lpScn + 4] = ToColor32(colors, (((chr_h >> 2) & 2) | ((chr_l >> 3) & 1)));
m_lpPattern[lpScn + 1] = ToColor32(colors, (((chr_h >> 5) & 2) | ((chr_l >> 6) & 1)));
m_lpPattern[lpScn + 5] = ToColor32(colors, (((chr_h >> 1) & 2) | ((chr_l >> 2) & 1)));
m_lpPattern[lpScn + 2] = ToColor32(colors, (((chr_h >> 4) & 2) | ((chr_l >> 5) & 1)));
m_lpPattern[lpScn + 6] = ToColor32(colors, (((chr_h >> 0) & 2) | ((chr_l >> 1) & 1)));
m_lpPattern[lpScn + 3] = ToColor32(colors, (((chr_h >> 3) & 2) | ((chr_l >> 4) & 1)));
m_lpPattern[lpScn + 7] = ToColor32(colors, (((chr_h << 1) & 2) | ((chr_l >> 0) & 1)));
// Next line
lpScn += 128;
}
// Next pattern
lpPtn += 16;
}
}
m_texture.SetPixels32(m_lpPattern);
m_texture.Apply();
}
private Color32 ToColor32(Dictionary<byte, RGBQUAD> map, int v)
{
var raw = map[(byte)v];
return new Color32(raw.rgbRed, raw.rgbGreen, raw.rgbBlue, 255);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c7a50c189f5be5b4ea54de444f8488a0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,9 +1,7 @@
using AxibugEmuOnline.Client.Assets.Script.NesEmulator;
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using VirtualNes.Core;
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
{ {

View File

@ -34,6 +34,13 @@ namespace VirtualNes.Core
m_length = length; m_length = length;
} }
public void SetArray(byte[] array, int offset)
{
m_rawArray = array;
m_offset = offset;
m_length = array.Length - offset;
}
public byte this[int index] public byte this[int index]
{ {
get get

View File

@ -78,6 +78,13 @@ namespace VirtualNes
CPU_MEM_PAGE[page] = 0; CPU_MEM_PAGE[page] = 0;
} }
internal static void SetPROM_Bank(byte page, ByteArrayRef ptr, byte type)
{
CPU_MEM_BANK[page] = ptr;
CPU_MEM_TYPE[page] = type;
CPU_MEM_PAGE[page] = 0;
}
internal static void SetPROM_8K_Bank(byte page, int bank) internal static void SetPROM_8K_Bank(byte page, int bank)
{ {
bank %= PROM_8K_SIZE; bank %= PROM_8K_SIZE;

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c57bc13f96a8d064a885b65c6aebc351
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -132,6 +132,7 @@ namespace VirtualNes.Core
} }
} }
private ByteArrayRef _PROM_BANK = new ByteArrayRef();
//void Mapper001::Write(WORD addr, BYTE data) //void Mapper001::Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data) public override void Write(ushort addr, byte data)
{ {
@ -145,11 +146,13 @@ namespace VirtualNes.Core
{ {
if (wram_bank != 0) if (wram_bank != 0)
{ {
SetPROM_Bank(3, &WRAM[0x2000], BANKTYPE_RAM); _PROM_BANK.SetArray(WRAM, 0x2000);
SetPROM_Bank(3, _PROM_BANK, BANKTYPE_RAM);
} }
else else
{ {
SetPROM_Bank(3, &WRAM[0x0000], BANKTYPE_RAM); _PROM_BANK.SetArray(WRAM, 0x0000);
SetPROM_Bank(3, _PROM_BANK, BANKTYPE_RAM);
} }
wram_bank = wram_count = 0; wram_bank = wram_count = 0;
} }
@ -290,11 +293,13 @@ namespace VirtualNes.Core
{ {
if (((reg[1] & 0x18) == 0)) if (((reg[1] & 0x18) == 0))
{ {
SetPROM_Bank(3, &WRAM[0x0000], BANKTYPE_RAM); _PROM_BANK.SetArray(WRAM, 0x0000);
SetPROM_Bank(3, _PROM_BANK, BANKTYPE_RAM);
} }
else else
{ {
SetPROM_Bank(3, &WRAM[0x2000], BANKTYPE_RAM); _PROM_BANK.SetArray(WRAM, 0x2000);
SetPROM_Bank(3, _PROM_BANK, BANKTYPE_RAM);
} }
} }

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c921e7f594a988845856d30f6a925157
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bb072eff593853c41974a6d3b8bc1f93
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -31,7 +31,7 @@ namespace VirtualNes.Core
if (crc == 0x2b72fe7e) if (crc == 0x2b72fe7e)
{ // Ganso Saiyuuki - Super Monkey Dai Bouken(J) { // Ganso Saiyuuki - Super Monkey Dai Bouken(J)
nes.SetRenderMethod( EnumRenderMethod.TILE_RENDER); nes.SetRenderMethod(EnumRenderMethod.TILE_RENDER);
nes.ppu.SetExtNameTableMode(true); nes.ppu.SetExtNameTableMode(true);
} }

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d63147469fd9c5540882a5a89799462b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +1,19 @@
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Mapper005 Nintendo MMC5 // // Mapper005 Nintendo MMC5 //
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
using static VirtualNes.MMU; using System;
using static VirtualNes.Core.CPU; using static VirtualNes.Core.CPU;
using INT = System.Int32; using static VirtualNes.Core.PPU;
using static VirtualNes.MMU;
using BYTE = System.Byte; using BYTE = System.Byte;
using Codice.CM.Client.Differences; using INT = System.Int32;
namespace VirtualNes.Core namespace VirtualNes.Core
{ {
public class Mapper005 : Mapper public class Mapper005 : Mapper
{ {
public const int MMC5_IRQ_METAL = 1 << 0;
BYTE sram_size; BYTE sram_size;
BYTE prg_size; // $5100 BYTE prg_size; // $5100
@ -34,9 +37,19 @@ namespace VirtualNes.Core
BYTE chr_type; BYTE chr_type;
BYTE chr_mode; // $5120-$512B use BYTE chr_mode; // $5120-$512B use
//BYTE chr_page[2][8]; //BYTE chr_page[2][8];
BYTE[,] chr_page = new byte[2,8]; // $5120-$512B BYTE[,] chr_page = new byte[2, 8]; // $5120-$512B
LPBYTE BG_MEM_BANK[8]; // BGパターン用バンク // BGパターン用バンク
BYTE BG_MEM_PAGE[8]; ByteArrayRef[] BG_MEM_BANK = new ByteArrayRef[8]{
new ByteArrayRef(),
new ByteArrayRef(),
new ByteArrayRef(),
new ByteArrayRef(),
new ByteArrayRef(),
new ByteArrayRef(),
new ByteArrayRef(),
new ByteArrayRef(),
};
BYTE[] BG_MEM_PAGE = new byte[8];
BYTE irq_status; // $5204(R) BYTE irq_status; // $5204(R)
BYTE irq_enable; // $5204(W) BYTE irq_enable; // $5204(W)
@ -50,7 +63,7 @@ namespace VirtualNes.Core
public override void Reset() public override void Reset()
{ {
INT i; byte i;
prg_size = 3; prg_size = 3;
chr_size = 3; chr_size = 3;
@ -83,8 +96,8 @@ namespace VirtualNes.Core
chr_mode = 0; chr_mode = 0;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
chr_page[0][i] = i; chr_page[0, i] = i;
chr_page[1][i] = 4 + (i & 0x03); chr_page[1, i] = (byte)(4 + (i & 0x03));
} }
SetPROM_32K_Bank(PROM_8K_SIZE - 1, PROM_8K_SIZE - 1, PROM_8K_SIZE - 1, PROM_8K_SIZE - 1); SetPROM_32K_Bank(PROM_8K_SIZE - 1, PROM_8K_SIZE - 1, PROM_8K_SIZE - 1, PROM_8K_SIZE - 1);
@ -92,7 +105,7 @@ namespace VirtualNes.Core
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
BG_MEM_BANK[i] = VROM + 0x0400 * i; BG_MEM_BANK[i].SetArray(VROM, 0x0400 * i);
BG_MEM_PAGE[i] = i; BG_MEM_PAGE[i] = i;
} }
@ -130,7 +143,7 @@ namespace VirtualNes.Core
if (crc == 0x95ca9ec7) if (crc == 0x95ca9ec7)
{ // Castlevania 3 - Dracula's Curse(U) { // Castlevania 3 - Dracula's Curse(U)
nes.SetRenderMethod(NES::TILE_RENDER); nes.SetRenderMethod(EnumRenderMethod.TILE_RENDER);
} }
if (crc == 0xcd9acf43) if (crc == 0xcd9acf43)
@ -161,15 +174,15 @@ namespace VirtualNes.Core
case 0x5204: case 0x5204:
data = irq_status; data = irq_status;
// irq_status = 0; // irq_status = 0;
irq_status &= ~0x80; irq_status = (byte)(irq_status & ~0x80);
nes.cpu.ClrIRQ(IRQ_MAPPER); nes.cpu.ClrIRQ(IRQ_MAPPER);
break; break;
case 0x5205: case 0x5205:
data = mult_a * mult_b; data = (byte)(mult_a * mult_b);
break; break;
case 0x5206: case 0x5206:
data = (BYTE)(((WORD)mult_a * (WORD)mult_b) >> 8); data = (BYTE)((mult_a * mult_b) >> 8);
break; break;
} }
@ -191,39 +204,33 @@ namespace VirtualNes.Core
//void Mapper005::WriteLow(WORD addr, BYTE data) //void Mapper005::WriteLow(WORD addr, BYTE data)
public override void WriteLow(ushort addr, byte data) public override void WriteLow(ushort addr, byte data)
{ {
INT i; byte i;
#if FALSE//0
if( addr >= 0x5000 && addr <=0x50FF ) {
DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
}
#endif
switch (addr) switch (addr)
{ {
case 0x5100: case 0x5100:
prg_size = data & 0x03; prg_size = (byte)(data & 0x03);
break; break;
case 0x5101: case 0x5101:
chr_size = data & 0x03; chr_size = (byte)(data & 0x03);
break; break;
case 0x5102: case 0x5102:
sram_we_a = data & 0x03; sram_we_a = (byte)(data & 0x03);
break; break;
case 0x5103: case 0x5103:
sram_we_b = data & 0x03; sram_we_b = (byte)(data & 0x03);
break; break;
case 0x5104: case 0x5104:
graphic_mode = data & 0x03; graphic_mode = (byte)(data & 0x03);
break; break;
case 0x5105: case 0x5105:
nametable_mode = data; nametable_mode = data;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
nametable_type[i] = data & 0x03; nametable_type[i] = (byte)(data & 0x03);
SetVRAM_1K_Bank(8 + i, nametable_type[i]); SetVRAM_1K_Bank((byte)(8 + i), nametable_type[i]);
data >>= 2; data >>= 2;
} }
break; break;
@ -232,11 +239,11 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
fill_chr = data; fill_chr = data;
break; break;
case 0x5107: case 0x5107:
fill_pal = data & 0x03; fill_pal = (byte)(data & 0x03);
break; break;
case 0x5113: case 0x5113:
SetBank_SRAM(3, data & 0x07); SetBank_SRAM(3, (byte)(data & 0x07));
break; break;
case 0x5114: case 0x5114:
@ -255,7 +262,7 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
case 0x5126: case 0x5126:
case 0x5127: case 0x5127:
chr_mode = 0; chr_mode = 0;
chr_page[0][addr & 0x07] = data; chr_page[0, addr & 0x07] = data;
SetBank_PPU(); SetBank_PPU();
break; break;
@ -264,8 +271,8 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
case 0x512A: case 0x512A:
case 0x512B: case 0x512B:
chr_mode = 1; chr_mode = 1;
chr_page[1][(addr & 0x03) + 0] = data; chr_page[1, (addr & 0x03) + 0] = data;
chr_page[1][(addr & 0x03) + 4] = data; chr_page[1, (addr & 0x03) + 4] = data;
SetBank_PPU(); SetBank_PPU();
break; break;
@ -276,7 +283,7 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
split_scroll = data; split_scroll = data;
break; break;
case 0x5202: case 0x5202:
split_page = data & 0x3F; split_page = (byte)(data & 0x3F);
break; break;
case 0x5203: case 0x5203:
@ -310,7 +317,7 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
} }
else if (graphic_mode != 3) else if (graphic_mode != 3)
{ // Split,ExGraphic { // Split,ExGraphic
if ((irq_status & 0x40)!=0) if ((irq_status & 0x40) != 0)
{ {
VRAM[0x0800 + (addr & 0x3FF)] = data; VRAM[0x0800 + (addr & 0x3FF)] = data;
} }
@ -351,7 +358,7 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
void SetBank_CPU(uint addr, BYTE data) void SetBank_CPU(uint addr, BYTE data)
{ {
if ((data & 0x80)!=0) if ((data & 0x80) != 0)
{ {
// PROM Bank // PROM Bank
switch (addr & 7) switch (addr & 7)
@ -402,30 +409,31 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
case 4: case 4:
if (prg_size == 3) if (prg_size == 3)
{ {
SetBank_SRAM(4, data & 0x07); SetBank_SRAM(4, (byte)(data & 0x07));
} }
break; break;
case 5: case 5:
if (prg_size == 1 || prg_size == 2) if (prg_size == 1 || prg_size == 2)
{ {
SetBank_SRAM(4, (data & 0x06) + 0); SetBank_SRAM(4, (byte)((data & 0x06) + 0));
SetBank_SRAM(5, (data & 0x06) + 1); SetBank_SRAM(5, (byte)((data & 0x06) + 1));
} }
else if (prg_size == 3) else if (prg_size == 3)
{ {
SetBank_SRAM(5, data & 0x07); SetBank_SRAM(5, (byte)(data & 0x07));
} }
break; break;
case 6: case 6:
if (prg_size == 2 || prg_size == 3) if (prg_size == 2 || prg_size == 3)
{ {
SetBank_SRAM(6, data & 0x07); SetBank_SRAM(6, (byte)(data & 0x07));
} }
break; break;
} }
} }
} }
private ByteArrayRef _prom_bank = new ByteArrayRef();
void SetBank_SRAM(BYTE page, BYTE data) void SetBank_SRAM(BYTE page, BYTE data)
{ {
if (sram_size == 0) data = (byte)((data > 3) ? 8 : 0); if (sram_size == 0) data = (byte)((data > 3) ? 8 : 0);
@ -435,7 +443,9 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
if (data != 8) if (data != 8)
{ {
SetPROM_Bank(page, &WRAM[0x2000 * data], BANKTYPE_RAM); int offset = 0x2000 * data;
_prom_bank.SetArray(WRAM, offset, WRAM.Length - offset);
SetPROM_Bank(page, _prom_bank, BANKTYPE_RAM);
CPU_MEM_PAGE[page] = data; CPU_MEM_PAGE[page] = data;
} }
else else
@ -444,7 +454,7 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
} }
} }
void Mapper005::SetBank_PPU() void SetBank_PPU()
{ {
INT i; INT i;
@ -454,27 +464,27 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
switch (chr_size) switch (chr_size)
{ {
case 0: case 0:
SetVROM_8K_Bank(chr_page[0][7]); SetVROM_8K_Bank(chr_page[0, 7]);
break; break;
case 1: case 1:
SetVROM_4K_Bank(0, chr_page[0][3]); SetVROM_4K_Bank(0, chr_page[0, 3]);
SetVROM_4K_Bank(4, chr_page[0][7]); SetVROM_4K_Bank(4, chr_page[0, 7]);
break; break;
case 2: case 2:
SetVROM_2K_Bank(0, chr_page[0][1]); SetVROM_2K_Bank(0, chr_page[0, 1]);
SetVROM_2K_Bank(2, chr_page[0][3]); SetVROM_2K_Bank(2, chr_page[0, 3]);
SetVROM_2K_Bank(4, chr_page[0][5]); SetVROM_2K_Bank(4, chr_page[0, 5]);
SetVROM_2K_Bank(6, chr_page[0][7]); SetVROM_2K_Bank(6, chr_page[0, 7]);
break; break;
case 3: case 3:
SetVROM_8K_Bank(chr_page[0][0], SetVROM_8K_Bank(chr_page[0, 0],
chr_page[0][1], chr_page[0, 1],
chr_page[0][2], chr_page[0, 2],
chr_page[0][3], chr_page[0, 3],
chr_page[0][4], chr_page[0, 4],
chr_page[0][5], chr_page[0, 5],
chr_page[0][6], chr_page[0, 6],
chr_page[0][7]); chr_page[0, 7]);
break; break;
} }
} }
@ -486,46 +496,46 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
case 0: case 0:
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
BG_MEM_BANK[i] = VROM + 0x2000 * (chr_page[1][7] % VROM_8K_SIZE) + 0x0400 * i; BG_MEM_BANK[i].SetArray(VROM, 0x2000 * (chr_page[1, 7] % VROM_8K_SIZE) + 0x0400 * i);
BG_MEM_PAGE[i] = (chr_page[1][7] % VROM_8K_SIZE) * 8 + i; BG_MEM_PAGE[i] = (byte)((chr_page[1, 7] % VROM_8K_SIZE) * 8 + i);
} }
break; break;
case 1: case 1:
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
BG_MEM_BANK[i + 0] = VROM + 0x1000 * (chr_page[1][3] % VROM_4K_SIZE) + 0x0400 * i; BG_MEM_BANK[i + 0].SetArray(VROM, 0x1000 * (chr_page[1, 3] % VROM_4K_SIZE) + 0x0400 * i);
BG_MEM_BANK[i + 4] = VROM + 0x1000 * (chr_page[1][7] % VROM_4K_SIZE) + 0x0400 * i; BG_MEM_BANK[i + 4].SetArray(VROM, 0x1000 * (chr_page[1, 7] % VROM_4K_SIZE) + 0x0400 * i);
BG_MEM_PAGE[i + 0] = (chr_page[1][3] % VROM_4K_SIZE) * 4 + i; BG_MEM_PAGE[i + 0] = (byte)((chr_page[1, 3] % VROM_4K_SIZE) * 4 + i);
BG_MEM_PAGE[i + 4] = (chr_page[1][7] % VROM_4K_SIZE) * 4 + i; BG_MEM_PAGE[i + 4] = (byte)((chr_page[1, 7] % VROM_4K_SIZE) * 4 + i);
} }
break; break;
case 2: case 2:
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
BG_MEM_BANK[i + 0] = VROM + 0x0800 * (chr_page[1][1] % VROM_2K_SIZE) + 0x0400 * i; BG_MEM_BANK[i + 0].SetArray(VROM, 0x0800 * (chr_page[1, 1] % VROM_2K_SIZE) + 0x0400 * i);
BG_MEM_BANK[i + 2] = VROM + 0x0800 * (chr_page[1][3] % VROM_2K_SIZE) + 0x0400 * i; BG_MEM_BANK[i + 2].SetArray(VROM, 0x0800 * (chr_page[1, 3] % VROM_2K_SIZE) + 0x0400 * i);
BG_MEM_BANK[i + 4] = VROM + 0x0800 * (chr_page[1][5] % VROM_2K_SIZE) + 0x0400 * i; BG_MEM_BANK[i + 4].SetArray(VROM, 0x0800 * (chr_page[1, 5] % VROM_2K_SIZE) + 0x0400 * i);
BG_MEM_BANK[i + 6] = VROM + 0x0800 * (chr_page[1][7] % VROM_2K_SIZE) + 0x0400 * i; BG_MEM_BANK[i + 6].SetArray(VROM, 0x0800 * (chr_page[1, 7] % VROM_2K_SIZE) + 0x0400 * i);
BG_MEM_PAGE[i + 0] = (chr_page[1][1] % VROM_2K_SIZE) * 2 + i; BG_MEM_PAGE[i + 0] = (byte)((chr_page[1, 1] % VROM_2K_SIZE) * 2 + i);
BG_MEM_PAGE[i + 2] = (chr_page[1][3] % VROM_2K_SIZE) * 2 + i; BG_MEM_PAGE[i + 2] = (byte)((chr_page[1, 3] % VROM_2K_SIZE) * 2 + i);
BG_MEM_PAGE[i + 4] = (chr_page[1][5] % VROM_2K_SIZE) * 2 + i; BG_MEM_PAGE[i + 4] = (byte)((chr_page[1, 5] % VROM_2K_SIZE) * 2 + i);
BG_MEM_PAGE[i + 6] = (chr_page[1][7] % VROM_2K_SIZE) * 2 + i; BG_MEM_PAGE[i + 6] = (byte)((chr_page[1, 7] % VROM_2K_SIZE) * 2 + i);
} }
break; break;
case 3: case 3:
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
BG_MEM_BANK[i] = VROM + 0x0400 * (chr_page[1][i] % VROM_1K_SIZE); BG_MEM_BANK[i].SetArray(VROM, 0x0400 * (chr_page[1, i] % VROM_1K_SIZE));
BG_MEM_PAGE[i] = (chr_page[1][i] % VROM_1K_SIZE) + i; BG_MEM_PAGE[i] = (byte)((chr_page[1, i] % VROM_1K_SIZE) + i);
} }
break; break;
} }
} }
} }
void Mapper005::HSync(INT scanline) public override void HSync(int scanline)
{ {
if (irq_type & MMC5_IRQ_METAL) if ((irq_type & MMC5_IRQ_METAL) != 0)
{ {
if (irq_scanline == irq_line) if (irq_scanline == irq_line)
{ {
@ -540,14 +550,14 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
irq_status |= 0x40; irq_status |= 0x40;
irq_clear = 0; irq_clear = 0;
} }
else if (irq_type & MMC5_IRQ_METAL) else if ((irq_type & MMC5_IRQ_METAL) != 0)
{ {
irq_scanline = 0; irq_scanline = 0;
irq_status &= ~0x80; irq_status = (byte)(irq_status & ~0x80);
irq_status &= ~0x40; irq_status = (byte)(irq_status & ~0x40);
} }
if (!(irq_type & MMC5_IRQ_METAL)) if ((irq_type & MMC5_IRQ_METAL) == 0)
{ {
if (irq_scanline == irq_line) if (irq_scanline == irq_line)
{ {
@ -557,28 +567,17 @@ DEBUGOUT( "$%04X=%02X C:%10d\n", addr, data, nes.cpu.GetTotalCycles() );
if (++irq_clear > 2) if (++irq_clear > 2)
{ {
irq_scanline = 0; irq_scanline = 0;
irq_status &= ~0x80; irq_status = (byte)(irq_status & ~0x80);
irq_status &= ~0x40; irq_status = (byte)(irq_status & ~0x40);
nes.cpu.ClrIRQ(IRQ_MAPPER); nes.cpu.ClrIRQ(IRQ_MAPPER);
} }
} }
if ((irq_enable & 0x80) && (irq_status & 0x80) && (irq_status & 0x40)) if ((irq_enable & 0x80) != 0 && (irq_status & 0x80) != 0 && (irq_status & 0x40) != 0)
{ {
nes.cpu.SetIRQ(IRQ_MAPPER); nes.cpu.SetIRQ(IRQ_MAPPER);
/// nes.cpu.IRQ_NotPending(); /// nes.cpu.IRQ_NotPending();
#if 0
{
LPBYTE lpScn = nes.ppu.GetScreenPtr();
lpScn = lpScn+(256+16)*scanline;
for( INT i = 0; i < 256+16; i++ ) {
lpScn[i] = 22;
}
}
#endif
} }
// For Split mode! // For Split mode!
@ -618,7 +617,7 @@ LPBYTE lpScn = nes.ppu.GetScreenPtr();
//void Mapper005::PPU_ExtLatchX(INT x) //void Mapper005::PPU_ExtLatchX(INT x)
public override void PPU_ExtLatchX(int x) public override void PPU_ExtLatchX(int x)
{ {
split_x = x; split_x = (byte)x;
} }
//void Mapper005::PPU_ExtLatch(WORD addr, BYTE& chr_l, BYTE& chr_h, BYTE& attr ) //void Mapper005::PPU_ExtLatch(WORD addr, BYTE& chr_l, BYTE& chr_h, BYTE& attr )
@ -631,15 +630,15 @@ LPBYTE lpScn = nes.ppu.GetScreenPtr();
tile_yofs = nes.ppu.GetTILEY(); tile_yofs = nes.ppu.GetTILEY();
bSplit = FALSE; bSplit = false;
if (split_control & 0x80) if ((split_control & 0x80) != 0)
{ {
if (!(split_control & 0x40)) if ((split_control & 0x40) == 0)
{ {
// Left side // Left side
if ((split_control & 0x1F) > split_x) if ((split_control & 0x1F) > split_x)
{ {
bSplit = TRUE; bSplit = true;
} }
} }
else else
@ -647,7 +646,7 @@ LPBYTE lpScn = nes.ppu.GetScreenPtr();
// Right side // Right side
if ((split_control & 0x1F) <= split_x) if ((split_control & 0x1F) <= split_x)
{ {
bSplit = TRUE; bSplit = true;
} }
} }
} }
@ -660,13 +659,13 @@ LPBYTE lpScn = nes.ppu.GetScreenPtr();
if (graphic_mode == 1) if (graphic_mode == 1)
{ {
// ExGraphic mode // ExGraphic mode
ntbladr = 0x2000 + (addr & 0x0FFF); ntbladr = (ushort)(0x2000 + (addr & 0x0FFF));
// Get Nametable // Get Nametable
tileadr = fill_chr * 0x10 + tile_yofs; tileadr = (ushort)(fill_chr * 0x10 + tile_yofs);
// Get TileBank // Get TileBank
tilebank = 0x1000 * ((VRAM[0x0800 + (ntbladr & 0x03FF)] & 0x3F) % VROM_4K_SIZE); tilebank = (uint)(0x1000 * ((VRAM[0x0800 + (ntbladr & 0x03FF)] & 0x3F) % VROM_4K_SIZE));
// Attribute // Attribute
attr = (fill_pal << 2) & 0x0C; attr = (byte)((fill_pal << 2) & 0x0C);
// Get Pattern // Get Pattern
chr_l = VROM[tilebank + tileadr]; chr_l = VROM[tilebank + tileadr];
chr_h = VROM[tilebank + tileadr + 8]; chr_h = VROM[tilebank + tileadr + 8];
@ -674,11 +673,11 @@ LPBYTE lpScn = nes.ppu.GetScreenPtr();
else else
{ {
// Normal // Normal
tileofs = (PPUREG[0] & PPU_BGTBL_BIT) ? 0x1000 : 0x0000; tileofs = (ushort)((PPUREG[0] & PPU_BGTBL_BIT) != 0 ? 0x1000 : 0x0000);
tileadr = tileofs + fill_chr * 0x10 + tile_yofs; tileadr = (ushort)(tileofs + fill_chr * 0x10 + tile_yofs);
attr = (fill_pal << 2) & 0x0C; attr = (byte)((fill_pal << 2) & 0x0C);
// Get Pattern // Get Pattern
if (chr_type) if (chr_type != 0)
{ {
chr_l = PPU_MEM_BANK[tileadr >> 10][tileadr & 0x03FF]; chr_l = PPU_MEM_BANK[tileadr >> 10][tileadr & 0x03FF];
chr_h = PPU_MEM_BANK[tileadr >> 10][(tileadr & 0x03FF) + 8]; chr_h = PPU_MEM_BANK[tileadr >> 10][(tileadr & 0x03FF) + 8];
@ -693,13 +692,13 @@ LPBYTE lpScn = nes.ppu.GetScreenPtr();
else if (graphic_mode == 1) else if (graphic_mode == 1)
{ {
// ExGraphic mode // ExGraphic mode
ntbladr = 0x2000 + (addr & 0x0FFF); ntbladr = (ushort)(0x2000 + (addr & 0x0FFF));
// Get Nametable // Get Nametable
tileadr = (WORD)PPU_MEM_BANK[ntbladr >> 10][ntbladr & 0x03FF] * 0x10 + tile_yofs; tileadr = (ushort)(PPU_MEM_BANK[ntbladr >> 10][ntbladr & 0x03FF] * 0x10 + tile_yofs);
// Get TileBank // Get TileBank
tilebank = 0x1000 * ((VRAM[0x0800 + (ntbladr & 0x03FF)] & 0x3F) % VROM_4K_SIZE); tilebank = (uint)(0x1000 * ((VRAM[0x0800 + (ntbladr & 0x03FF)] & 0x3F) % VROM_4K_SIZE));
// Get Attribute // Get Attribute
attr = (VRAM[0x0800 + (ntbladr & 0x03FF)] & 0xC0) >> 4; attr = (byte)((VRAM[0x0800 + (ntbladr & 0x03FF)] & 0xC0) >> 4);
// Get Pattern // Get Pattern
chr_l = VROM[tilebank + tileadr]; chr_l = VROM[tilebank + tileadr];
chr_h = VROM[tilebank + tileadr + 8]; chr_h = VROM[tilebank + tileadr + 8];
@ -707,18 +706,18 @@ LPBYTE lpScn = nes.ppu.GetScreenPtr();
else else
{ {
// Normal or ExVRAM // Normal or ExVRAM
tileofs = (PPUREG[0] & PPU_BGTBL_BIT) ? 0x1000 : 0x0000; tileofs = (ushort)((PPUREG[0] & PPU_BGTBL_BIT) != 0 ? 0x1000 : 0x0000);
ntbladr = 0x2000 + (addr & 0x0FFF); ntbladr = (ushort)(0x2000 + (addr & 0x0FFF));
attradr = 0x23C0 + (addr & 0x0C00) + ((addr & 0x0380) >> 4) + ((addr & 0x001C) >> 2); attradr = (ushort)(0x23C0 + (addr & 0x0C00) + ((addr & 0x0380) >> 4) + ((addr & 0x001C) >> 2));
// Get Nametable // Get Nametable
tileadr = tileofs + PPU_MEM_BANK[ntbladr >> 10][ntbladr & 0x03FF] * 0x10 + tile_yofs; tileadr = (ushort)(tileofs + PPU_MEM_BANK[ntbladr >> 10][ntbladr & 0x03FF] * 0x10 + tile_yofs);
// Get Attribute // Get Attribute
attr = PPU_MEM_BANK[attradr >> 10][attradr & 0x03FF]; attr = PPU_MEM_BANK[attradr >> 10][attradr & 0x03FF];
if (ntbladr & 0x0002) attr >>= 2; if ((ntbladr & 0x0002) != 0) attr >>= 2;
if (ntbladr & 0x0040) attr >>= 4; if ((ntbladr & 0x0040) != 0) attr >>= 4;
attr = (attr & 0x03) << 2; attr = (byte)((attr & 0x03) << 2);
// Get Pattern // Get Pattern
if (chr_type) if (chr_type != 0)
{ {
chr_l = PPU_MEM_BANK[tileadr >> 10][tileadr & 0x03FF]; chr_l = PPU_MEM_BANK[tileadr >> 10][tileadr & 0x03FF];
chr_h = PPU_MEM_BANK[tileadr >> 10][(tileadr & 0x03FF) + 8]; chr_h = PPU_MEM_BANK[tileadr >> 10][(tileadr & 0x03FF) + 8];
@ -732,16 +731,16 @@ LPBYTE lpScn = nes.ppu.GetScreenPtr();
} }
else else
{ {
ntbladr = ((split_addr & 0x03E0) | (split_x & 0x1F)) & 0x03FF; ntbladr = (ushort)(((split_addr & 0x03E0) | (split_x & 0x1F)) & 0x03FF);
// Get Split TileBank // Get Split TileBank
tilebank = 0x1000 * ((INT)split_page % VROM_4K_SIZE); tilebank = (uint)(0x1000 * (split_page % VROM_4K_SIZE));
tileadr = (ushort)VRAM[0x0800 + ntbladr] * 0x10 + split_yofs; tileadr = (ushort)(VRAM[0x0800 + ntbladr] * 0x10 + split_yofs);
// Get Attribute // Get Attribute
attradr = 0x03C0 + ((ntbladr & 0x0380) >> 4) + ((ntbladr & 0x001C) >> 2); attradr = (ushort)(0x03C0 + ((ntbladr & 0x0380) >> 4) + ((ntbladr & 0x001C) >> 2));
attr = VRAM[0x0800 + attradr]; attr = VRAM[0x0800 + attradr];
if (ntbladr & 0x0002) attr >>= 2; if ((ntbladr & 0x0002) != 0) attr >>= 2;
if (ntbladr & 0x0040) attr >>= 4; if ((ntbladr & 0x0040) != 0) attr >>= 4;
attr = (attr & 0x03) << 2; attr = (byte)((attr & 0x03) << 2);
// Get Pattern // Get Pattern
chr_l = VROM[tilebank + tileadr]; chr_l = VROM[tilebank + tileadr];
chr_h = VROM[tilebank + tileadr + 8]; chr_h = VROM[tilebank + tileadr + 8];
@ -781,7 +780,7 @@ LPBYTE lpScn = nes.ppu.GetScreenPtr();
{ {
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
p[24 + j * 8 + i] = chr_page[j][i]; p[24 + j * 8 + i] = chr_page[j, i];
} }
} }
// for( i = 0; i < 8; i++ ) { // for( i = 0; i < 8; i++ ) {
@ -823,7 +822,7 @@ LPBYTE lpScn = nes.ppu.GetScreenPtr();
{ {
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
chr_page[j][i] = p[24 + j * 8 + i]; chr_page[j, i] = p[24 + j * 8 + i];
} }
} }
// // BGバンクの再設定処理 // // BGバンクの再設定処理

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26977049b3ea7ad4fa3b5c35a325ae48
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0672fe1374d484f4ab1c824d0882bfdd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 063872d968d91234a9a22755e3db7aab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e39136ad8af00f4c95499cab3a0aa45
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 60942642eeee2e04fbe2fad967c2400d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0beeffcb64a5c124c9ef8d2b428f723e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d46cb68121988e498159e8a53b0cb90
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a0d9dccfbd35bbf458c8f5d100e2f89b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 660200e3200da7d4eb9925d2b63afef5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9a00ec8072aa26648bcd7bef203e9a39
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -22,6 +22,7 @@ namespace VirtualNes.Core
BYTE irq_latch; BYTE irq_latch;
BYTE irq_request; BYTE irq_request;
int MMC4prg, MMC4chr; int MMC4prg, MMC4chr;
public Mapper245(NES parent) : base(parent) public Mapper245(NES parent) : base(parent)
{ {
} }
@ -164,9 +165,9 @@ namespace VirtualNes.Core
void SetBank_PPU() void SetBank_PPU()
{ {
if ((VROM_1K_SIZE) != 0) if (VROM_1K_SIZE != 0)
{ {
if (((reg[0] & 0x80)! + 0) != 0) if ((reg[0] & 0x80) != 0)
{ {
SetVROM_8K_Bank(chr4, chr5, chr6, chr7, SetVROM_8K_Bank(chr4, chr5, chr6, chr7,
chr23 + 1, chr23, chr01 + 1, chr01); chr23 + 1, chr23, chr01 + 1, chr01);

View File

@ -1147,6 +1147,16 @@ namespace VirtualNes.Core
bChrLatch = bMode; bChrLatch = bMode;
} }
internal void SetExtNameTableMode(bool bMode)
{
bExtNameTable = bMode;
}
internal void SetExtMonoMode(bool bMode)
{
bExtMono = bMode;
}
public struct Sprite public struct Sprite
{ {
public byte y public byte y