/Nes/Mappers/Mapper255.cs

http://mynes.codeplex.com · C# · 97 lines · 75 code · 2 blank · 20 comment · 16 complexity · 0792719186d43de072a2b82bd69d1234 MD5 · raw file

  1. /*********************************************************************\
  2. *This file is part of My Nes *
  3. *A Nintendo Entertainment System Emulator. *
  4. * *
  5. *Copyright © Ala Hadid 2009 - 2011 *
  6. *E-mail: mailto:ahdsoftwares@hotmail.com *
  7. * *
  8. *My Nes is free software: you can redistribute it and/or modify *
  9. *it under the terms of the GNU General Public License as published by *
  10. *the Free Software Foundation, either version 3 of the License, or *
  11. *(at your option) any later version. *
  12. * *
  13. *My Nes is distributed in the hope that it will be useful, *
  14. *but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. *GNU General Public License for more details. *
  17. * *
  18. *You should have received a copy of the GNU General Public License *
  19. *along with this program. If not, see <http://www.gnu.org/licenses/>.*
  20. \*********************************************************************/
  21. namespace MyNes.Nes
  22. {
  23. class Mapper255 : Mapper
  24. {
  25. byte Mapper225_reg0 = 0x0F;
  26. byte Mapper225_reg1 = 0x0F;
  27. byte Mapper225_reg2 = 0x0F;
  28. byte Mapper225_reg3 = 0x0F;
  29. public Mapper255(NesSystem nesSystem)
  30. : base(nesSystem) { }
  31. public override void Poke(int address, byte data)
  32. {
  33. if ((address >= 0x8000) && (address <= 0xFFFF))
  34. {
  35. int banks = ((address & 0x4000) != 0) ? 1 : 0;
  36. ushort wher = (ushort)((address & 0x0Fc0) >> 7);
  37. cpuMemory.Switch8kChrRom(((address & 0x003F) + (banks << 6)) * 8);
  38. if ((address & 0x1000) != 0)//A12
  39. {
  40. if ((address & 0x0040) != 0)//A6
  41. {
  42. cpuMemory.Switch16kPrgRom((((wher + (banks << 5)) << 1) + 1) * 4, 0);
  43. cpuMemory.Switch16kPrgRom((((wher + (banks << 5)) << 1) + 1) * 4, 1);
  44. }
  45. else
  46. {
  47. cpuMemory.Switch16kPrgRom(((wher + (banks << 5)) << 1) * 4, 0);
  48. cpuMemory.Switch16kPrgRom(((wher + (banks << 5)) << 1) * 4, 1);
  49. }
  50. }
  51. else
  52. {
  53. cpuMemory.Switch32kPrgRom((wher + (banks << 5)) * 8);//ignore A6
  54. }
  55. cartridge.Mirroring = ((address >> 13) & 1) == 0 ? Mirroring.ModeVert : Mirroring.ModeHorz;
  56. }
  57. else if ((address >= 0x5800) && (address <= 0x5FFF))
  58. {
  59. switch (address & 0x3)
  60. {
  61. case 0: Mapper225_reg0 = (byte)(data & 0xf); break;
  62. case 1: Mapper225_reg1 = (byte)(data & 0xf); break;
  63. case 2: Mapper225_reg2 = (byte)(data & 0xf); break;
  64. case 3: Mapper225_reg3 = (byte)(data & 0xf); break;
  65. }
  66. }
  67. }
  68. protected override void Initialize(bool initializing)
  69. {
  70. cpuMemory.Map(0x4018, 0x7FFF, Peek, Poke);
  71. cpuMemory.Switch32kPrgRom(0);
  72. if (cartridge.HasCharRam)
  73. cpuMemory.FillChr(8);
  74. cpuMemory.Switch8kChrRom(0);
  75. Mapper225_reg0 = 0xF;
  76. Mapper225_reg1 = 0xF;
  77. Mapper225_reg2 = 0xF;
  78. Mapper225_reg3 = 0xF;
  79. }
  80. public override byte Peek(int addr)
  81. {
  82. if ((addr >= 0x5800) && (addr <= 0x5FFF))
  83. {
  84. switch (addr & 0x3)
  85. {
  86. case 0: return Mapper225_reg0;
  87. case 1: return Mapper225_reg1;
  88. case 2: return Mapper225_reg2;
  89. case 3: return Mapper225_reg3;
  90. }
  91. }
  92. return 0xF;
  93. }
  94. }
  95. }