MONOTEST.C 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. ** Command & Conquer Renegade(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. #include "windows.h"
  19. #include "winioctl.h"
  20. #include "stdio.h"
  21. #include "stdlib.h"
  22. #include "monodrvr.h"
  23. #include "conio.h"
  24. #define MESSAGE1 "*** Page 1 ***\n"
  25. #define MESSAGE2 "*** Page 2 ***\n"
  26. #define MESSAGE3 "Another line of text.\n"
  27. long Print(HANDLE handle, char const * text)
  28. {
  29. long retval = 0;
  30. if (text != NULL) {
  31. WriteFile(handle, text, strlen(text), &retval, NULL);
  32. printf(text);
  33. }
  34. return(retval);
  35. }
  36. int __cdecl main(int argc, char *argv[])
  37. {
  38. HANDLE handle1;
  39. HANDLE handle2;
  40. char attrib = 0x70;
  41. handle1 = CreateFile("\\\\.\\MONO", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  42. if (handle1 != INVALID_HANDLE_VALUE) {
  43. long retval;
  44. struct {
  45. int X,Y,W,H;
  46. } windowcontrol;
  47. int value;
  48. struct {
  49. int X,Y,W,H,A;
  50. } fillcontrol;
  51. Print(handle1, MESSAGE1);
  52. printf("Press <ENTER> to proceed.\n");
  53. getchar();
  54. handle2 = CreateFile("\\\\.\\MONO", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  55. if (handle2 != INVALID_HANDLE_VALUE) {
  56. Print(handle2, MESSAGE2);
  57. printf("Press <ENTER> to proceed again.\n");getchar();
  58. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_BRING_TO_TOP, NULL, 0, NULL, 0, &retval, 0);
  59. printf("First page should reappear.\n");getchar();
  60. DeviceIoControl(handle2, (DWORD)IOCTL_MONO_BRING_TO_TOP, NULL, 0, NULL, 0, &retval, 0);
  61. printf("Second page should reappear.\n");getchar();
  62. {
  63. unsigned short * ptr = NULL;
  64. unsigned short * ptr2 = NULL;
  65. DeviceIoControl(handle2, (DWORD)IOCTL_MONO_LOCK, NULL, 0, &ptr, sizeof(ptr), &retval, 0);
  66. if (ptr != NULL) {
  67. *ptr = 0x0720;
  68. }
  69. printf("Upper left character should blank out.\n");getchar();
  70. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_BRING_TO_TOP, NULL, 0, NULL, 0, &retval, 0);
  71. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_LOCK, NULL, 0, &ptr2, sizeof(ptr2), &retval, 0);
  72. if (ptr2 != NULL) {
  73. *ptr2 = 0x0720;
  74. }
  75. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_UNLOCK, NULL, 0, NULL, 0, &retval, 0);
  76. printf("First page should NOT reappear (but it has been modified).\n");getchar();
  77. DeviceIoControl(handle2, (DWORD)IOCTL_MONO_BRING_TO_TOP, NULL, 0, NULL, 0, &retval, 0);
  78. if (ptr != NULL) {
  79. *ptr = 0x0721;
  80. }
  81. DeviceIoControl(handle2, (DWORD)IOCTL_MONO_UNLOCK, NULL, 0, NULL, 0, &retval, 0);
  82. printf("Second page is now modified after after a call to unlock for page 1.\n");getchar();
  83. }
  84. CloseHandle(handle2);
  85. } else {
  86. printf("Unable to open second device handle.\n");getchar();
  87. }
  88. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_BRING_TO_TOP, NULL, 0, NULL, 0, &retval, 0);
  89. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_SET_ATTRIBUTE, &attrib, 1, NULL, 0, &retval, 0);
  90. Print(handle1, MESSAGE3);
  91. printf("First page should reappear with new text.\n");getchar();
  92. windowcontrol.X = 10;
  93. windowcontrol.Y = 10;
  94. windowcontrol.W = 20;
  95. windowcontrol.H = 10;
  96. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_SET_WINDOW, &windowcontrol, sizeof(windowcontrol), NULL, 0, &retval, 0);
  97. Print(handle1, "This text should appear in a window that is of limited size. You should notice that the text wraps at the right margin.\n");
  98. printf("Sub window printing -- no wrap at right margin.\n");getchar();
  99. value = MONOFLAG_WRAP;
  100. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_SET_FLAG, &value, sizeof(value), NULL, 0, &retval, 0);
  101. Print(handle1, "\fThis text should appear in a window that is of limited size. You should notice that the text wraps at the right margin.\n");
  102. printf("Sub window printing -- wrapping at right margin.\n");getchar();
  103. fillcontrol.X = 0;
  104. fillcontrol.Y = 0;
  105. fillcontrol.W = 100;
  106. fillcontrol.H = 100;
  107. fillcontrol.A = 0x0F;
  108. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_FILL_ATTRIB, &fillcontrol, sizeof(fillcontrol), NULL, 0, &retval, 0);
  109. printf("Screen attribute change.\n");getchar();
  110. fillcontrol.X = 0;
  111. fillcontrol.Y = 0;
  112. fillcontrol.W = 100;
  113. fillcontrol.H = 100;
  114. fillcontrol.A = 0x07;
  115. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_FILL_ATTRIB, &fillcontrol, sizeof(fillcontrol), NULL, 0, &retval, 0);
  116. printf("Screen attribute restore.\n");getchar();
  117. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_PAN, NULL, 0, NULL, 0, &retval, 0);
  118. printf("Now it should pan over one column.\n");getchar();
  119. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_SCROLL, NULL, 0, NULL, 0, &retval, 0);
  120. printf("Now it should scroll up one row.\n");getchar();
  121. attrib = 0x07;
  122. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_SET_ATTRIBUTE, &attrib, 1, NULL, 0, &retval, 0);
  123. DeviceIoControl(handle1, (DWORD)IOCTL_MONO_CLEAR_SCREEN, NULL, 0, NULL, 0, &retval, 0);
  124. CloseHandle(handle1);
  125. }
  126. #ifdef NEVER
  127. HANDLE hDriver;
  128. UCHAR outputString[] = "Test Message\nfor the monochrome device.\n";
  129. UCHAR altString[] = "'\t','\n'";
  130. UCHAR topline[] = "Top line of screen.\n\n\n\n";
  131. DWORD cbReturned;
  132. struct {
  133. int X;
  134. int Y;
  135. } cursorpos;
  136. if ((hDriver = CreateFile("\\\\.\\MONO", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != ((HANDLE)-1)) {
  137. printf("\nRetrieved valid handle for MONO driver\n");
  138. } else {
  139. printf("Can't get a handle to MONO driver\n");
  140. return 1;
  141. }
  142. WriteFile(hDriver, outputString, strlen(outputString), &cbReturned, NULL);
  143. printf("WriteFile says it wrote out %d bytes.\n", cbReturned);
  144. if (DeviceIoControl(hDriver, (DWORD) IOCTL_MONO_PRINT_RAW, altString, sizeof(altString)-1, NULL, 0, &cbReturned, 0)) {
  145. printf("DeviceIoControl worked\n\n");
  146. cursorpos.X = 0;
  147. cursorpos.Y = 0;
  148. DeviceIoControl(hDriver, (DWORD)IOCTL_MONO_SET_CURSOR, (char*)&cursorpos, sizeof(cursorpos), NULL, 0, &cbReturned, 0);
  149. WriteFile(hDriver, topline, strlen(topline), &cbReturned, NULL);
  150. printf("Hit <Enter> to clear the mono display: \n");
  151. getchar();
  152. DeviceIoControl(hDriver, (DWORD) IOCTL_MONO_CLEAR_SCREEN, NULL, 0, NULL, 0, &cbReturned, 0);
  153. printf("'Bye\n");
  154. } else {
  155. printf("DeviceIoControl failed\n");
  156. }
  157. CloseHandle(hDriver);
  158. #endif
  159. return 0;
  160. }