Vram.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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(){
  32. return std::unique_ptr<Vram>(new Vram());
  33. }
  34. /**
  35. * Destructor.
  36. */
  37. virtual ~Vram();
  38. /**
  39. * Retrieves the block width.
  40. *
  41. * @return The block width.
  42. */
  43. u16 GetWidth() const;
  44. /**
  45. * Retrieves the block width.
  46. *
  47. * @return The block width.
  48. */
  49. u16 GetHeight() const;
  50. /**
  51. * Saves the contents of the VRAM block to a file.
  52. *
  53. * @param file[in] Path to the file to save.
  54. */
  55. void Save(const Ogre::String& file);
  56. // TODO: Where is this implemented?:
  57. /**
  58. * Adds an image buffer to an existing buffer.
  59. *
  60. * @param x[in] X coordinate for the start of the image buffer.
  61. * @param y[in] Y coordinate for the start of the image buffer.
  62. * @param width[in] Width of the image buffer.
  63. * @param height[in] Height of the image buffer.
  64. * @param buffer[out] The buffer to add the image buffer to.
  65. */
  66. void AddImageBuffer(u16 x, u16 y, u16 width, u16 height, u8* buffer);
  67. /**
  68. * Writes 8 bytes to the VRAM block.
  69. *
  70. * @param x[in] X coordinate of the block where to write.
  71. * @param y[in] Y coordinate of the block where to write.
  72. * @param byte[in] The data to write.
  73. */
  74. void PutU8(u16 x, u16 y, u8 byte);
  75. /**
  76. * Reads 8 bytes from the VRAM block.
  77. *
  78. * @param x[in] X coordinate of the block where to read.
  79. * @param y[in] Y coordinate of the block where to read.
  80. * @return The read bytes.
  81. */
  82. u8 GetU8(u16 x, u16 y) const;
  83. /**
  84. * Writes 16 bytes to the VRAM block.
  85. *
  86. * @param x[in] X coordinate of the block where to write.
  87. * @param y[in] Y coordinate of the block where to write.
  88. * @param byte[in] The data to write.
  89. */
  90. void PutU16(u16 x, u16 y, u16 bytes);
  91. /**
  92. * Reads 16 bytes from the VRAM block.
  93. *
  94. * @param x[in] X coordinate of the block where to read.
  95. * @param y[in] Y coordinate of the block where to read.
  96. * @return The read bytes.
  97. */
  98. u16 GetU16(u16 x, u16 y) const;
  99. private:
  100. /**
  101. * Constructor.
  102. */
  103. Vram();
  104. /**
  105. * The data block
  106. */
  107. u8 vram_[2048 * 512];
  108. /**
  109. * The VRAM block width.
  110. */
  111. u16 width_;
  112. /**
  113. * The VRAM block height.
  114. */
  115. u16 height_;
  116. };