Source code of Windows XP (NT5)
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.

845 lines
26 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  3. /* Houston, Texas */
  4. /*===========================================================================*/
  5. #define NOLSTRING TRUE /* jtf win3 mod */
  6. #include <windows.h>
  7. #include "port1632.h"
  8. #include "dcrc.h"
  9. #include "dynacomm.h"
  10. #include "task.h"
  11. #include "video.h"
  12. /*---------------------------------------------------------------------------*/
  13. /* clipRect () - Sets a rect to the current clip rect */
  14. /* Note: assumes getPort () has been called */
  15. /*---------------------------------------------------------------------------*/
  16. VOID clipRect(RECT *clpRect)
  17. {
  18. HRGN hClipRgn;
  19. hClipRgn = CreateRectRgnIndirect ((LPRECT) clpRect);
  20. SelectClipRgn(thePort, hClipRgn);
  21. DeleteObject (hClipRgn);
  22. }
  23. /*---------------------------------------------------------------------------*/
  24. /* pos() - [mbb] */
  25. /*---------------------------------------------------------------------------*/
  26. INT pos(STRING *word, STRING *str)
  27. {
  28. INT ndx, count;
  29. if((count = *str - *word + 1) > 0)
  30. {
  31. for(ndx = 1; ndx <= count; ndx += 1)
  32. if(memcmp(str+ndx, word+1, *word) == 0)
  33. return(ndx);
  34. }
  35. return(FALSE);
  36. }
  37. /*---------------------------------------------------------------------------*/
  38. /* delay() - Spin wheels & be nice to other windows applications */
  39. /*---------------------------------------------------------------------------*/
  40. /* NOTE: 1000/60 msec/ticks => 50/3; max delay w/o overflow = 3932 ticks */
  41. VOID delay(UINT units, DWORD *endingCount)
  42. {
  43. DWORD tmStart;
  44. DWORD dtmWait = (units * 50) / 3;
  45. tmStart = GetTickCount();
  46. while(GetTickCount() - tmStart < dtmWait)
  47. {
  48. PeekMessage(&msg, hItWnd, 0, 0, PM_NOREMOVE);
  49. updateTimer();
  50. }
  51. if(endingCount != NULL)
  52. *endingCount = tmStart + dtmWait;
  53. }
  54. /*---------------------------------------------------------------------------*/
  55. /* concat() - Concatanate two Pascal-type strings. [scf]*/
  56. /*---------------------------------------------------------------------------*/
  57. BYTE *concat (STRING *out, STRING *s1, STRING *s2)
  58. {
  59. STRING scratch[STR255];
  60. if ((WORD) (*s1 + *s2) < STR255)
  61. {
  62. if (out == s2)
  63. {
  64. memcpy (scratch, s2, (WORD) *s2 + 1);
  65. memcpy (&out[1], &s1[1], (WORD) *s1);
  66. memcpy (&out[*s1 + 1], &scratch[1], (WORD) *scratch);
  67. *out = *s1 + *scratch;
  68. }
  69. else
  70. {
  71. memcpy (&out[1], &s1[1], (WORD) *s1);
  72. memcpy (&out[*s1 + 1], &s2[1], (WORD) *s2);
  73. *out = *s1 + *s2;
  74. }
  75. }
  76. nullTerminate (out);
  77. return out;
  78. }
  79. /*---------------------------------------------------------------------------*/
  80. /* stripControl() - [scf] */
  81. /*---------------------------------------------------------------------------*/
  82. VOID stripControl(STRING *str)
  83. {
  84. WORD ndxDst, ndxSrc;
  85. STRING newStr[STR255];
  86. ndxSrc = 1;
  87. *newStr = 0;
  88. for (ndxDst = 1; ndxDst <= *str; ndxDst++)
  89. if (ndxSrc <= *str)
  90. {
  91. newStr[0] = (BYTE) ndxDst;
  92. if((str[ndxSrc] == '^') && (str[ndxSrc+1] != '$')) /* mbbx 1.04... */
  93. if (str[ndxSrc+1] == '^' || ndxSrc == *str)
  94. {
  95. newStr[ndxDst] = '^';
  96. ndxSrc += 2;
  97. }
  98. else
  99. {
  100. newStr[ndxDst] = str[ndxSrc+1] & 0x1f;
  101. ndxSrc += 2;
  102. }
  103. else
  104. {
  105. newStr[ndxDst] = str[ndxSrc];
  106. ndxSrc++;
  107. }
  108. }
  109. strEquals(str, newStr);
  110. }
  111. /*---------------------------------------------------------------------------*/
  112. /* clearBuffer() - Initialize terminal I/O capture buffer. [scf] */
  113. /*---------------------------------------------------------------------------*/
  114. VOID clearBuffer()
  115. {
  116. RECT clientRect;
  117. gIdleTimer = GetCurrentTime(); /* rjs bug2 001 */
  118. timPointer = GetCurrentTime();
  119. escAnsi = FALSE;
  120. escCol = -1;
  121. escCursor = FALSE;
  122. escGraphics = FALSE;
  123. grChrMode = FALSE;
  124. escLin = -1;
  125. escSeq = FALSE;
  126. escExtend = EXNONE;
  127. escSkip = 0;
  128. escVideo = 0;
  129. vidGraphics = GRNONE;
  130. vidInverse = FALSE;
  131. termDirty = FALSE;
  132. curLin = 0;
  133. curCol = 0;
  134. curTopLine = savTopLine = 0;
  135. savLeftCol = 0;
  136. cursorValid = FALSE;
  137. rectCursor(&cursorRect);
  138. clearTermBuffer(0, maxLines, maxChars + 2); /* mbbx 2.00.03: lines > 399 ... */
  139. termSetSelect(0L, 0L);
  140. chrHeight = stdChrHeight;
  141. chrWidth = stdChrWidth;
  142. GetClientRect (hTermWnd, (LPRECT) &clientRect);
  143. visScreenLine = hTE.viewRect.bottom / chrHeight - 1;
  144. nScrollRange.x = maxChars - (clientRect.right / chrWidth);
  145. nScrollPos.y = 0;
  146. nScrollPos.x = 0;
  147. updateTermScrollBars(FALSE);
  148. activSelect = FALSE;
  149. noSelect = TRUE; /* rjs bugs 020 */
  150. clearModes();
  151. InvalidateRect(hTermWnd, NULL, TRUE); /* mbbx 2.00.03 ... */
  152. UpdateWindow(hTermWnd);
  153. }
  154. /*---------------------------------------------------------------------------*/
  155. /* clearModes() - An terminal emulation initialization worker routine. [scf] */
  156. /*---------------------------------------------------------------------------*/
  157. VOID clearModes()
  158. {
  159. INT ndx;
  160. INT lin;
  161. INT col;
  162. cursorKeyMode = FALSE;
  163. keyPadAppMode = FALSE;
  164. originMode = FALSE;
  165. chInsMode = FALSE;
  166. scrRgnBeg = 0;
  167. shiftCharSet = 0;
  168. charSet[0] = 'B';
  169. charSet[1] = 'B';
  170. scrRgnEnd = maxScreenLine;
  171. statusLine = FALSE;
  172. curAttrib = 0;
  173. protectMode = FALSE;
  174. for (ndx = 1; ndx <= 131; ndx++)
  175. if (ndx % 8 == 0)
  176. tabs[ndx] = 1;
  177. else
  178. tabs[ndx] = 0;
  179. for (lin = 0; lin <= 23; lin++)
  180. for (col = 0; col <= 132; col++)
  181. attrib[lin][col] = 0;
  182. for (ndx = 0; ndx <= maxChars -1; ndx++)
  183. line25[ndx] = ' ';
  184. }
  185. /*---------------------------------------------------------------------------*/
  186. /* setCommDefaults() - [mbb] */
  187. /*---------------------------------------------------------------------------*/
  188. VOID setCommDefaults() /* mbbx 2.01.20 (2.01.17) ... */
  189. {
  190. BYTE str[MINRESSTR], portData[32];
  191. INT nPort, nSpeed, nData, nStop;
  192. trmParams.comDevRef = ITMNOCOM;
  193. trmParams.speed = 1200;
  194. trmParams.dataBits = ITMDATA8;
  195. trmParams.stopBits = ITMSTOP1;
  196. trmParams.parity = ITMNOPARITY;
  197. LoadString(hInst, STR_INI_PORT, (LPSTR) str, MINRESSTR);
  198. GetProfileString((LPSTR) szAppName_private, (LPSTR) str, (LPSTR) NULL_STR, (LPSTR) portData, sizeof(portData));
  199. switch(sscanf(portData, "COM%d:%d,%c,%d,%d", &nPort, &nSpeed, str, &nData, &nStop))
  200. {
  201. case 5:
  202. if(nStop == 2)
  203. trmParams.stopBits = ITMSTOP2;
  204. /* then fall thru... */
  205. case 4:
  206. if((nData >= 4) && (nData < 8))
  207. trmParams.dataBits = ITMDATA8 - (8 - nData);
  208. /* then fall thru... */
  209. case 3:
  210. switch(str[0])
  211. {
  212. case 'o':
  213. trmParams.parity = ITMODDPARITY;
  214. break;
  215. case 'e':
  216. trmParams.parity = ITMEVENPARITY;
  217. break;
  218. case 'm':
  219. trmParams.parity = ITMMARKPARITY;
  220. break;
  221. case 's':
  222. trmParams.parity = ITMSPACEPARITY;
  223. break;
  224. }
  225. /* then fall thru... */
  226. case 2:
  227. if((nSpeed < 150) || (nSpeed == 192))
  228. nSpeed *= 100;
  229. trmParams.speed = (WORD)nSpeed;
  230. /* then fall thru... */
  231. case 1:
  232. if(nPort >= 1)
  233. {
  234. trmParams.newDevRef = ITMWINCOM;
  235. trmParams.comPortRef = ITMCOM1 + (nPort - 1);
  236. trmParams.fResetDevice = TRUE;
  237. }
  238. break;
  239. }
  240. DEBOUT("setCommDefaults: trmParams.comDevRef = %x\n",trmParams.comDevRef);
  241. DEBOUT("setCommDefaults: trmParams.speed = %d\n",trmParams.speed);
  242. DEBOUT("setCommDefaults: trmParams.dataBits = %d\n",trmParams.dataBits);
  243. DEBOUT("setCommDefaults: trmParams.stopBits = %d\n" ,trmParams.stopBits);
  244. DEBOUT("setCommDefaults: trmParams.parity = %d\n",trmParams.parity);
  245. DEBOUT("setCommDefaults: trmParams.newDevRef = %d\n",trmParams.newDevRef);
  246. DEBOUT("setCommDefaults: trmParams.comPortRef = %d\n",trmParams.comPortRef);
  247. DEBOUT("setCommDefaults: trmParams.fResetDevice = %d\n",trmParams.fResetDevice);
  248. }
  249. /*---------------------------------------------------------------------------*/
  250. /* setDefaultFonts() - [mbb] */
  251. /*---------------------------------------------------------------------------*/
  252. VOID setDefaultFonts() /* rkhx 2.00 ... */
  253. {
  254. BYTE szFont[MINRESSTR], szDefFontFace[LF_FACESIZE], szFontFace[LF_FACESIZE];
  255. INT ndx;
  256. WORD fontHeight = 8; /* mbbx 2.00: was 0 */
  257. LoadString(hInst, STR_INI_FONT, (LPSTR) szFont, MINRESSTR);
  258. LoadString(hInst, STR_INI_FONTFACE, (LPSTR) szDefFontFace, LF_FACESIZE);
  259. GetProfileString((LPSTR) szAppName_private, (LPSTR) szFont, (LPSTR) szDefFontFace,
  260. (LPSTR) szFontFace, LF_FACESIZE);
  261. for(ndx = 0; szFontFace[ndx] != 0; ndx += 1)
  262. {
  263. if(szFontFace[ndx] == ',')
  264. {
  265. sscanf(szFontFace+(ndx+1), "%d", &fontHeight);
  266. szFontFace[ndx] = 0;
  267. break;
  268. }
  269. }
  270. strcpy(trmParams.fontFace, szFontFace); /* mbbx 2.00: font selection... */
  271. trmParams.fontSize = fontHeight;
  272. buildTermFont();
  273. }
  274. /*---------------------------------------------------------------------------*/
  275. /* getDefCountry() - [mbb] */
  276. /*---------------------------------------------------------------------------*/
  277. /* MS-DOS 3.0 COUNTRY command: */
  278. #define CC_USA 1
  279. #define CC_UK 44
  280. #define CC_DENMARK 45
  281. #define CC_NORWAY 47
  282. #define CC_FINLAND 358
  283. #define CC_FRANCE 33
  284. /* NOTE: CANADA not defined */
  285. #define CC_GERMANY 49
  286. #define CC_ITALY 39
  287. #define CC_SPAIN 34
  288. #define CC_SWEDEN 46
  289. #define CC_SWITZERLAND 41
  290. WORD getDefCountry() /* mbbx 1.04: ics... */
  291. {
  292. ICS_TYPE icsType;
  293. BYTE szIntl[MINRESSTR];
  294. BYTE szCountry[MINRESSTR];
  295. LoadString(hInst, STR_INI_INTL, (LPSTR) szIntl, MINRESSTR);
  296. LoadString(hInst, STR_INI_ICOUNTRY, (LPSTR) szCountry, MINRESSTR);
  297. switch(GetProfileInt((LPSTR) szIntl, (LPSTR) szCountry, 0))
  298. {
  299. case CC_UK:
  300. icsType = ICS_BRITISH;
  301. break;
  302. case CC_DENMARK:
  303. case CC_NORWAY:
  304. icsType = ICS_DANISH;
  305. break;
  306. case CC_FINLAND:
  307. icsType = ICS_FINISH;
  308. break;
  309. case CC_FRANCE:
  310. icsType = ICS_FRENCH;
  311. break;
  312. case CC_GERMANY:
  313. icsType = ICS_GERMAN;
  314. break;
  315. case CC_ITALY:
  316. icsType = ICS_ITALIAN;
  317. break;
  318. case CC_SPAIN:
  319. icsType = ICS_SPANISH;
  320. break;
  321. case CC_SWEDEN:
  322. icsType = ICS_SWEDISH;
  323. break;
  324. case CC_SWITZERLAND:
  325. icsType = ICS_SWISS;
  326. break;
  327. default:
  328. icsType = ICS_NONE;
  329. break;
  330. }
  331. return((WORD) icsType);
  332. }
  333. /*---------------------------------------------------------------------------*/
  334. /* icsResetTable() - [mbb] */
  335. /*---------------------------------------------------------------------------*/
  336. #define ICS_RESBYTES 12
  337. VOID icsResetTable(WORD icsType)
  338. {
  339. BYTE ndx;
  340. BYTE work1[ICS_RESBYTES+1], work2[ICS_RESBYTES+1];
  341. trmParams.language = (BYTE) ICS_NONE;
  342. for(ndx = 0; ndx < 256; ndx += 1)
  343. icsXlateTable[ndx] = ndx;
  344. if((icsType > ICS_NONE) && (icsType < ICS_MAXTYPE))
  345. {
  346. if((LoadString(hInst, STR_ICS_DATA, (LPSTR) work1, ICS_RESBYTES+1) == ICS_RESBYTES) &&
  347. (LoadString(hInst, STR_ICS_DATA + icsType, (LPSTR) work2, ICS_RESBYTES+1) == ICS_RESBYTES))
  348. {
  349. for(ndx = 0; ndx < ICS_RESBYTES; ndx += 1)
  350. {
  351. icsXlateTable[work1[ndx]] = work2[ndx];
  352. icsXlateTable[work2[ndx]] = work1[ndx];
  353. }
  354. trmParams.language = icsType;
  355. }
  356. }
  357. }
  358. /*---------------------------------------------------------------------------*/
  359. /* setDefaults() - [scf] */
  360. /*---------------------------------------------------------------------------*/
  361. #define DEFBUFFERLINES 100
  362. VOID setDefaults()
  363. {
  364. BYTE str[80];
  365. INT ndx;
  366. memset(&trmParams, 0, sizeof(recTrmParams)); /* mbbx 1.00: default to NULL */
  367. trmParams.fileID = DCS_FILE_ID; /* mbbx 2.00 ... */
  368. LoadString(hInst, STR_VERSION, (LPSTR) trmParams.version, DCS_VERSIONSZ);
  369. trmParams.controlZ = CNTRLZ;
  370. trmParams.fileSize = sizeof(recTrmParams);
  371. setCommDefaults(); /* mbbx 2.01.17 ... */
  372. trmParams.fParity = FALSE; /* mbbx 1.10: CUA */
  373. trmParams.flowControl = ITMXONFLOW;
  374. trmParams.fCarrier = FALSE; /* mbbx 1.10: CUA */
  375. /* Terminal: */
  376. trmParams.emulate = ITMVT100; /* mbbx 1.04: was ITMTTY; */
  377. trmParams.fCtrlBits = FALSE; /* mbbx 1.10: VT220 8BIT = TRUE */
  378. LoadString(hInst, STR_ANSWERBACK, (LPSTR) trmParams.answerBack, DCS_ANSWERBACKSZ);
  379. trmParams.lineWrap = TRUE; /* mbbx 1.10: CUA... */
  380. trmParams.localEcho = FALSE;
  381. trmParams.sound = TRUE; /* mbbx 1.04: synch */
  382. trmParams.inpCRLF = FALSE;
  383. trmParams.outCRLF = FALSE;
  384. trmParams.columns = ITM80COL;
  385. trmParams.termCursor = ITMBLKCURSOR;
  386. trmParams.cursorBlink = TRUE;
  387. LoadString(hInst, STR_INI_BUFFER, (LPSTR) str, MINRESSTR);
  388. trmParams.bufferLines = (WORD)GetProfileInt((LPSTR) szAppName_private, (LPSTR) str, DEFBUFFERLINES);
  389. maxChars = 0; /* mbbx 2.00.04 */
  390. DEBOUT("Calling: %s\n","resetTermBuffer()");
  391. resetTermBuffer();
  392. DEBOUT("Outof: %s\n","resetTermBuffer()");
  393. DEBOUT("Calling: %s\n","setDefaultFonts()");
  394. setDefaultFonts();
  395. DEBOUT("Outof: %s\n","setDefaultFonts()");
  396. DEBOUT("Calling: %s\n","icsResetTable()");
  397. icsResetTable(getDefCountry()); /* mbbx 1.04: ics */
  398. DEBOUT("Outof: %s\n","icsResetTable()");
  399. trmParams.fHideTermVSB = FALSE;
  400. trmParams.fHideTermHSB = FALSE;
  401. /* trmParams.useWinCtrl = TRUE; rjs msoft */
  402. // -sdj 08 may 92: I am not sure why cntl-c is not xmited
  403. // and used instead for copy-paste. When terminal is used
  404. // as a debug machine, or to connect to mainframe, it is important
  405. // most of the times that the control-c should go out to the other end
  406. // user can turn this other way if he needs to..
  407. // changing default from TRUE to FALSE
  408. trmParams.useWinCtrl = FALSE;
  409. /* Binary Transfers: */
  410. trmParams.xBinType = ITMXMODEM;
  411. trmParams.rcvBlSz = 2000;
  412. trmParams.sendBlSz = 2000;
  413. trmParams.retryCt = 20;
  414. /* Text Transfers: */
  415. trmParams.xTxtType = ITMSTD;
  416. trmParams.xChrType = ITMCHRDELAY;
  417. trmParams.xChrDelay = 1;
  418. trmParams.xLinType = ITMLINDELAY;
  419. trmParams.xLinDelay = 1;
  420. LoadString(hInst, STR_XFERLINESTR, (LPSTR) trmParams.xLinStr, DCS_XLINSTRSZ);
  421. trmParams.xWordWrap = FALSE;
  422. trmParams.xWrapCol = 79; /* mbbx 1.04: revert from 65 */
  423. /* Phone: */
  424. trmParams.dlyRetry = 30; /* mbbx 1.10: CUA */
  425. trmParams.cntRetry = 0;
  426. trmParams.flgRetry = FALSE;
  427. trmParams.flgSignal = FALSE;
  428. /* Modem: */
  429. trmParams.xMdmType = ITMHAYES;
  430. LoadString(hInst, STR_DIALPREFIX, (LPSTR) trmParams.dialPrefix, DCS_MODEMCMDSZ);
  431. LoadString(hInst, STR_DIALSUFFIX, (LPSTR) trmParams.dialSuffix, DCS_MODEMCMDSZ);
  432. LoadString(hInst, STR_HANGPREFIX, (LPSTR) trmParams.hangPrefix, DCS_MODEMCMDSZ);
  433. LoadString(hInst, STR_HANGSUFFIX, (LPSTR) trmParams.hangSuffix, DCS_MODEMCMDSZ);
  434. LoadString(hInst, STR_ANSWER, (LPSTR) trmParams.answer, DCS_MODEMCMDSZ);
  435. LoadString(hInst, STR_ORIGINATE, (LPSTR) trmParams.originate, DCS_MODEMCMDSZ);
  436. /* Environment: */
  437. if(fKeysShown) /* mbbx 2.00: show fkeys... */
  438. trmParams.environmentFlags |= DCS_EVF_FKEYSSHOW;
  439. else
  440. trmParams.environmentFlags &= ~DCS_EVF_FKEYSSHOW;
  441. trmParams.environmentFlags |= DCS_EVF_FKEYSARRANGE;
  442. /* Parent: */
  443. for(ndx = 1; ndx <= 131; ndx++)
  444. if(ndx % 8 == 0)
  445. tabs[ndx] = 1;
  446. else
  447. tabs[ndx] = 0;
  448. answerMode = FALSE;
  449. keyPadAppMode = FALSE;
  450. cursorKeyMode = FALSE;
  451. }
  452. /*---------------------------------------------------------------------------*/
  453. /* resetEmul() - Load the Emulation table from resource. [scf] */
  454. /*---------------------------------------------------------------------------*/
  455. VOID resetEmul() /* mbbx per slc */
  456. {
  457. #ifdef ORGCODE
  458. HANDLE hResInfo, hFile;
  459. TEXTMETRIC fontMetrics;
  460. INT ndx, ndx2;
  461. if((hResInfo = FindResource(hInst, getResId(1000 + (trmParams.emulate - ITMTERMFIRST)), (LPSTR) DC_RES_CCTL)) != NULL) /* mbbx 1.04: REZ */
  462. {
  463. if((hFile = AccessResource(hInst, hResInfo)) != -1)
  464. {
  465. if(_read(hFile, emulInfo, 128) == 128)
  466. {
  467. if(_read(hFile, GlobalLock(hemulKeyInfo), SIZEOFEMULKEYINFO) == SIZEOFEMULKEYINFO)
  468. {
  469. GlobalUnlock(hemulKeyInfo);
  470. if(_read(hFile, vidGraphChars, 128) != 128) /* mbbx 1.10 ... */
  471. trmParams.emulate = -1;
  472. if((trmParams.emulate == ITMVT100) || (trmParams.emulate == ITMVT220))
  473. ansi = TRUE;
  474. else
  475. ansi = FALSE;
  476. }
  477. else /* read for emulKeyInfo failed so unlock it */
  478. {
  479. GlobalUnlock (hemulKeyInfo);
  480. trmParams.emulate = -1;
  481. }
  482. }
  483. else
  484. trmParams.emulate = -1;
  485. _close(hFile);
  486. }
  487. else
  488. trmParams.emulate = -1;
  489. }
  490. else
  491. trmParams.emulate = -1;
  492. #else
  493. HANDLE hFoundRes,hResInfo;
  494. LPSTR lpResData,lpEmulKey;
  495. TEXTMETRIC fontMetrics;
  496. INT ndx, ndx2;
  497. if((hFoundRes = FindResource(hInst, getResId(1000 + (trmParams.emulate - ITMTERMFIRST)), (LPSTR) DC_RES_CCTL)) != NULL) /* mbbx 1.04: REZ */
  498. {
  499. DEBOUT("resetEmul: findresource returns %lx\n",hFoundRes);
  500. /*accessresource no longer in win32, so gotta LoadResource, then lock it, */
  501. /*so I get a pointer to the resource data itself.(JAP)*/
  502. if( (hResInfo = LoadResource(hInst,hFoundRes)) != NULL)
  503. {
  504. DEBOUT("resetEmul: LoadResource returns %lx\n",hResInfo);
  505. if((lpResData = LockResource(hResInfo)) )
  506. {
  507. DEBOUT("resetEmul: LockResource returns %lx\n",lpResData);
  508. memcpy(emulInfo, lpResData, 128);
  509. if ( (lpEmulKey = GlobalLock(hemulKeyInfo)) != NULL )
  510. {
  511. memcpy(lpEmulKey,lpResData+128,SIZEOFEMULKEYINFO);
  512. memcpy(vidGraphChars, lpResData + 128 + SIZEOFEMULKEYINFO, 128);
  513. if((trmParams.emulate == ITMVT100) || (trmParams.emulate == ITMVT220))
  514. {
  515. DEBOUT("resetEmul:%s\n","emulate = VT100|VT52, ansi=true");
  516. ansi = TRUE;
  517. }
  518. else
  519. {
  520. DEBOUT("resetEmul:%s\n","emulate not VT100|VT52, ansi=false");
  521. ansi = FALSE;
  522. }
  523. GlobalUnlock(hemulKeyInfo);
  524. UnlockResource(hResInfo);
  525. }
  526. else /* Globallock failed, so put -1 in .emulate */
  527. {
  528. DEBOUT("resetEmul: %s\n","GlobalLock FAILED");
  529. trmParams.emulate = -1;
  530. UnlockResource(hResInfo);
  531. }
  532. }
  533. else /* LockResource failed, so put -1 in .emulate */
  534. {
  535. DEBOUT("resetEmul: %s\n","LockResource FAILED");
  536. trmParams.emulate = -1;
  537. }
  538. }
  539. else /* LoadResource failed, so put -1 in .emulate */
  540. {
  541. DEBOUT("resetEmul: %s\n","LoadResource FAILED");
  542. trmParams.emulate = -1;
  543. }
  544. }
  545. else
  546. /* FindResource failed, so put -1 in .emulate */
  547. {
  548. DEBOUT("resetEmul: %s\n","FindResource FAILED");
  549. trmParams.emulate = -1;
  550. }
  551. #endif
  552. /*********** now check if .emulate is -1 and do the defaults ***********/
  553. if(trmParams.emulate == (BYTE) -1)
  554. {
  555. LoadString(hInst, STR_LOADEMUL, (LPSTR) taskState.string, 80); /* mbbx 1.04: REZ... */
  556. testMsg(taskState.string,NULL,NULL);
  557. trmParams.emulate = ITMTTY;
  558. escHandler = pNullState;
  559. }
  560. else
  561. {
  562. escHandler = pEscSequence;
  563. getPort();
  564. GetTextMetrics(thePort, (TEXTMETRIC FAR *) &fontMetrics);
  565. releasePort();
  566. if(fontMetrics.tmCharSet == ANSI_CHARSET)
  567. {
  568. for(ndx = 0; ndx < 64; ndx += 1)
  569. {
  570. switch(vidGraphChars[ndx].buffer)
  571. {
  572. case 0x9C:
  573. vidGraphChars[ndx].buffer = 0xA3;
  574. break;
  575. case 0xF1:
  576. vidGraphChars[ndx].buffer = 0xB1;
  577. break;
  578. case 0xF8:
  579. vidGraphChars[ndx].buffer = 0xB0;
  580. break;
  581. case 0xFA:
  582. vidGraphChars[ndx].buffer = 0xB7;
  583. break;
  584. default:
  585. if(vidGraphChars[ndx].buffer > 0x80)
  586. vidGraphChars[ndx].buffer = 0x20;
  587. break;
  588. }
  589. }
  590. }
  591. }
  592. clearModes();
  593. for(ndx2 = 0; ndx2 <= 127; ndx2 += 1)
  594. {
  595. ndx = emulInfo[ndx2];
  596. if(ndx > 128)
  597. ndx = ESCSKIPNDX;
  598. pEscTable[ndx2] = pProcTable[ndx];
  599. if(ansi)
  600. aEscTable[ndx2] = aProcTable[ndx];
  601. }
  602. termState = NULL;
  603. }
  604. /*---------------------------------------------------------------------------*/
  605. /* initTermBuffer() - [mbb] */
  606. /*---------------------------------------------------------------------------*/
  607. /* mbbx 2.00.03: buffer lines > 399 ... */
  608. /* NOTE: the following routines contain code which assumes the term buffer */
  609. /* will be limited to 64K... This seems like a reasonable limit */
  610. /* since too large a buffer would slow down the emulation! */
  611. /* #define MINBUFFERLINES 25
  612. #define MAXBUFFERSIZE 0xFFFF jtf 3.12 */
  613. #define MINBUFFERLINES (maxScreenLine+2)
  614. #define MAXBUFFERSIZE 0x7FFF /* jtf 3.12 */
  615. #define TERMBUFFERFUDGE 1
  616. BOOL clearTermBuffer(UINT prevLines, UINT bufLines, UINT lineWidth)
  617. {
  618. LPSTR lpBufData;
  619. UINT wPrevSize;
  620. if((lpBufData = GlobalLock(hTE.hText)) == NULL)
  621. return(FALSE);
  622. wPrevSize = prevLines * lineWidth;
  623. lsetmem(lpBufData += wPrevSize, 0x20, (bufLines * lineWidth) - wPrevSize);
  624. while(prevLines < bufLines)
  625. {
  626. lpBufData += lineWidth;
  627. // NOTE: Will AV on RISC if lineWidth is odd
  628. *(((WORD FAR *) lpBufData)-1) = 0x0A0D;
  629. prevLines += 1;
  630. }
  631. *lpBufData = 0; /* NULL terminated, of course */
  632. #ifndef BUGBYPASS
  633. DEBOUT("initTermBuffer: %s\n","GlobalUnlock BUG??? CHECK THIS OUT");
  634. return (TRUE);
  635. #else
  636. GlobalUnlock(hTE.hText);
  637. return (TRUE);
  638. #endif
  639. }
  640. BOOL initTermBuffer(WORD bufLines, WORD lineWidth, BOOL bReset)
  641. {
  642. LONG lBufSize;
  643. LPSTR lpBufData;
  644. HANDLE hNewBuf;
  645. if(bReset && (hTE.hText != NULL))
  646. hTE.hText = GlobalFree(hTE.hText);
  647. if(bufLines < MINBUFFERLINES)
  648. bufLines = MINBUFFERLINES;
  649. if((lBufSize = ((LONG) bufLines * lineWidth) + TERMBUFFERFUDGE) > MAXBUFFERSIZE)
  650. {
  651. bufLines = (MAXBUFFERSIZE - TERMBUFFERFUDGE) / lineWidth;
  652. lBufSize = (bufLines * lineWidth) + TERMBUFFERFUDGE;
  653. }
  654. if(hTE.hText == NULL)
  655. {
  656. GlobalCompact(lBufSize);
  657. if((hTE.hText = GlobalAlloc(GMEM_MOVEABLE, (DWORD) (MINBUFFERLINES * lineWidth) +
  658. TERMBUFFERFUDGE)) == NULL)
  659. {
  660. testResMsg(STR_OUTOFMEMORY);
  661. SendMessage(hItWnd, WM_CLOSE, 0, 0L);
  662. return(FALSE);
  663. }
  664. maxLines = 0;
  665. }
  666. else if(bufLines < savTopLine + (maxScreenLine + 2))
  667. {
  668. lpBufData = GlobalLock(hTE.hText);
  669. lmovmem(lpBufData + ((savTopLine + (maxScreenLine + 2) - bufLines) * lineWidth), lpBufData, lBufSize);
  670. GlobalUnlock(hTE.hText);
  671. if(curTopLine > (savTopLine = bufLines - (maxScreenLine + 2)))
  672. curTopLine = savTopLine;
  673. if(!IsIconic(hItWnd)) /* rjs bugs 015 */
  674. sizeTerm(0L); /* reset scrollbars */
  675. }
  676. while(bufLines > MINBUFFERLINES)
  677. {
  678. if((hNewBuf = GlobalReAlloc(hTE.hText, lBufSize, GMEM_MOVEABLE)) != NULL)
  679. {
  680. hTE.hText = hNewBuf;
  681. break;
  682. }
  683. bufLines -= 1;
  684. lBufSize -= lineWidth;
  685. }
  686. if(bufLines > maxLines)
  687. clearTermBuffer(maxLines, bufLines, lineWidth);
  688. maxLines = bufLines;
  689. return(TRUE);
  690. }
  691. /*---------------------------------------------------------------------------*/
  692. /* resetTermBuffer() - [mbb] */
  693. /*---------------------------------------------------------------------------*/
  694. VOID resetTermBuffer()
  695. {
  696. WORD lineWidth;
  697. BOOL bNewWidth;
  698. lineWidth = (trmParams.columns == ITM80COL) ? 80 : 132;
  699. if((bNewWidth = (lineWidth != maxChars)) || (trmParams.bufferLines != maxLines))
  700. {
  701. maxChars = lineWidth;
  702. initTermBuffer(trmParams.bufferLines, lineWidth + 2, bNewWidth);
  703. if(bNewWidth)
  704. clearBuffer();
  705. }
  706. }