Vram.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <memory>
  17. #include "common/TypeDefine.h"
  18. #include "common/Surface.h"
  19. /**
  20. * Emulates a VRAM block.
  21. *
  22. * The blocks have the same size they had in the Play Station 1 (2048 * 512).
  23. */
  24. class Vram{
  25. public:
  26. /**
  27. * Creates a VRAM block.
  28. *
  29. * @return The VRAM block.
  30. */
  31. static std::unique_ptr<Vram> MakeInstance(){return std::unique_ptr<Vram>(new Vram());}
  32. /**
  33. * Destructor.
  34. */
  35. virtual ~Vram();
  36. /**
  37. * Retrieves the block width.
  38. *
  39. * @return The block width.
  40. */
  41. u16 GetWidth() const;
  42. /**
  43. * Retrieves the block width.
  44. *
  45. * @return The block width.
  46. */
  47. u16 GetHeight() const;
  48. /**
  49. * Saves the contents of the VRAM block to a file.
  50. *
  51. * @param file[in] Path to the file to save.
  52. */
  53. void Save(const Ogre::String& file);
  54. // TODO: Where is this implemented?:
  55. /**
  56. * Adds an image buffer to an existing buffer.
  57. *
  58. * @param x[in] X coordinate for the start of the image buffer.
  59. * @param y[in] Y coordinate for the start of the image buffer.
  60. * @param width[in] Width of the image buffer.
  61. * @param height[in] Height of the image buffer.
  62. * @param buffer[out] The buffer to add the image buffer to.
  63. */
  64. void AddImageBuffer(u16 x, u16 y, u16 width, u16 height, u8* buffer);
  65. /**
  66. * Writes 8 bytes to the VRAM block.
  67. *
  68. * @param x[in] X coordinate of the block where to write.
  69. * @param y[in] Y coordinate of the block where to write.
  70. * @param byte[in] The data to write.
  71. */
  72. void PutU8(u16 x, u16 y, u8 byte);
  73. /**
  74. * Reads 8 bytes from the VRAM block.
  75. *
  76. * @param x[in] X coordinate of the block where to read.
  77. * @param y[in] Y coordinate of the block where to read.
  78. * @return The read bytes.
  79. */
  80. u8 GetU8(u16 x, u16 y) const;
  81. /**
  82. * Writes 16 bytes to the VRAM block.
  83. *
  84. * @param x[in] X coordinate of the block where to write.
  85. * @param y[in] Y coordinate of the block where to write.
  86. * @param byte[in] The data to write.
  87. */
  88. void PutU16(u16 x, u16 y, u16 bytes);
  89. /**
  90. * Reads 16 bytes from the VRAM block.
  91. *
  92. * @param x[in] X coordinate of the block where to read.
  93. * @param y[in] Y coordinate of the block where to read.
  94. * @return The read bytes.
  95. */
  96. u16 GetU16(u16 x, u16 y) const;
  97. private:
  98. /**
  99. * Constructor.
  100. */
  101. Vram();
  102. /**
  103. * The data block
  104. */
  105. u8 vram_[2048 * 512];
  106. /**
  107. * The VRAM block width.
  108. */
  109. u16 width_;
  110. /**
  111. * The VRAM block height.
  112. */
  113. u16 height_;
  114. };