ODGraph.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /* OpenDoors Online Software Programming Toolkit
  2. * (C) Copyright 1991 - 1999 by Brian Pirie.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. *
  19. * File: ODGraph.c
  20. *
  21. * Description: Implements special ANSI/AVATAR control functions.
  22. *
  23. * Revisions: Date Ver Who Change
  24. * ---------------------------------------------------------------
  25. * Oct 13, 1994 6.00 BP New file header format.
  26. * Dec 09, 1994 6.00 BP Standardized coding style.
  27. * Aug 19, 1995 6.00 BP 32-bit portability.
  28. * Nov 11, 1995 6.00 BP Removed register keyword.
  29. * Nov 14, 1995 6.00 BP Added include of odscrn.h.
  30. * Nov 16, 1995 6.00 BP Removed oddoor.h, added odcore.h.
  31. * Nov 16, 1995 6.00 BP Moved local vars here from odcore.c.
  32. * Dec 12, 1995 6.00 BP Added entry, exit and kernel macros.
  33. * Dec 30, 1995 6.00 BP Added ODCALL for calling convention.
  34. * Feb 19, 1996 6.00 BP Changed version number to 6.00.
  35. * Mar 03, 1996 6.10 BP Begin version 6.10.
  36. * Mar 13, 1996 6.10 BP Added od_get_cursor().
  37. * Aug 10, 2003 6.23 SH *nix support
  38. */
  39. #define BUILDING_OPENDOORS
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include "OpenDoor.h"
  44. #include "ODCore.h"
  45. #include "ODGen.h"
  46. #include "ODScrn.h"
  47. #include "ODKrnl.h"
  48. /* Local private variables. */
  49. static char szANSIClearLine[3] = {27, '[', 'K'};
  50. static char szAvatarClearLine[2] = {22, 7};
  51. /* ----------------------------------------------------------------------------
  52. * od_clr_line()
  53. *
  54. * Clears the contents of the current line, from the current cursor position
  55. * to the end of the line. This function affects both local and remote
  56. * screens.
  57. *
  58. * Parameters: None.
  59. *
  60. * Return: void
  61. */
  62. ODAPIDEF void ODCALL od_clr_line(void)
  63. {
  64. char *pchLine;
  65. INT nCharsLeft;
  66. INT nCount;
  67. /* Log function entry if running in trace mode. */
  68. TRACE(TRACE_API, "od_clr_line()");
  69. /* Ensure that OpenDoors has been initialized. */
  70. if(!bODInitialized) od_init();
  71. OD_API_ENTRY();
  72. /* Obtain the current cursor position. */
  73. ODScrnGetTextInfo(&ODTextInfo);
  74. /* Calculate the number of columns that are to be erased. */
  75. nCharsLeft = 80 - ODTextInfo.curx;
  76. /* If either ANSI or AVATAR mode is available, then we first */
  77. /* clear the line on the local screen without affecting the */
  78. /* remote screen. */
  79. if(od_control.user_avatar || od_control.user_ansi)
  80. {
  81. pchLine = (char *)szODWorkString;
  82. for(nCount = 0; nCount <= nCharsLeft; ++nCount) *pchLine++ = ' ';
  83. *pchLine = '\0';
  84. ODScrnEnableScrolling(0);
  85. ODScrnDisplayString(szODWorkString);
  86. ODScrnEnableScrolling(1);
  87. ODScrnSetCursorPos(ODTextInfo.curx, ODTextInfo.cury);
  88. }
  89. /* If AVATAR mode is active. */
  90. if(od_control.user_avatar)
  91. {
  92. /* Transmit the two-character AVATAR clear to end of line sequence. */
  93. od_disp(szAvatarClearLine, 2, FALSE);
  94. }
  95. /* If ANSI mode is active. */
  96. else if(od_control.user_ansi)
  97. {
  98. /* Transmit the three-character ANSI clear to end of line sequence. */
  99. od_disp(szANSIClearLine, 3, FALSE);
  100. }
  101. /* If we are operating in plain-ASCII mode. */
  102. else
  103. {
  104. /* Generate a sequence of space characters followed by backspace */
  105. /* characters. */
  106. pchLine = (char *)szODWorkString;
  107. for(nCount = 0; nCount < nCharsLeft; ++nCount) *pchLine++ = ' ';
  108. for(nCount = 0; nCount < nCharsLeft; ++nCount) *pchLine++ = 8;
  109. *pchLine='\0';
  110. /* Send this sequence to both the local and remote screens. */
  111. od_disp(szODWorkString, strlen(szODWorkString), TRUE);
  112. }
  113. OD_API_EXIT();
  114. }
  115. /* ----------------------------------------------------------------------------
  116. * od_set_cursor()
  117. *
  118. * Moves the position of the cursor on both local and remote screens. This
  119. * function is available in all display modes other than plain-ASCII.
  120. *
  121. * Parameters: nRow - 1-based index of the row to position the cursor in.
  122. *
  123. * nColumn - Index of the column to position the cursor in.
  124. *
  125. * Return: void
  126. */
  127. ODAPIDEF void ODCALL od_set_cursor(INT nRow, INT nColumn)
  128. {
  129. static char szControlSequence[40];
  130. /* Log function entry if running in trace mode. */
  131. TRACE(TRACE_API, "od_set_cursor()");
  132. /* Ensure that OpenDoors has been initialized. */
  133. if(!bODInitialized) od_init();
  134. OD_API_ENTRY();
  135. /* Check validity of parameters. */
  136. if(nRow < 1 || nColumn < 1)
  137. {
  138. od_control.od_error = ERR_PARAMETER;
  139. return;
  140. }
  141. /* If AVATAR mode is on. */
  142. if(od_control.user_avatar)
  143. {
  144. /* Position the local cursor. */
  145. ODScrnSetCursorPos((BYTE)nColumn, (BYTE)nRow);
  146. /* Generate the AVATAR control sequence to position the remote cursor. */
  147. szControlSequence[0] = 22;
  148. szControlSequence[1] = 8;
  149. szControlSequence[2] = nRow;
  150. szControlSequence[3] = nColumn;
  151. /* Transmit the AVATAR control sequence to the remote terminal. */
  152. od_disp(szControlSequence, 4, FALSE);
  153. }
  154. /* If ANSI mode is on. */
  155. else if(od_control.user_ansi)
  156. {
  157. /* Generate the ANSI control sequence to position the remote cursor. */
  158. sprintf(szControlSequence, "x[%d;%dH", nRow, nColumn);
  159. szControlSequence[0] = 27;
  160. /* Transmit the ANSI control seequence to the remote terminal. */
  161. od_disp(szControlSequence, strlen(szControlSequence), FALSE);
  162. /* Position the cursor on the local screen. */
  163. ODScrnSetCursorPos((BYTE)nColumn, (BYTE)nRow);
  164. }
  165. else
  166. {
  167. /* If neither ANSI nor AVATAR modes are available, indicate this */
  168. /* in the error code in od_control. */
  169. od_control.od_error = ERR_NOGRAPHICS;
  170. }
  171. OD_API_EXIT();
  172. }
  173. /* ----------------------------------------------------------------------------
  174. * od_get_cursor()
  175. *
  176. * Returns our best estimate of the current position of the cursor on the
  177. * remote screen.
  178. *
  179. * Parameters: pnRow - 1-based index of the row to position the cursor in.
  180. *
  181. * pnColumn - Index of the column to position the cursor in.
  182. *
  183. * Return: void
  184. */
  185. ODAPIDEF void ODCALL od_get_cursor(INT *pnRow, INT *pnColumn)
  186. {
  187. tODScrnTextInfo TextInfo;
  188. /* Log function entry if running in trace mode. */
  189. TRACE(TRACE_API, "od_get_cursor()");
  190. /* Ensure that OpenDoors has been initialized. */
  191. if(!bODInitialized) od_init();
  192. OD_API_ENTRY();
  193. /* Check for parameter validity. */
  194. if(pnRow == NULL && pnColumn == NULL)
  195. {
  196. od_control.od_error = ERR_PARAMETER;
  197. OD_API_EXIT();
  198. return;
  199. }
  200. /* Obtain current state of local screen. */
  201. ODScrnGetTextInfo(&TextInfo);
  202. /* Set the caller's parameters to the current row and column, if each */
  203. /* of these parameters were supplied. */
  204. if(pnRow != NULL) *pnRow = (INT)TextInfo.cury;
  205. if(pnColumn != NULL) *pnColumn = (INT)TextInfo.curx;
  206. OD_API_EXIT();
  207. }