BPMemory.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. // Copyright 2009 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <string>
  6. #include "Common/BitField.h"
  7. #include "Common/CommonTypes.h"
  8. #pragma pack(4)
  9. #define BPMEM_GENMODE 0x00
  10. #define BPMEM_DISPLAYCOPYFILTER 0x01 // 0x01 + 4
  11. #define BPMEM_IND_MTXA 0x06 // 0x06 + (3 * 3)
  12. #define BPMEM_IND_MTXB 0x07 // 0x07 + (3 * 3)
  13. #define BPMEM_IND_MTXC 0x08 // 0x08 + (3 * 3)
  14. #define BPMEM_IND_IMASK 0x0F
  15. #define BPMEM_IND_CMD 0x10 // 0x10 + 16
  16. #define BPMEM_SCISSORTL 0x20
  17. #define BPMEM_SCISSORBR 0x21
  18. #define BPMEM_LINEPTWIDTH 0x22
  19. #define BPMEM_PERF0_TRI 0x23
  20. #define BPMEM_PERF0_QUAD 0x24
  21. #define BPMEM_RAS1_SS0 0x25
  22. #define BPMEM_RAS1_SS1 0x26
  23. #define BPMEM_IREF 0x27
  24. #define BPMEM_TREF 0x28 // 0x28 + 8
  25. #define BPMEM_SU_SSIZE 0x30 // 0x30 + (2 * 8)
  26. #define BPMEM_SU_TSIZE 0x31 // 0x31 + (2 * 8)
  27. #define BPMEM_ZMODE 0x40
  28. #define BPMEM_BLENDMODE 0x41
  29. #define BPMEM_CONSTANTALPHA 0x42
  30. #define BPMEM_ZCOMPARE 0x43
  31. #define BPMEM_FIELDMASK 0x44
  32. #define BPMEM_SETDRAWDONE 0x45
  33. #define BPMEM_BUSCLOCK0 0x46
  34. #define BPMEM_PE_TOKEN_ID 0x47
  35. #define BPMEM_PE_TOKEN_INT_ID 0x48
  36. #define BPMEM_EFB_TL 0x49
  37. #define BPMEM_EFB_BR 0x4A
  38. #define BPMEM_EFB_ADDR 0x4B
  39. #define BPMEM_MIPMAP_STRIDE 0x4D
  40. #define BPMEM_COPYYSCALE 0x4E
  41. #define BPMEM_CLEAR_AR 0x4F
  42. #define BPMEM_CLEAR_GB 0x50
  43. #define BPMEM_CLEAR_Z 0x51
  44. #define BPMEM_TRIGGER_EFB_COPY 0x52
  45. #define BPMEM_COPYFILTER0 0x53
  46. #define BPMEM_COPYFILTER1 0x54
  47. #define BPMEM_CLEARBBOX1 0x55
  48. #define BPMEM_CLEARBBOX2 0x56
  49. #define BPMEM_CLEAR_PIXEL_PERF 0x57
  50. #define BPMEM_REVBITS 0x58
  51. #define BPMEM_SCISSOROFFSET 0x59
  52. #define BPMEM_PRELOAD_ADDR 0x60
  53. #define BPMEM_PRELOAD_TMEMEVEN 0x61
  54. #define BPMEM_PRELOAD_TMEMODD 0x62
  55. #define BPMEM_PRELOAD_MODE 0x63
  56. #define BPMEM_LOADTLUT0 0x64
  57. #define BPMEM_LOADTLUT1 0x65
  58. #define BPMEM_TEXINVALIDATE 0x66
  59. #define BPMEM_PERF1 0x67
  60. #define BPMEM_FIELDMODE 0x68
  61. #define BPMEM_BUSCLOCK1 0x69
  62. #define BPMEM_TX_SETMODE0 0x80 // 0x80 + 4
  63. #define BPMEM_TX_SETMODE1 0x84 // 0x84 + 4
  64. #define BPMEM_TX_SETIMAGE0 0x88 // 0x88 + 4
  65. #define BPMEM_TX_SETIMAGE1 0x8C // 0x8C + 4
  66. #define BPMEM_TX_SETIMAGE2 0x90 // 0x90 + 4
  67. #define BPMEM_TX_SETIMAGE3 0x94 // 0x94 + 4
  68. #define BPMEM_TX_SETTLUT 0x98 // 0x98 + 4
  69. #define BPMEM_TX_SETMODE0_4 0xA0 // 0xA0 + 4
  70. #define BPMEM_TX_SETMODE1_4 0xA4 // 0xA4 + 4
  71. #define BPMEM_TX_SETIMAGE0_4 0xA8 // 0xA8 + 4
  72. #define BPMEM_TX_SETIMAGE1_4 0xAC // 0xA4 + 4
  73. #define BPMEM_TX_SETIMAGE2_4 0xB0 // 0xB0 + 4
  74. #define BPMEM_TX_SETIMAGE3_4 0xB4 // 0xB4 + 4
  75. #define BPMEM_TX_SETTLUT_4 0xB8 // 0xB8 + 4
  76. #define BPMEM_TEV_COLOR_ENV 0xC0 // 0xC0 + (2 * 16)
  77. #define BPMEM_TEV_ALPHA_ENV 0xC1 // 0xC1 + (2 * 16)
  78. #define BPMEM_TEV_COLOR_RA 0xE0 // 0xE0 + (2 * 4)
  79. #define BPMEM_TEV_COLOR_BG 0xE1 // 0xE1 + (2 * 4)
  80. #define BPMEM_FOGRANGE 0xE8 // 0xE8 + 6
  81. #define BPMEM_FOGPARAM0 0xEE
  82. #define BPMEM_FOGBMAGNITUDE 0xEF
  83. #define BPMEM_FOGBEXPONENT 0xF0
  84. #define BPMEM_FOGPARAM3 0xF1
  85. #define BPMEM_FOGCOLOR 0xF2
  86. #define BPMEM_ALPHACOMPARE 0xF3
  87. #define BPMEM_BIAS 0xF4
  88. #define BPMEM_ZTEX2 0xF5
  89. #define BPMEM_TEV_KSEL 0xF6 // 0xF6 + 8
  90. #define BPMEM_BP_MASK 0xFE
  91. // Tev/combiner things
  92. #define TEVSCALE_1 0
  93. #define TEVSCALE_2 1
  94. #define TEVSCALE_4 2
  95. #define TEVDIVIDE_2 3
  96. #define TEVCMP_R8 0
  97. #define TEVCMP_GR16 1
  98. #define TEVCMP_BGR24 2
  99. #define TEVCMP_RGB8 3
  100. #define TEVOP_ADD 0
  101. #define TEVOP_SUB 1
  102. #define TEVCMP_R8_GT 8
  103. #define TEVCMP_R8_EQ 9
  104. #define TEVCMP_GR16_GT 10
  105. #define TEVCMP_GR16_EQ 11
  106. #define TEVCMP_BGR24_GT 12
  107. #define TEVCMP_BGR24_EQ 13
  108. #define TEVCMP_RGB8_GT 14
  109. #define TEVCMP_RGB8_EQ 15
  110. #define TEVCMP_A8_GT 14
  111. #define TEVCMP_A8_EQ 15
  112. #define TEVCOLORARG_CPREV 0
  113. #define TEVCOLORARG_APREV 1
  114. #define TEVCOLORARG_C0 2
  115. #define TEVCOLORARG_A0 3
  116. #define TEVCOLORARG_C1 4
  117. #define TEVCOLORARG_A1 5
  118. #define TEVCOLORARG_C2 6
  119. #define TEVCOLORARG_A2 7
  120. #define TEVCOLORARG_TEXC 8
  121. #define TEVCOLORARG_TEXA 9
  122. #define TEVCOLORARG_RASC 10
  123. #define TEVCOLORARG_RASA 11
  124. #define TEVCOLORARG_ONE 12
  125. #define TEVCOLORARG_HALF 13
  126. #define TEVCOLORARG_KONST 14
  127. #define TEVCOLORARG_ZERO 15
  128. #define TEVALPHAARG_APREV 0
  129. #define TEVALPHAARG_A0 1
  130. #define TEVALPHAARG_A1 2
  131. #define TEVALPHAARG_A2 3
  132. #define TEVALPHAARG_TEXA 4
  133. #define TEVALPHAARG_RASA 5
  134. #define TEVALPHAARG_KONST 6
  135. #define TEVALPHAARG_ZERO 7
  136. #define GX_TEVPREV 0
  137. #define GX_TEVREG0 1
  138. #define GX_TEVREG1 2
  139. #define GX_TEVREG2 3
  140. #define ZTEXTURE_DISABLE 0
  141. #define ZTEXTURE_ADD 1
  142. #define ZTEXTURE_REPLACE 2
  143. #define TevBias_ZERO 0
  144. #define TevBias_ADDHALF 1
  145. #define TevBias_SUBHALF 2
  146. #define TevBias_COMPARE 3
  147. union IND_MTXA
  148. {
  149. struct
  150. {
  151. s32 ma : 11;
  152. s32 mb : 11;
  153. u32 s0 : 2; // bits 0-1 of scale factor
  154. u32 rid : 8;
  155. };
  156. u32 hex;
  157. };
  158. union IND_MTXB
  159. {
  160. struct
  161. {
  162. s32 mc : 11;
  163. s32 md : 11;
  164. u32 s1 : 2; // bits 2-3 of scale factor
  165. u32 rid : 8;
  166. };
  167. u32 hex;
  168. };
  169. union IND_MTXC
  170. {
  171. struct
  172. {
  173. s32 me : 11;
  174. s32 mf : 11;
  175. u32 s2 : 2; // bits 4-5 of scale factor
  176. u32 rid : 8;
  177. };
  178. u32 hex;
  179. };
  180. struct IND_MTX
  181. {
  182. IND_MTXA col0;
  183. IND_MTXB col1;
  184. IND_MTXC col2;
  185. };
  186. union IND_IMASK
  187. {
  188. struct
  189. {
  190. u32 mask : 24;
  191. u32 rid : 8;
  192. };
  193. u32 hex;
  194. };
  195. #define TEVSELCC_CPREV 0
  196. #define TEVSELCC_APREV 1
  197. #define TEVSELCC_C0 2
  198. #define TEVSELCC_A0 3
  199. #define TEVSELCC_C1 4
  200. #define TEVSELCC_A1 5
  201. #define TEVSELCC_C2 6
  202. #define TEVSELCC_A2 7
  203. #define TEVSELCC_TEXC 8
  204. #define TEVSELCC_TEXA 9
  205. #define TEVSELCC_RASC 10
  206. #define TEVSELCC_RASA 11
  207. #define TEVSELCC_ONE 12
  208. #define TEVSELCC_HALF 13
  209. #define TEVSELCC_KONST 14
  210. #define TEVSELCC_ZERO 15
  211. #define TEVSELCA_APREV 0
  212. #define TEVSELCA_A0 1
  213. #define TEVSELCA_A1 2
  214. #define TEVSELCA_A2 3
  215. #define TEVSELCA_TEXA 4
  216. #define TEVSELCA_RASA 5
  217. #define TEVSELCA_KONST 6
  218. #define TEVSELCA_ZERO 7
  219. struct TevStageCombiner
  220. {
  221. union ColorCombiner
  222. {
  223. struct //abc=8bit,d=10bit
  224. {
  225. u32 d : 4; // TEVSELCC_X
  226. u32 c : 4; // TEVSELCC_X
  227. u32 b : 4; // TEVSELCC_X
  228. u32 a : 4; // TEVSELCC_X
  229. u32 bias : 2;
  230. u32 op : 1;
  231. u32 clamp : 1;
  232. u32 shift : 2;
  233. u32 dest : 2; //1,2,3
  234. };
  235. u32 hex;
  236. };
  237. union AlphaCombiner
  238. {
  239. struct
  240. {
  241. u32 rswap : 2;
  242. u32 tswap : 2;
  243. u32 d : 3; // TEVSELCA_
  244. u32 c : 3; // TEVSELCA_
  245. u32 b : 3; // TEVSELCA_
  246. u32 a : 3; // TEVSELCA_
  247. u32 bias : 2; //GXTevBias
  248. u32 op : 1;
  249. u32 clamp : 1;
  250. u32 shift : 2;
  251. u32 dest : 2; //1,2,3
  252. };
  253. u32 hex;
  254. };
  255. ColorCombiner colorC;
  256. AlphaCombiner alphaC;
  257. };
  258. #define ITF_8 0
  259. #define ITF_5 1
  260. #define ITF_4 2
  261. #define ITF_3 3
  262. #define ITB_NONE 0
  263. #define ITB_S 1
  264. #define ITB_T 2
  265. #define ITB_ST 3
  266. #define ITB_U 4
  267. #define ITB_SU 5
  268. #define ITB_TU 6
  269. #define ITB_STU 7
  270. #define ITBA_OFF 0
  271. #define ITBA_S 1
  272. #define ITBA_T 2
  273. #define ITBA_U 3
  274. #define ITW_OFF 0
  275. #define ITW_256 1
  276. #define ITW_128 2
  277. #define ITW_64 3
  278. #define ITW_32 4
  279. #define ITW_16 5
  280. #define ITW_0 6
  281. // several discoveries:
  282. // GXSetTevIndBumpST(tevstage, indstage, matrixind)
  283. // if ( matrix == 2 ) realmat = 6; // 10
  284. // else if ( matrix == 3 ) realmat = 7; // 11
  285. // else if ( matrix == 1 ) realmat = 5; // 9
  286. // GXSetTevIndirect(tevstage, indstage, 0, 3, realmat, 6, 6, 0, 0, 0)
  287. // GXSetTevIndirect(tevstage+1, indstage, 0, 3, realmat+4, 6, 6, 1, 0, 0)
  288. // GXSetTevIndirect(tevstage+2, indstage, 0, 0, 0, 0, 0, 1, 0, 0)
  289. union TevStageIndirect
  290. {
  291. struct
  292. {
  293. u32 bt : 2; // Indirect tex stage ID
  294. u32 fmt : 2; // Format: ITF_X
  295. u32 bias : 3; // ITB_X
  296. u32 bs : 2; // ITBA_X, indicates which coordinate will become the 'bump alpha'
  297. u32 mid : 4; // Matrix ID to multiply offsets with
  298. u32 sw : 3; // ITW_X, wrapping factor for S of regular coord
  299. u32 tw : 3; // ITW_X, wrapping factor for T of regular coord
  300. u32 lb_utclod : 1; // Use modified or unmodified texture coordinates for LOD computation
  301. u32 fb_addprev : 1; // 1 if the texture coordinate results from the previous TEV stage should be added
  302. u32 pad0 : 3;
  303. u32 rid : 8;
  304. };
  305. struct
  306. {
  307. u32 hex : 21;
  308. u32 unused : 11;
  309. };
  310. // If bs and mid are zero, the result of the stage is independent of
  311. // the texture sample data, so we can skip sampling the texture.
  312. bool IsActive() { return bs != ITBA_OFF || mid != 0; }
  313. };
  314. union TwoTevStageOrders
  315. {
  316. struct
  317. {
  318. u32 texmap0 : 3; // Indirect tex stage texmap
  319. u32 texcoord0 : 3;
  320. u32 enable0 : 1; // 1 if should read from texture
  321. u32 colorchan0 : 3; // RAS1_CC_X
  322. u32 pad0 : 2;
  323. u32 texmap1 : 3;
  324. u32 texcoord1 : 3;
  325. u32 enable1 : 1; // 1 if should read from texture
  326. u32 colorchan1 : 3; // RAS1_CC_X
  327. u32 pad1 : 2;
  328. u32 rid : 8;
  329. };
  330. u32 hex;
  331. int getTexMap(int i){return i?texmap1:texmap0;}
  332. int getTexCoord(int i){return i?texcoord1:texcoord0;}
  333. int getEnable(int i){return i?enable1:enable0;}
  334. int getColorChan(int i){return i?colorchan1:colorchan0;}
  335. };
  336. union TEXSCALE
  337. {
  338. struct
  339. {
  340. u32 ss0 : 4; // Indirect tex stage 0, 2^(-ss0)
  341. u32 ts0 : 4; // Indirect tex stage 0
  342. u32 ss1 : 4; // Indirect tex stage 1
  343. u32 ts1 : 4; // Indirect tex stage 1
  344. u32 pad : 8;
  345. u32 rid : 8;
  346. };
  347. u32 hex;
  348. };
  349. union RAS1_IREF
  350. {
  351. struct
  352. {
  353. u32 bi0 : 3; // Indirect tex stage 0 ntexmap
  354. u32 bc0 : 3; // Indirect tex stage 0 ntexcoord
  355. u32 bi1 : 3;
  356. u32 bc1 : 3;
  357. u32 bi2 : 3;
  358. u32 bc3 : 3;
  359. u32 bi4 : 3;
  360. u32 bc4 : 3;
  361. u32 rid : 8;
  362. };
  363. u32 hex;
  364. u32 getTexCoord(int i) { return (hex>>(6*i+3))&7; }
  365. u32 getTexMap(int i) { return (hex>>(6*i))&7; }
  366. };
  367. // Texture structs
  368. union TexMode0
  369. {
  370. enum TextureFilter : u32
  371. {
  372. TEXF_NONE = 0,
  373. TEXF_POINT = 1,
  374. TEXF_LINEAR = 2
  375. };
  376. struct
  377. {
  378. u32 wrap_s : 2;
  379. u32 wrap_t : 2;
  380. u32 mag_filter : 1;
  381. u32 min_filter : 3;
  382. u32 diag_lod : 1;
  383. s32 lod_bias : 8;
  384. u32 pad0 : 2;
  385. u32 max_aniso : 2;
  386. u32 lod_clamp : 1;
  387. };
  388. u32 hex;
  389. };
  390. union TexMode1
  391. {
  392. struct
  393. {
  394. u32 min_lod : 8;
  395. u32 max_lod : 8;
  396. };
  397. u32 hex;
  398. };
  399. union TexImage0
  400. {
  401. struct
  402. {
  403. u32 width : 10; // Actually w-1
  404. u32 height : 10; // Actually h-1
  405. u32 format : 4;
  406. };
  407. u32 hex;
  408. };
  409. union TexImage1
  410. {
  411. struct
  412. {
  413. u32 tmem_even : 15; // TMEM line index for even LODs
  414. u32 cache_width : 3;
  415. u32 cache_height : 3;
  416. u32 image_type : 1; // 1 if this texture is managed manually (0 means we'll autofetch the texture data whenever it changes)
  417. };
  418. u32 hex;
  419. };
  420. union TexImage2
  421. {
  422. struct
  423. {
  424. u32 tmem_odd : 15; // tmem line index for odd LODs
  425. u32 cache_width : 3;
  426. u32 cache_height : 3;
  427. };
  428. u32 hex;
  429. };
  430. union TexImage3
  431. {
  432. struct
  433. {
  434. u32 image_base: 24; //address in memory >> 5 (was 20 for GC)
  435. };
  436. u32 hex;
  437. };
  438. union TexTLUT
  439. {
  440. struct
  441. {
  442. u32 tmem_offset : 10;
  443. u32 tlut_format : 2;
  444. };
  445. u32 hex;
  446. };
  447. union ZTex1
  448. {
  449. struct
  450. {
  451. u32 bias : 24;
  452. };
  453. u32 hex;
  454. };
  455. union ZTex2
  456. {
  457. struct
  458. {
  459. u32 type : 2; // TEV_Z_TYPE_X
  460. u32 op : 2; // GXZTexOp
  461. };
  462. u32 hex;
  463. };
  464. // Z-texture types (formats)
  465. #define TEV_ZTEX_TYPE_U8 0
  466. #define TEV_ZTEX_TYPE_U16 1
  467. #define TEV_ZTEX_TYPE_U24 2
  468. #define TEV_ZTEX_DISABLE 0
  469. #define TEV_ZTEX_ADD 1
  470. #define TEV_ZTEX_REPLACE 2
  471. struct FourTexUnits
  472. {
  473. TexMode0 texMode0[4];
  474. TexMode1 texMode1[4];
  475. TexImage0 texImage0[4];
  476. TexImage1 texImage1[4];
  477. TexImage2 texImage2[4];
  478. TexImage3 texImage3[4];
  479. TexTLUT texTlut[4];
  480. u32 unknown[4];
  481. };
  482. // Geometry/other structs
  483. union GenMode
  484. {
  485. enum CullMode : u32
  486. {
  487. CULL_NONE = 0,
  488. CULL_BACK = 1, // cull back-facing primitives
  489. CULL_FRONT = 2, // cull front-facing primitives
  490. CULL_ALL = 3, // cull all primitives
  491. };
  492. BitField< 0,4,u32> numtexgens;
  493. BitField< 4,3,u32> numcolchans;
  494. // 1 bit unused?
  495. BitField< 8,1,u32> flat_shading; // unconfirmed
  496. BitField< 9,1,u32> multisampling;
  497. BitField<10,4,u32> numtevstages;
  498. BitField<14,2,CullMode> cullmode;
  499. BitField<16,3,u32> numindstages;
  500. BitField<19,1,u32> zfreeze;
  501. u32 hex;
  502. };
  503. union LPSize
  504. {
  505. struct
  506. {
  507. u32 linesize : 8; // in 1/6th pixels
  508. u32 pointsize : 8; // in 1/6th pixels
  509. u32 lineoff : 3;
  510. u32 pointoff : 3;
  511. u32 lineaspect : 1; // interlacing: adjust for pixels having AR of 1/2
  512. u32 padding : 1;
  513. };
  514. u32 hex;
  515. };
  516. union X12Y12
  517. {
  518. struct
  519. {
  520. u32 y : 12;
  521. u32 x : 12;
  522. };
  523. u32 hex;
  524. };
  525. union X10Y10
  526. {
  527. struct
  528. {
  529. u32 x : 10;
  530. u32 y : 10;
  531. };
  532. u32 hex;
  533. };
  534. // Framebuffer/pixel stuff (incl fog)
  535. union BlendMode
  536. {
  537. enum BlendFactor : u32
  538. {
  539. ZERO = 0,
  540. ONE = 1,
  541. SRCCLR = 2, // for dst factor
  542. INVSRCCLR = 3, // for dst factor
  543. DSTCLR = SRCCLR, // for src factor
  544. INVDSTCLR = INVSRCCLR, // for src factor
  545. SRCALPHA = 4,
  546. INVSRCALPHA = 5,
  547. DSTALPHA = 6,
  548. INVDSTALPHA = 7
  549. };
  550. enum LogicOp : u32
  551. {
  552. CLEAR = 0,
  553. AND = 1,
  554. AND_REVERSE = 2,
  555. COPY = 3,
  556. AND_INVERTED = 4,
  557. NOOP = 5,
  558. XOR = 6,
  559. OR = 7,
  560. NOR = 8,
  561. EQUIV = 9,
  562. INVERT = 10,
  563. OR_REVERSE = 11,
  564. COPY_INVERTED = 12,
  565. OR_INVERTED = 13,
  566. NAND = 14,
  567. SET = 15
  568. };
  569. BitField< 0,1,u32> blendenable;
  570. BitField< 1,1,u32> logicopenable;
  571. BitField< 2,1,u32> dither;
  572. BitField< 3,1,u32> colorupdate;
  573. BitField< 4,1,u32> alphaupdate;
  574. BitField< 5,3,BlendFactor> dstfactor;
  575. BitField< 8,3,BlendFactor> srcfactor;
  576. BitField<11,1,u32> subtract;
  577. BitField<12,4,LogicOp> logicmode;
  578. u32 hex;
  579. };
  580. union FogParam0
  581. {
  582. struct
  583. {
  584. u32 mantissa : 11;
  585. u32 exponent : 8;
  586. u32 sign : 1;
  587. };
  588. float GetA()
  589. {
  590. union { u32 i; float f; } dummy;
  591. dummy.i = ((u32)sign << 31) | ((u32)exponent << 23) | ((u32)mantissa << 12); // scale mantissa from 11 to 23 bits
  592. return dummy.f;
  593. }
  594. u32 hex;
  595. };
  596. union FogParam3
  597. {
  598. struct
  599. {
  600. u32 c_mant : 11;
  601. u32 c_exp : 8;
  602. u32 c_sign : 1;
  603. u32 proj : 1; // 0 - perspective, 1 - orthographic
  604. u32 fsel : 3; // 0 - off, 2 - linear, 4 - exp, 5 - exp2, 6 - backward exp, 7 - backward exp2
  605. };
  606. // amount to subtract from eyespacez after range adjustment
  607. float GetC()
  608. {
  609. union { u32 i; float f; } dummy;
  610. dummy.i = ((u32)c_sign << 31) | ((u32)c_exp << 23) | ((u32)c_mant << 12); // scale mantissa from 11 to 23 bits
  611. return dummy.f;
  612. }
  613. u32 hex;
  614. };
  615. union FogRangeKElement
  616. {
  617. struct
  618. {
  619. u32 HI : 12;
  620. u32 LO : 12;
  621. u32 regid : 8;
  622. };
  623. // TODO: Which scaling coefficient should we use here? This is just a guess!
  624. float GetValue(int i) { return (i ? HI : LO) / 256.f; }
  625. u32 HEX;
  626. };
  627. struct FogRangeParams
  628. {
  629. union RangeBase
  630. {
  631. struct
  632. {
  633. u32 Center : 10; // viewport center + 342
  634. u32 Enabled : 1;
  635. u32 unused : 13;
  636. u32 regid : 8;
  637. };
  638. u32 hex;
  639. };
  640. RangeBase Base;
  641. FogRangeKElement K[5];
  642. };
  643. // final eq: ze = A/(B_MAG - (Zs>>B_SHF));
  644. struct FogParams
  645. {
  646. FogParam0 a;
  647. u32 b_magnitude;
  648. u32 b_shift; // b's exp + 1?
  649. FogParam3 c_proj_fsel;
  650. union FogColor
  651. {
  652. struct
  653. {
  654. u32 b : 8;
  655. u32 g : 8;
  656. u32 r : 8;
  657. };
  658. u32 hex;
  659. };
  660. FogColor color; //0:b 8:g 16:r - nice!
  661. };
  662. union ZMode
  663. {
  664. enum CompareMode : u32
  665. {
  666. NEVER = 0,
  667. LESS = 1,
  668. EQUAL = 2,
  669. LEQUAL = 3,
  670. GREATER = 4,
  671. NEQUAL = 5,
  672. GEQUAL = 6,
  673. ALWAYS = 7
  674. };
  675. BitField<0,1,u32> testenable;
  676. BitField<1,3,CompareMode> func;
  677. BitField<4,1,u32> updateenable;
  678. u32 hex;
  679. };
  680. union ConstantAlpha
  681. {
  682. struct
  683. {
  684. u32 alpha : 8;
  685. u32 enable : 1;
  686. };
  687. u32 hex;
  688. };
  689. union FieldMode
  690. {
  691. struct
  692. {
  693. u32 texLOD : 1; // adjust vert tex LOD computation to account for interlacing
  694. };
  695. u32 hex;
  696. };
  697. union FieldMask
  698. {
  699. struct
  700. {
  701. // If bit is not set, do not write field to EFB
  702. u32 odd : 1;
  703. u32 even : 1;
  704. };
  705. u32 hex;
  706. };
  707. union PEControl
  708. {
  709. enum PixelFormat : u32
  710. {
  711. RGB8_Z24 = 0,
  712. RGBA6_Z24 = 1,
  713. RGB565_Z16 = 2,
  714. Z24 = 3,
  715. Y8 = 4,
  716. U8 = 5,
  717. V8 = 6,
  718. YUV420 = 7,
  719. INVALID_FMT = 0xffffffff, // Used by Dolphin to represent a missing value.
  720. };
  721. enum DepthFormat : u32
  722. {
  723. ZLINEAR = 0,
  724. ZNEAR = 1,
  725. ZMID = 2,
  726. ZFAR = 3,
  727. // It seems these Z formats aren't supported/were removed ?
  728. ZINV_LINEAR = 4,
  729. ZINV_NEAR = 5,
  730. ZINV_MID = 6,
  731. ZINV_FAR = 7
  732. };
  733. BitField< 0,3,PixelFormat> pixel_format;
  734. BitField< 3,3,DepthFormat> zformat;
  735. BitField< 6,1,u32> early_ztest;
  736. u32 hex;
  737. };
  738. // Texture coordinate stuff
  739. union TCInfo
  740. {
  741. struct
  742. {
  743. u32 scale_minus_1 : 16;
  744. u32 range_bias : 1;
  745. u32 cylindric_wrap : 1;
  746. // These bits only have effect in the s field of TCoordInfo
  747. u32 line_offset : 1;
  748. u32 point_offset : 1;
  749. };
  750. u32 hex;
  751. };
  752. struct TCoordInfo
  753. {
  754. TCInfo s;
  755. TCInfo t;
  756. };
  757. union TevReg
  758. {
  759. u64 hex;
  760. // Access to individual registers
  761. BitField< 0, 32,u64> low;
  762. BitField<32, 32,u64> high;
  763. // TODO: Check if Konst uses all 11 bits or just 8
  764. // Low register
  765. BitField< 0,11,s64> red;
  766. BitField<12,11,s64> alpha;
  767. BitField<23, 1,u64> type_ra;
  768. // High register
  769. BitField<32,11,s64> blue;
  770. BitField<44,11,s64> green;
  771. BitField<55, 1,u64> type_bg;
  772. };
  773. union TevKSel
  774. {
  775. struct {
  776. u32 swap1 : 2;
  777. u32 swap2 : 2;
  778. u32 kcsel0 : 5;
  779. u32 kasel0 : 5;
  780. u32 kcsel1 : 5;
  781. u32 kasel1 : 5;
  782. };
  783. u32 hex;
  784. int getKC(int i) {return i?kcsel1:kcsel0;}
  785. int getKA(int i) {return i?kasel1:kasel0;}
  786. };
  787. union AlphaTest
  788. {
  789. enum CompareMode : u32
  790. {
  791. NEVER = 0,
  792. LESS = 1,
  793. EQUAL = 2,
  794. LEQUAL = 3,
  795. GREATER = 4,
  796. NEQUAL = 5,
  797. GEQUAL = 6,
  798. ALWAYS = 7
  799. };
  800. enum Op : u32
  801. {
  802. AND = 0,
  803. OR = 1,
  804. XOR = 2,
  805. XNOR = 3
  806. };
  807. BitField< 0,8, u32> ref0;
  808. BitField< 8,8, u32> ref1;
  809. BitField<16,3, CompareMode> comp0;
  810. BitField<19,3, CompareMode> comp1;
  811. BitField<22,2, Op> logic;
  812. u32 hex;
  813. enum TEST_RESULT
  814. {
  815. UNDETERMINED = 0,
  816. FAIL = 1,
  817. PASS = 2,
  818. };
  819. __forceinline TEST_RESULT TestResult() const
  820. {
  821. switch (logic)
  822. {
  823. case AND:
  824. if (comp0 == ALWAYS && comp1 == ALWAYS)
  825. return PASS;
  826. if (comp0 == NEVER || comp1 == NEVER)
  827. return FAIL;
  828. break;
  829. case OR:
  830. if (comp0 == ALWAYS || comp1 == ALWAYS)
  831. return PASS;
  832. if (comp0 == NEVER && comp1 == NEVER)
  833. return FAIL;
  834. break;
  835. case XOR:
  836. if ((comp0 == ALWAYS && comp1 == NEVER) || (comp0 == NEVER && comp1 == ALWAYS))
  837. return PASS;
  838. if ((comp0 == ALWAYS && comp1 == ALWAYS) || (comp0 == NEVER && comp1 == NEVER))
  839. return FAIL;
  840. break;
  841. case XNOR:
  842. if ((comp0 == ALWAYS && comp1 == NEVER) || (comp0 == NEVER && comp1 == ALWAYS))
  843. return FAIL;
  844. if ((comp0 == ALWAYS && comp1 == ALWAYS) || (comp0 == NEVER && comp1 == NEVER))
  845. return PASS;
  846. break;
  847. default:
  848. return UNDETERMINED;
  849. }
  850. return UNDETERMINED;
  851. }
  852. };
  853. union UPE_Copy
  854. {
  855. u32 Hex;
  856. BitField< 0,1,u32> clamp0; // if set clamp top
  857. BitField< 1,1,u32> clamp1; // if set clamp bottom
  858. BitField< 2,1,u32> yuv; // if set, color conversion from RGB to YUV
  859. BitField< 3,4,u32> target_pixel_format; // realformat is (fmt/2)+((fmt&1)*8).... for some reason the msb is the lsb (pattern: cycling right shift)
  860. BitField< 7,2,u32> gamma; // gamma correction.. 0 = 1.0 ; 1 = 1.7 ; 2 = 2.2 ; 3 is reserved
  861. BitField< 9,1,u32> half_scale; // "mipmap" filter... 0 = no filter (scale 1:1) ; 1 = box filter (scale 2:1)
  862. BitField<10,1,u32> scale_invert; // if set vertical scaling is on
  863. BitField<11,1,u32> clear;
  864. BitField<12,2,u32> frame_to_field; // 0 progressive ; 1 is reserved ; 2 = interlaced (even lines) ; 3 = interlaced 1 (odd lines)
  865. BitField<14,1,u32> copy_to_xfb;
  866. BitField<15,1,u32> intensity_fmt; // if set, is an intensity format (I4,I8,IA4,IA8)
  867. BitField<16,1,u32> auto_conv; // if 0 automatic color conversion by texture format and pixel type
  868. u32 tp_realFormat()
  869. {
  870. return target_pixel_format / 2 + (target_pixel_format & 1) * 8;
  871. }
  872. };
  873. union BPU_PreloadTileInfo
  874. {
  875. u32 hex;
  876. struct
  877. {
  878. u32 count : 15;
  879. u32 type : 2;
  880. };
  881. };
  882. struct BPS_TmemConfig
  883. {
  884. u32 preload_addr;
  885. u32 preload_tmem_even;
  886. u32 preload_tmem_odd;
  887. BPU_PreloadTileInfo preload_tile_info;
  888. u32 tlut_src;
  889. u32 tlut_dest;
  890. u32 texinvalidate;
  891. };
  892. // All of BP memory
  893. struct BPCmd
  894. {
  895. int address;
  896. int changes;
  897. int newvalue;
  898. };
  899. struct BPMemory
  900. {
  901. GenMode genMode;
  902. u32 display_copy_filter[4]; // 01-04
  903. u32 unknown; // 05
  904. // indirect matrices (set by GXSetIndTexMtx, selected by TevStageIndirect::mid)
  905. // abc form a 2x3 offset matrix, there's 3 such matrices
  906. // the 3 offset matrices can either be indirect type, S-type, or T-type
  907. // 6bit scale factor s is distributed across IND_MTXA/B/C.
  908. // before using matrices scale by 2^-(s-17)
  909. IND_MTX indmtx[3];//06-0e GXSetIndTexMtx, 2x3 matrices
  910. IND_IMASK imask;//0f
  911. TevStageIndirect tevind[16];//10 GXSetTevIndirect
  912. X12Y12 scissorTL; //20
  913. X12Y12 scissorBR; //21
  914. LPSize lineptwidth; //22 line and point width
  915. u32 sucounter; //23
  916. u32 rascounter; //24
  917. TEXSCALE texscale[2]; //25-26 GXSetIndTexCoordScale
  918. RAS1_IREF tevindref; //27 GXSetIndTexOrder
  919. TwoTevStageOrders tevorders[8]; //28-2F
  920. TCoordInfo texcoords[8]; //0x30 s,t,s,t,s,t,s,t...
  921. ZMode zmode; //40
  922. BlendMode blendmode; //41
  923. ConstantAlpha dstalpha; //42
  924. PEControl zcontrol; //43 GXSetZCompLoc, GXPixModeSync
  925. FieldMask fieldmask; //44
  926. u32 drawdone; //45, bit1=1 if end of list
  927. u32 unknown5; //46 clock?
  928. u32 petoken; //47
  929. u32 petokenint; // 48
  930. X10Y10 copyTexSrcXY; // 49
  931. X10Y10 copyTexSrcWH; // 4a
  932. u32 copyTexDest; //4b// 4b == CopyAddress (GXDispCopy and GXTexCopy use it)
  933. u32 unknown6; //4c
  934. u32 copyMipMapStrideChannels; // 4d usually set to 4 when dest is single channel, 8 when dest is 2 channel, 16 when dest is RGBA
  935. // also, doubles whenever mipmap box filter option is set (excent on RGBA). Probably to do with number of bytes to look at when smoothing
  936. u32 dispcopyyscale; //4e
  937. u32 clearcolorAR; //4f
  938. u32 clearcolorGB; //50
  939. u32 clearZValue; //51
  940. UPE_Copy triggerEFBCopy; //52
  941. u32 copyfilter[2]; //53,54
  942. u32 boundbox0;//55
  943. u32 boundbox1;//56
  944. u32 unknown7[2];//57,58
  945. X10Y10 scissorOffset; //59
  946. u32 unknown8[6]; //5a,5b,5c,5d, 5e,5f
  947. BPS_TmemConfig tmem_config; // 60-66
  948. u32 metric; //67
  949. FieldMode fieldmode;//68
  950. u32 unknown10[7];//69-6F
  951. u32 unknown11[16];//70-7F
  952. FourTexUnits tex[2]; //80-bf
  953. TevStageCombiner combiners[16]; //0xC0-0xDF
  954. TevReg tevregs[4]; //0xE0
  955. FogRangeParams fogRange; // 0xE8
  956. FogParams fog; //0xEE,0xEF,0xF0,0xF1,0xF2
  957. AlphaTest alpha_test; //0xF3
  958. ZTex1 ztex1; //0xf4,0xf5
  959. ZTex2 ztex2;
  960. TevKSel tevksel[8];//0xf6,0xf7,f8,f9,fa,fb,fc,fd
  961. u32 bpMask; //0xFE
  962. u32 unknown18; //ff
  963. bool UseEarlyDepthTest() const { return zcontrol.early_ztest && zmode.testenable; }
  964. bool UseLateDepthTest() const { return !zcontrol.early_ztest && zmode.testenable; }
  965. };
  966. #pragma pack()
  967. extern BPMemory bpmem;
  968. void LoadBPReg(u32 value0);
  969. void LoadBPRegPreprocess(u32 value0);
  970. void GetBPRegInfo(const u8* data, std::string* name, std::string* desc);