NstRam.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. ////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Nestopia - NES/Famicom emulator written in C++
  4. //
  5. // Copyright (C) 2003-2008 Martin Freij
  6. //
  7. // This file is part of Nestopia.
  8. //
  9. // Nestopia is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation; either version 2 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // Nestopia is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with Nestopia; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. //
  23. ////////////////////////////////////////////////////////////////////////////////////////
  24. #ifndef NST_RAM_H
  25. #define NST_RAM_H
  26. #ifdef NST_PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29. #include "NstPins.hpp"
  30. namespace Nes
  31. {
  32. namespace Core
  33. {
  34. class Ram
  35. {
  36. public:
  37. enum Type
  38. {
  39. RAM,
  40. NVRAM,
  41. ROM
  42. };
  43. Ram();
  44. Ram(const Ram&);
  45. Ram(Type,bool,bool,dword,byte* = NULL);
  46. ~Ram();
  47. void Set(dword,byte* = NULL);
  48. void Set(Type,bool,bool,dword,byte* = NULL);
  49. void Destroy();
  50. void Fill(uint) const;
  51. void Mirror(dword);
  52. Ram& operator = (const Ram&);
  53. private:
  54. byte* mem;
  55. dword mask;
  56. dword size;
  57. byte type;
  58. bool readable;
  59. bool writable;
  60. bool internal;
  61. Pins pins;
  62. public:
  63. dword Size() const
  64. {
  65. return size;
  66. }
  67. dword Masking() const
  68. {
  69. return mask;
  70. }
  71. bool Empty() const
  72. {
  73. return size == 0;
  74. }
  75. bool Readable() const
  76. {
  77. return readable;
  78. }
  79. bool Writable() const
  80. {
  81. return writable;
  82. }
  83. bool Internal() const
  84. {
  85. return internal;
  86. }
  87. Type GetType() const
  88. {
  89. return static_cast<Type>(type);
  90. }
  91. void ReadEnable(bool r)
  92. {
  93. readable = r;
  94. }
  95. void WriteEnable(bool w)
  96. {
  97. writable = w;
  98. }
  99. void SetSecurity(bool r,bool w)
  100. {
  101. readable = r;
  102. writable = w;
  103. }
  104. void SetType(Type t)
  105. {
  106. type = t;
  107. }
  108. byte* Mem(dword offset=0) const
  109. {
  110. return mem + (offset & mask);
  111. }
  112. byte& operator [] (dword i) const
  113. {
  114. return mem[i];
  115. }
  116. Pins::PinsProxy Pin(uint i)
  117. {
  118. return pins[i];
  119. }
  120. Pins::ConstPinsProxy Pin(uint i) const
  121. {
  122. return pins[i];
  123. }
  124. bool PinsDefined() const
  125. {
  126. return pins;
  127. }
  128. };
  129. }
  130. }
  131. #endif