Sony PlayStation2 Study
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
1.5 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. #include <packet.h>
  5. #define SPR_BEGIN 0x70000000
  6. packet_t *packet_init(int qwords, int type)
  7. {
  8. int byte_size = 0;
  9. packet_t *packet = (packet_t*)calloc(1,sizeof(packet_t));
  10. if (packet == NULL)
  11. {
  12. return NULL;
  13. }
  14. if (type == PACKET_SPR)
  15. {
  16. packet->data = (qword_t *)SPR_BEGIN;
  17. packet->qwc = 0x1000;
  18. }
  19. else
  20. {
  21. // Size of qwords in bytes.
  22. byte_size = qwords << 4;
  23. // Allocate the data area in bytes aligned to cache line.
  24. if ((packet->data = memalign(64, byte_size)) == NULL)
  25. {
  26. free(packet);
  27. return NULL;
  28. }
  29. }
  30. // Set the pointer attribute to ucab space.
  31. if (type == PACKET_UCAB)
  32. {
  33. packet->data = (qword_t *)((u32)packet->data | 0x30000000);
  34. }
  35. // Clear the packet area.
  36. memset(packet->data, 0, byte_size);
  37. // Set the packet counts
  38. packet->qwc = 0;
  39. packet->qwords = qwords;
  40. packet->type = type;
  41. // End function.
  42. return packet;
  43. }
  44. void packet_free(packet_t *packet)
  45. {
  46. // Free the allocated data buffer.
  47. if (packet->type == PACKET_SPR)
  48. {
  49. packet->data = NULL;
  50. }
  51. else
  52. {
  53. if (packet->type == PACKET_UCAB)
  54. {
  55. packet->data = (qword_t *)((u32)packet->data ^ 0x30000000);
  56. }
  57. free(packet->data);
  58. }
  59. free(packet);
  60. }
  61. void packet_reset(packet_t *packet)
  62. {
  63. // Reset the quadword counter.
  64. packet->qwc = 0;
  65. if (packet->type == PACKET_SPR)
  66. {
  67. packet->data = (qword_t *)SPR_BEGIN;
  68. return;
  69. }
  70. // Zero out the data
  71. memset(packet->data, 0, packet->qwords << 4);
  72. }