Leaked source code of windows server 2003
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.

274 lines
6.3 KiB

  1. /* File: D:\WACKER\emu\vt52.c (Created: 28-Dec-1993)
  2. *
  3. * Copyright 1994, 1998 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 3 $
  7. * $Date: 5/09/01 4:47p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <tdll\stdtyp.h>
  12. #include <tdll\chars.h>
  13. #include <tdll\print.h>
  14. #include <tdll\mc.h>
  15. #include <tdll\htchar.h>
  16. #include <tdll\assert.h>
  17. #include "emu.h"
  18. #include "emu.hh"
  19. #include "emuid.h"
  20. #include "emudec.hh"
  21. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22. * vt52PrintCommands
  23. *
  24. * DESCRIPTION:
  25. * Processes vt52 printing commands.
  26. *
  27. * ARGUMENTS:
  28. * none
  29. *
  30. * RETURNS:
  31. * nothing
  32. */
  33. void vt52PrintCommands(const HHEMU hhEmu)
  34. {
  35. int line;
  36. ECHAR code;
  37. ECHAR aechBuf[10];
  38. code = hhEmu->emu_code;
  39. switch (code)
  40. {
  41. case ETEXT('^'): /* auto print on */
  42. hhEmu->print_echo = TRUE;
  43. break;
  44. case ETEXT('_'): /* auto print off */
  45. hhEmu->print_echo = FALSE;
  46. break;
  47. case ETEXT(']'): /* print screen */
  48. for (line = 0; line < 24; ++line)
  49. printEchoLine(hhEmu->hPrintHost,
  50. hhEmu->emu_apText[row_index(hhEmu, line)],
  51. emuRowLen(hhEmu, row_index(hhEmu, line)));
  52. CnvrtMBCStoECHAR(aechBuf, sizeof(aechBuf), TEXT("0x0C"),
  53. StrCharGetByteCount(TEXT("0x0C")));
  54. printEchoLine(hhEmu->hPrintHost, aechBuf, sizeof(ECHAR));
  55. break;
  56. case ETEXT('V'): /* print cursor line */
  57. printEchoLine(hhEmu->hPrintHost,
  58. hhEmu->emu_apText[row_index(hhEmu, hhEmu->emu_currow)],
  59. emuRowLen(hhEmu, row_index(hhEmu, hhEmu->emu_currow)));
  60. break;
  61. case ETEXT('W'): /* enter printer controller mode */
  62. hhEmu->state = 4; /* start vt52_prnc() */
  63. break;
  64. case ETEXT('X'): /* exit printer controller mode */
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  71. * vt52Print
  72. *
  73. * DESCRIPTION:
  74. * Stores character and prints saved string of characters when termination
  75. * character is received.
  76. *
  77. * ARGUMENTS:
  78. * none
  79. *
  80. * RETURNS:
  81. * nothing
  82. */
  83. void vt52Print(const HHEMU hhEmu)
  84. {
  85. const PSTDECPRIVATE pstPRI = (PSTDECPRIVATE)hhEmu->pvPrivate;
  86. ECHAR ccode;
  87. ccode = hhEmu->emu_code;
  88. *pstPRI->pntr++ = ccode;
  89. *pstPRI->pntr = 0;
  90. ++pstPRI->len_s;
  91. if (pstPRI->len_s >= pstPRI->len_t &&
  92. memcmp(pstPRI->terminate,
  93. &pstPRI->storage[pstPRI->len_s - pstPRI->len_t],
  94. sizeof(pstPRI->terminate)) == 0)
  95. {
  96. /* received termination string, wrap it up */
  97. emuPrintChars(hhEmu, pstPRI->storage, pstPRI->len_s - pstPRI->len_t);
  98. pstPRI->pntr = pstPRI->storage;
  99. pstPRI->len_s = 0;
  100. hhEmu->state = 0; /* drop out of this routine */
  101. // Finish-up print job.
  102. //
  103. printEchoClose(hhEmu->hPrintHost);
  104. return;
  105. }
  106. /* haven't received termination sequence yet, is storage filled? */
  107. if ((unsigned)pstPRI->len_s >= (sizeof(pstPRI->storage) - 1))
  108. {
  109. /* copy most of string to print buffer */
  110. emuPrintChars(hhEmu, pstPRI->storage, pstPRI->len_s - pstPRI->len_t);
  111. /* move end of string to beginning of storage */
  112. memmove(pstPRI->storage,
  113. &pstPRI->storage[pstPRI->len_s - pstPRI->len_t],
  114. (unsigned)pstPRI->len_t);
  115. pstPRI->pntr = pstPRI->storage + pstPRI->len_t;
  116. pstPRI->len_s = pstPRI->len_t;
  117. }
  118. }
  119. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  120. * vt52_id
  121. *
  122. * DESCRIPTION:
  123. * Transmits the VT52 id code--ESC/Z.
  124. *
  125. * ARGUMENTS:
  126. * none
  127. *
  128. * RETURNS:
  129. * nothing
  130. */
  131. void vt52_id(const HHEMU hhEmu)
  132. {
  133. TCHAR *sp;
  134. ECHAR ech[10];
  135. sp = TEXT("\033/Z");
  136. CnvrtMBCStoECHAR(ech, sizeof(ech), TEXT("\033/Z"),
  137. StrCharGetByteCount(TEXT("\033/Z")));
  138. emuSendString(hhEmu, ech, (int)StrCharGetStrLength(sp));
  139. }
  140. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  141. * vt52_CUP
  142. *
  143. * DESCRIPTION:
  144. * Positions the cursor for the VT52 emulator.
  145. *
  146. * ARGUMENTS:
  147. * none
  148. *
  149. * RETURNS:
  150. * nothing
  151. */
  152. void vt52_CUP(const HHEMU hhEmu)
  153. {
  154. char_pn(hhEmu);
  155. (*hhEmu->emu_setcurpos)(hhEmu,
  156. hhEmu->num_param[0] - 1,
  157. hhEmu->num_param[1] - 1);
  158. }
  159. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  160. * vt52_kbdin
  161. *
  162. * DESCRIPTION:
  163. * Processes local keyboard keys for the VT52 emulator.
  164. *
  165. * ARGUMENTS:
  166. * key -- key to process
  167. * fTest -- if TRUE, just checks if it is an emulator key.
  168. *
  169. * RETURNS:
  170. * nothing
  171. */
  172. int vt52_kbdin(const HHEMU hhEmu, int key, const int fTest)
  173. {
  174. int index;
  175. /* -------------- Check Backspace & Delete keys ------------- */
  176. if (hhEmu->stUserSettings.fReverseDelBk && ((key == VK_BACKSPACE) ||
  177. (key == DELETE_KEY) || (key == DELETE_KEY_EXT)))
  178. {
  179. key = (key == VK_BACKSPACE) ? DELETE_KEY : VK_BACKSPACE;
  180. }
  181. /* -------------- Mapped PF1-PF4 keys ------------- */
  182. if (hhEmu->stUserSettings.fMapPFkeys &&
  183. (index = emuKbdKeyLookup(hhEmu, key, &hhEmu->stEmuKeyTbl3)) != -1)
  184. {
  185. if (!fTest)
  186. emuSendKeyString(hhEmu, index, &hhEmu->stEmuKeyTbl3);
  187. }
  188. /* -------------- Keypad Application mode ------------- */
  189. else if (hhEmu->mode_DECKPAM &&
  190. (index = emuKbdKeyLookup(hhEmu, key, &hhEmu->stEmuKeyTbl2)) != -1)
  191. {
  192. if (!fTest)
  193. emuSendKeyString(hhEmu, index, &hhEmu->stEmuKeyTbl2);
  194. }
  195. /* -------------- Normal mode keys ------------- */
  196. else if ((index = emuKbdKeyLookup(hhEmu, key, &hhEmu->stEmuKeyTbl)) != -1)
  197. {
  198. if (!fTest)
  199. emuSendKeyString(hhEmu, index, &hhEmu->stEmuKeyTbl);
  200. }
  201. else
  202. {
  203. index = std_kbdin(hhEmu, key, fTest);
  204. }
  205. return index;
  206. }
  207. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  208. * emuVT52Unload
  209. *
  210. * DESCRIPTION:
  211. * Unloads current emulator by freeing used memory.
  212. *
  213. * ARGUMENTS:
  214. * none
  215. *
  216. * RETURNS:
  217. * nothing
  218. */
  219. void emuVT52Unload(const HHEMU hhEmu)
  220. {
  221. assert(hhEmu);
  222. if (hhEmu->pvPrivate)
  223. {
  224. free(hhEmu->pvPrivate);
  225. hhEmu->pvPrivate = 0;
  226. }
  227. //
  228. // Make sure to free the key tables that were created when the emulator
  229. // was loaded, otherwise there is a memory leak. REV: 05/09/2001
  230. //
  231. emuKeyTableFree(&hhEmu->stEmuKeyTbl);
  232. emuKeyTableFree(&hhEmu->stEmuKeyTbl2);
  233. emuKeyTableFree(&hhEmu->stEmuKeyTbl3);
  234. return;
  235. }
  236. /* end of vt52.c */