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.

237 lines
6.3 KiB

  1. /* File: D:\WACKER\emu\viewdini.c (Created: 31-Jan-1994)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 2 $
  7. * $Date: 5/09/01 4:47p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <tdll\stdtyp.h>
  12. #include <tdll\session.h>
  13. #include <tdll\mc.h>
  14. #include <tdll\assert.h>
  15. #include <tdll\backscrl.h>
  16. #include <tdll\htchar.h>
  17. #include <tdll\term.h>
  18. #include "emu.h"
  19. #include "emu.hh"
  20. #include "viewdata.hh"
  21. #if defined(INCL_VIEWDATA)
  22. #define MAX_ROWS 24
  23. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  24. * EmuViewdataInit
  25. *
  26. * DESCRIPTION: Performs the initialization of the Viewdata emulator that
  27. * is common to DOS and OS2.
  28. *
  29. * ARGUMENTS: ehdl -- handle the emulator session
  30. *
  31. * RETURNS: nothing
  32. */
  33. void EmuViewdataInit(const HHEMU hhEmu)
  34. {
  35. int i;
  36. LOGFONT lf;
  37. HWND hwndTerm;
  38. PSTVIEWDATAPRIVATE pstPRI;
  39. static struct trans_entry const astfViewdataTable[] =
  40. {
  41. {NEW_STATE, 0, 0, 0}, // State 0
  42. {0, ETEXT('\x20'), ETEXT('\x7F'), EmuViewdataCharDisplay}, // All
  43. {1, ETEXT('\x1B'), ETEXT('\x1B'), nothing}, // Esc
  44. {0, ETEXT('\x05'), ETEXT('\x05'), EmuViewdataAnswerback}, // Ctrl-E
  45. {0, ETEXT('\x08'), ETEXT('\x08'), EmuViewdataCursorLeft}, // Backspace
  46. {0, ETEXT('\x09'), ETEXT('\x09'), EmuViewdataCursorRight}, // Tab
  47. {0, ETEXT('\x0A'), ETEXT('\x0A'), EmuViewdataCursorDown}, // New Line
  48. {0, ETEXT('\x0B'), ETEXT('\x0B'), EmuViewdataCursorUp}, // VT
  49. {0, ETEXT('\x0C'), ETEXT('\x0C'), EmuViewdataClearScreen}, // Form Feed
  50. {0, ETEXT('\x0D'), ETEXT('\x0D'), carriagereturn}, // CR
  51. {0, ETEXT('\x11'), ETEXT('\x11'), EmuViewdataCursorSet}, // Ctrl-Q
  52. {0, ETEXT('\x14'), ETEXT('\x14'), EmuViewdataCursorSet}, // Ctrl-T
  53. {0, ETEXT('\x1E'), ETEXT('\x1E'), EmuViewdataCursorHome}, // Ctrl-^
  54. {0, ETEXT('\x80'), ETEXT('\xFF'), EmuChkChar}, // Upper Ascii
  55. {NEW_STATE, 0, 0, 0}, // State 1 // Esc
  56. {0, ETEXT('\x31'), ETEXT('\x37'), nothing}, // 1 - 7
  57. {0, ETEXT('\x41'), ETEXT('\x49'), EmuViewdataSetAttr}, // A - I
  58. {0, ETEXT('\x4C'), ETEXT('\x4D'), EmuViewdataSetAttr}, // L - M
  59. {0, ETEXT('\x51'), ETEXT('\x5A'), EmuViewdataSetAttr}, // Q - Z
  60. {0, ETEXT('\x5C'), ETEXT('\x5D'), EmuViewdataSetAttr}, // \ - ]
  61. {0, ETEXT('\x5E'), ETEXT('\x5E'), EmuViewdataMosaicHold}, // ^
  62. {0, ETEXT('\x5F'), ETEXT('\x5F'), EmuViewdataMosaicRelease}, // _
  63. };
  64. emuInstallStateTable(hhEmu, astfViewdataTable, DIM(astfViewdataTable));
  65. // Allocate and initialize private data for viewdata emulator.
  66. //
  67. if (hhEmu->pvPrivate != 0)
  68. {
  69. free(hhEmu->pvPrivate);
  70. hhEmu->pvPrivate = 0;
  71. }
  72. hhEmu->pvPrivate = malloc(sizeof(VIEWDATAPRIVATE));
  73. if (hhEmu->pvPrivate == 0)
  74. {
  75. assert(FALSE);
  76. return;
  77. }
  78. pstPRI = (PSTVIEWDATAPRIVATE)hhEmu->pvPrivate;
  79. pstPRI->aMapColors[0] = 4;
  80. pstPRI->aMapColors[1] = 2;
  81. pstPRI->aMapColors[2] = 6;
  82. pstPRI->aMapColors[3] = 1;
  83. pstPRI->aMapColors[4] = 5;
  84. pstPRI->aMapColors[5] = 3;
  85. pstPRI->aMapColors[6] = 15;
  86. /* --- Allocate attribute buffer for View Data junk --- */
  87. pstPRI->apstVD = malloc(MAX_EMUROWS * sizeof(PSTVIEWDATA));
  88. if (pstPRI->apstVD == 0)
  89. {
  90. assert(FALSE);
  91. return;
  92. }
  93. memset(pstPRI->apstVD, 0, MAX_EMUROWS * sizeof(PSTVIEWDATA));
  94. for (i = 0 ; i < MAX_EMUROWS ; ++i)
  95. {
  96. pstPRI->apstVD[i] = malloc(VIEWDATA_COLS_40MODE * sizeof(STVIEWDATA));
  97. if (pstPRI->apstVD[i] == 0)
  98. {
  99. assert(FALSE);
  100. return;
  101. }
  102. memset(pstPRI->apstVD[i], 0, sizeof(STVIEWDATA));
  103. }
  104. /* --- functions specific to prestel (viewdata) --- */
  105. hhEmu->emuResetTerminal = EmuViewdataReset;
  106. hhEmu->emu_deinstall = EmuViewdataDeinstall;
  107. hhEmu->emu_kbdin = EmuViewdataKbd;
  108. hhEmu->emu_graphic = EmuViewdataCharDisplay;
  109. hhEmu->emu_highchar = ETEXT('\x7F');
  110. hhEmu->emu_maxcol = VIEWDATA_COLS_40MODE - 1;
  111. // Also, set font to Arial Alternative
  112. //
  113. memset(&lf, 0, sizeof(LOGFONT));
  114. hwndTerm = sessQueryHwndTerminal(hhEmu->hSession);
  115. termGetLogFont(hwndTerm, &lf);
  116. if (StrCharCmpi(lf.lfFaceName, "Arial Alternative") != 0)
  117. {
  118. StrCharCopy(lf.lfFaceName, "Arial Alternative");
  119. lf.lfCharSet = DEFAULT_CHARSET;
  120. lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
  121. termSetLogFont(hwndTerm, &lf);
  122. }
  123. EmuViewdataReset(hhEmu, FALSE);
  124. std_setcolors(hhEmu, VC_BRT_WHITE, VC_BLACK);
  125. // Turn backscroll off for Prestel
  126. //
  127. backscrlSetShowFlag(sessQueryBackscrlHdl(hhEmu->hSession), FALSE);
  128. return;
  129. }
  130. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  131. * FUNCTION:
  132. * EmuViewdataDeinstall
  133. *
  134. * DESCRIPTION:
  135. * Frees up buffers allocated for view data junk.
  136. *
  137. * ARGUMENTS:
  138. * fQuitting - because other funcs have it.
  139. *
  140. * RETURNS:
  141. * void
  142. *
  143. */
  144. void EmuViewdataDeinstall(const HHEMU hhEmu)
  145. {
  146. int i;
  147. const PSTVIEWDATAPRIVATE pstPRI = (PSTVIEWDATAPRIVATE)hhEmu->pvPrivate;
  148. assert(hhEmu);
  149. if (pstPRI)
  150. {
  151. if (pstPRI->apstVD)
  152. {
  153. //
  154. // Fixed memory leak as this was only freeing 24 rows
  155. // not the MAX_EMUROWS that was allocated. REV 05/09/2001.
  156. //
  157. for (i = 0 ; i < MAX_EMUROWS ; ++i)
  158. {
  159. if (pstPRI->apstVD[i])
  160. {
  161. free(pstPRI->apstVD[i]);
  162. pstPRI->apstVD[i] =NULL;
  163. }
  164. }
  165. free(pstPRI->apstVD);
  166. pstPRI->apstVD = NULL;
  167. }
  168. free(hhEmu->pvPrivate);
  169. hhEmu->pvPrivate = 0;
  170. }
  171. return;
  172. }
  173. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  174. * EmuViewdataReset
  175. *
  176. * DESCRIPTION: Sets the viewdata emulator to the proper conditions when
  177. * starting up.
  178. *
  179. * ARGUMENTS: ehdl -- emu handle
  180. *
  181. * RETURNS: nothing
  182. */
  183. /* ARGSUSED */
  184. int EmuViewdataReset(const HHEMU hhEmu, int const fHost)
  185. {
  186. hhEmu->top_margin = 0;
  187. hhEmu->bottom_margin = MAX_ROWS-1;
  188. hhEmu->mode_KAM = hhEmu->mode_IRM = hhEmu->mode_VEM =
  189. hhEmu->mode_HEM = hhEmu->mode_DECCKM = hhEmu->mode_DECOM =
  190. hhEmu->mode_DECCOLM = hhEmu->mode_DECPFF = hhEmu->mode_DECPEX =
  191. hhEmu->mode_DECSCNM = hhEmu->mode_25enab =
  192. hhEmu->mode_protect = hhEmu->mode_block = hhEmu->mode_local = RESET;
  193. hhEmu->mode_SRM = hhEmu->mode_LNM = hhEmu->mode_DECTCEM = SET;
  194. hhEmu->mode_AWM = TRUE;
  195. emu_cleartabs(hhEmu, 3);
  196. return 0;
  197. }
  198. #endif // INCL_VIEWDATA
  199. /************************* end of viewdini.c **************************/