MPLPC.CPP 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program 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. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. extern "C" {
  19. #include "lpc.h"
  20. #include "types.h"
  21. #include "services.h"
  22. #include "rtq.h"
  23. #include <stdio.h>
  24. #include <mem.h>
  25. };
  26. #include "mplib.h"
  27. #define IDLE_QUEUE 6
  28. #define REC_QUEUE 7
  29. #define SEND_QUEUE 8
  30. void
  31. SetLPCData(LPCData *lpc)
  32. {
  33. lpc->version = 1;
  34. lpc->sizeOfArgs = 0;
  35. lpc->service = LPC_NOSERVICE;
  36. }
  37. void
  38. GetGameDef(void *gameDef, int* len)
  39. {
  40. RTQ_NODE *n = MGenGetNode(IDLE_QUEUE);
  41. LPCData *p;
  42. LPCReturn *r;
  43. if (!n) {
  44. *len = 0;
  45. return; // can't get service!
  46. }
  47. p = (LPCData *) n->rtqDatum;
  48. SetLPCData(p);
  49. p->service = LPC_GENGETGAMEDEF;
  50. MGenMoveTo(IDLE_QUEUE, SEND_QUEUE);
  51. // make call
  52. PostWindowsMessage();
  53. // wait for return
  54. while ((n = MGenGetNode(REC_QUEUE)) == 0)
  55. Yield();
  56. r = (LPCReturn *) n->rtqDatum;
  57. if (r->sizeOfReturn > *len || r->error != LPC_NOERROR) {
  58. *len = 0;
  59. return;
  60. }
  61. *len = r->sizeOfReturn;
  62. memcpy(gameDef, r->Data, r->sizeOfReturn);
  63. // get ready for next call
  64. MGenMoveTo(REC_QUEUE, IDLE_QUEUE);
  65. }
  66. int
  67. LPCGetMPAddr(void)
  68. {
  69. RTQ_NODE *n = MGenGetNode(IDLE_QUEUE);
  70. LPCData *p;
  71. LPCReturn *r;
  72. int retVal;
  73. p = (LPCData *) n->rtqDatum;
  74. SetLPCData(p);
  75. p->service = LPC_GETMPADDR;
  76. MGenMoveTo(IDLE_QUEUE, SEND_QUEUE);
  77. PostWindowsMessage();
  78. while ((n = MGenGetNode(REC_QUEUE)) == 0)
  79. Yield();
  80. r = (LPCReturn *) n->rtqDatum;
  81. if (r->sizeOfReturn != sizeof(int) || r->error != LPC_NOERROR) {
  82. return -1;
  83. }
  84. retVal = *((int *) r->Data);
  85. MGenMoveTo(REC_QUEUE, IDLE_QUEUE);
  86. return retVal;
  87. }
  88. void
  89. NullLPC(void)
  90. {
  91. RTQ_NODE *n = MGenGetNode(IDLE_QUEUE);
  92. LPCData *p;
  93. p = (LPCData *) n->rtqDatum;
  94. SetLPCData(p);
  95. p->service = LPC_NULLSERVICE;
  96. MGenMoveTo(IDLE_QUEUE, SEND_QUEUE);
  97. PostWindowsMessage();
  98. while ((n = MGenGetNode(REC_QUEUE)) == 0)
  99. Yield();
  100. MGenMoveTo(REC_QUEUE, IDLE_QUEUE);
  101. }
  102.