pica.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <initializer_list>
  6. #include <map>
  7. #include "common/bit_field.h"
  8. #include "common/common_types.h"
  9. #include "common/register_set.h"
  10. namespace Pica {
  11. struct Regs {
  12. enum Id : u32 {
  13. ViewportSizeX = 0x41,
  14. ViewportInvSizeX = 0x42,
  15. ViewportSizeY = 0x43,
  16. ViewportInvSizeY = 0x44,
  17. ViewportCorner = 0x68,
  18. DepthBufferFormat = 0x116,
  19. ColorBufferFormat = 0x117,
  20. DepthBufferAddress = 0x11C,
  21. ColorBufferAddress = 0x11D,
  22. ColorBufferSize = 0x11E,
  23. VertexArrayBaseAddr = 0x200,
  24. VertexDescriptor = 0x201, // 0x202
  25. VertexAttributeOffset = 0x203, // 0x206,0x209,0x20C,0x20F,0x212,0x215,0x218,0x21B,0x21E,0x221,0x224
  26. VertexAttributeInfo0 = 0x204, // 0x207,0x20A,0x20D,0x210,0x213,0x216,0x219,0x21C,0x21F,0x222,0x225
  27. VertexAttributeInfo1 = 0x205, // 0x208,0x20B,0x20E,0x211,0x214,0x217,0x21A,0x21D,0x220,0x223,0x226
  28. NumIds = 0x300,
  29. };
  30. template<Id id>
  31. union Struct;
  32. };
  33. static inline Regs::Id VertexAttributeOffset(int n)
  34. {
  35. return static_cast<Regs::Id>(0x203 + 3*n);
  36. }
  37. static inline Regs::Id VertexAttributeInfo0(int n)
  38. {
  39. return static_cast<Regs::Id>(0x204 + 3*n);
  40. }
  41. static inline Regs::Id VertexAttributeInfo1(int n)
  42. {
  43. return static_cast<Regs::Id>(0x205 + 3*n);
  44. }
  45. union CommandHeader {
  46. CommandHeader(u32 h) : hex(h) {}
  47. u32 hex;
  48. BitField< 0, 16, Regs::Id> cmd_id;
  49. BitField<16, 4, u32> parameter_mask;
  50. BitField<20, 11, u32> extra_data_length;
  51. BitField<31, 1, u32> group_commands;
  52. };
  53. static std::map<Regs::Id, const char*> command_names = {
  54. {Regs::ViewportSizeX, "ViewportSizeX" },
  55. {Regs::ViewportInvSizeX, "ViewportInvSizeX" },
  56. {Regs::ViewportSizeY, "ViewportSizeY" },
  57. {Regs::ViewportInvSizeY, "ViewportInvSizeY" },
  58. {Regs::ViewportCorner, "ViewportCorner" },
  59. {Regs::DepthBufferFormat, "DepthBufferFormat" },
  60. {Regs::ColorBufferFormat, "ColorBufferFormat" },
  61. {Regs::DepthBufferAddress, "DepthBufferAddress" },
  62. {Regs::ColorBufferAddress, "ColorBufferAddress" },
  63. {Regs::ColorBufferSize, "ColorBufferSize" },
  64. };
  65. template<>
  66. union Regs::Struct<Regs::ViewportSizeX> {
  67. BitField<0, 24, u32> value;
  68. };
  69. template<>
  70. union Regs::Struct<Regs::ViewportSizeY> {
  71. BitField<0, 24, u32> value;
  72. };
  73. template<>
  74. union Regs::Struct<Regs::VertexDescriptor> {
  75. enum class Format : u64 {
  76. BYTE = 0,
  77. UBYTE = 1,
  78. SHORT = 2,
  79. FLOAT = 3,
  80. };
  81. BitField< 0, 2, Format> format0;
  82. BitField< 2, 2, u64> size0; // number of elements minus 1
  83. BitField< 4, 2, Format> format1;
  84. BitField< 6, 2, u64> size1;
  85. BitField< 8, 2, Format> format2;
  86. BitField<10, 2, u64> size2;
  87. BitField<12, 2, Format> format3;
  88. BitField<14, 2, u64> size3;
  89. BitField<16, 2, Format> format4;
  90. BitField<18, 2, u64> size4;
  91. BitField<20, 2, Format> format5;
  92. BitField<22, 2, u64> size5;
  93. BitField<24, 2, Format> format6;
  94. BitField<26, 2, u64> size6;
  95. BitField<28, 2, Format> format7;
  96. BitField<30, 2, u64> size7;
  97. BitField<32, 2, Format> format8;
  98. BitField<34, 2, u64> size8;
  99. BitField<36, 2, Format> format9;
  100. BitField<38, 2, u64> size9;
  101. BitField<40, 2, Format> format10;
  102. BitField<42, 2, u64> size10;
  103. BitField<44, 2, Format> format11;
  104. BitField<46, 2, u64> size11;
  105. BitField<48, 12, u64> attribute_mask;
  106. BitField<60, 4, u64> num_attributes; // number of total attributes minus 1
  107. };
  108. } // namespace