slvideo.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594
  1. /* Copyright (c) 1992, 1995 John E. Davis
  2. * All rights reserved.
  3. *
  4. * You may distribute under the terms of either the GNU General Public
  5. * License or the Perl Artistic License.
  6. */
  7. #include "config.h"
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #ifdef __WIN32__
  12. # include <windows.h>
  13. #endif
  14. #ifdef __GO32__
  15. # undef msdos
  16. #endif
  17. #if defined (msdos)
  18. # include <conio.h>
  19. # include <bios.h>
  20. # include <mem.h>
  21. #endif
  22. #if defined (__WATCOMC__)
  23. # include <graph.h>
  24. # define int86 int386 /* simplify code writing */
  25. #endif
  26. #if defined (__GO32__)
  27. # include <pc.h>
  28. # define GO32_VIDEO
  29. #endif
  30. #if defined (__os2__) && !defined (EMX_VIDEO)
  31. # define INCL_BASE
  32. # define INCL_NOPM
  33. # define INCL_VIO
  34. # define INCL_KBD
  35. # include <os2.h>
  36. #else
  37. # if defined (__EMX__) /* EMX video does both DOS & OS/2 */
  38. # ifndef EMX_VIDEO
  39. # define EMX_VIDEO
  40. # endif
  41. # include <sys/video.h>
  42. # endif
  43. #endif
  44. #include <dos.h>
  45. #include "_slang.h"
  46. #ifdef GO32_VIDEO
  47. # define HAS_SAVE_SCREEN
  48. #endif
  49. /* ------------------------- global variables ------------------------- */
  50. #ifdef WIN32
  51. extern HANDLE hStdout, hStdin;
  52. extern CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  53. #endif
  54. int SLtt_Term_Cannot_Insert;
  55. int SLtt_Term_Cannot_Scroll;
  56. int SLtt_Ignore_Beep = 3;
  57. int SLtt_Use_Ansi_Colors;
  58. int SLtt_Screen_Rows = 25;
  59. int SLtt_Screen_Cols = 80;
  60. /* ------------------------- local variables -------------------------- */
  61. static int Attribute_Byte;
  62. static int Scroll_r1 = 0, Scroll_r2 = 25;
  63. static int Cursor_Row = 1, Cursor_Col = 1;
  64. static int Current_Color;
  65. static int IsColor = 1;
  66. static int Blink_Killed; /* high intensity background enabled */
  67. #define JMAX_COLORS 256
  68. #define JNORMAL_COLOR 0
  69. #define JNO_COLOR -1
  70. static unsigned char Color_Map [JMAX_COLORS] =
  71. {
  72. 0x7, 0x70, 0x70, 0x70, 0x70, 0x7, 0x7, 0x7,
  73. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  74. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  75. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  76. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  77. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  78. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  79. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  80. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  81. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  82. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  83. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  84. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  85. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  86. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  87. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  88. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  89. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  90. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  91. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  92. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  93. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  94. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  95. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  96. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  97. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  98. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  99. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  100. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  101. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  102. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
  103. 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7
  104. };
  105. #define JMAX_COLOR_NAMES 16
  106. static char *Color_Names [JMAX_COLOR_NAMES] =
  107. {
  108. "black", "blue", "green", "cyan",
  109. "red", "magenta", "brown", "lightgray",
  110. "gray", "brightblue", "brightgreen", "brightcyan",
  111. "brightred", "brightmagenta", "yellow", "white"
  112. };
  113. /*
  114. * set_color_from_attribute (int attribute);
  115. * define the correspondence of color to attribute
  116. */
  117. #define set_color_from_attribute(a)\
  118. SLtt_set_color (\
  119. JNORMAL_COLOR, NULL,\
  120. Color_Names[(a) & 0xf],\
  121. Color_Names[(a) >> 4])
  122. /* this is how to make a space character */
  123. #define mkSpaceChar() (((Attribute_Byte) << 8) | 0x20)
  124. /* buffer to hold a line of character/attribute pairs */
  125. #define MAXCOLS 256
  126. static unsigned char Line_Buffer [MAXCOLS*2];
  127. /*----------------------------------------------------------------------*\
  128. * define various ways and means of writing to the screen
  129. \*----------------------------------------------------------------------*/
  130. #if defined (__GO32__) || defined (__WATCOMC__)
  131. # if !defined (GO32_VIDEO)
  132. # define HAS_LINEAR_SCREEN
  133. # endif
  134. #else /* __GO32__ or __WATCOMC__ */
  135. # if defined (msdos)
  136. # define USE_ASM
  137. # endif
  138. #endif /* __GO32__ or __WATCOMC__ */
  139. /* define for direct to memory screen writes */
  140. #if defined (USE_ASM) || defined (HAS_LINEAR_SCREEN)
  141. static unsigned char *Video_Base;
  142. # define mkScreenPointer(row,col) ((unsigned short *)\
  143. (Video_Base +\
  144. 2 * (SLtt_Screen_Cols * (row)\
  145. + (col))))
  146. # if defined (USE_ASM)
  147. int SLtt_Msdos_Cheap_Video = 0;
  148. static int Video_Status_Port;
  149. # define MONO_STATUS 0x3BA
  150. # define CGA_STATUS 0x3DA
  151. # define CGA_SETMODE 0x3D8
  152. # define SNOW_CHECK \
  153. if (SLtt_Msdos_Cheap_Video)\
  154. { while ((inp (CGA_STATUS) & 0x08)); while (!(inp (CGA_STATUS) & 0x08)); }
  155. # endif /* USE_ASM */
  156. #endif /* USE_ASM or HAS_LINEAR_SCREEN */
  157. /* -------------------------------------------------------------------- */
  158. #if defined (__WATCOMC__)
  159. # define ScreenPrimary (0xb800 << 4)
  160. # define ScreenSize (SLtt_Screen_Cols * SLtt_Screen_Rows)
  161. # define ScreenSetCursor (x,y) _settextposition (x+1,y+1)
  162. void ScreenGetCursor (int *x, int *y)
  163. {
  164. struct rccoord rc = _gettextposition ();
  165. *x = rc.row - 1;
  166. *y = rc.col - 1;
  167. }
  168. void ScreenRetrieve (unsigned char *dest)
  169. {
  170. memcpy (dest, (unsigned char *) ScreenPrimary, 2 * ScreenSize);
  171. }
  172. void ScreenUpdate (unsigned char *src)
  173. {
  174. memcpy ((unsigned char *) ScreenPrimary, src, 2 * ScreenSize);
  175. }
  176. #endif /* __WATCOMC__ */
  177. #ifdef HAS_SAVE_SCREEN
  178. static void *Saved_Screen_Buffer;
  179. static int Saved_Cursor_Row;
  180. static void save_screen (void)
  181. {
  182. int row, col;
  183. if (Saved_Screen_Buffer != NULL)
  184. {
  185. SLFREE (Saved_Screen_Buffer);
  186. Saved_Screen_Buffer = NULL;
  187. }
  188. #ifdef GO32_VIDEO
  189. Saved_Screen_Buffer = SLMALLOC (sizeof (short) *
  190. ScreenCols () * ScreenRows ());
  191. if (Saved_Screen_Buffer == NULL)
  192. return;
  193. ScreenRetrieve (Saved_Screen_Buffer);
  194. ScreenGetCursor (&row, &col);
  195. Saved_Cursor_Row = row;
  196. #endif
  197. }
  198. static void restore_screen (void)
  199. {
  200. if (Saved_Screen_Buffer == NULL) return;
  201. #ifdef GO32_VIDEO
  202. ScreenUpdate (Saved_Screen_Buffer);
  203. SLtt_goto_rc (Saved_Cursor_Row, 0);
  204. #endif
  205. }
  206. #endif /* HAS_SAVE_SCREEN */
  207. /*----------------------------------------------------------------------*\
  208. * Function: void SLtt_write_string (char *str);
  209. *
  210. * put string STR to 'stdout'
  211. \*----------------------------------------------------------------------*/
  212. void SLtt_write_string (char *str)
  213. {
  214. #ifdef WIN32
  215. int bytes;
  216. (void) WriteConsole(hStdout, str, strlen(str), &bytes, NULL);
  217. #else
  218. fputs (str, stdout);
  219. #endif
  220. }
  221. /*----------------------------------------------------------------------*\
  222. * Function: void SLtt_set_scroll_region (int r1, int r2);
  223. *
  224. * define a scroll region of top_row to bottom_row
  225. \*----------------------------------------------------------------------*/
  226. void SLtt_set_scroll_region (int top_row, int bottom_row)
  227. {
  228. Scroll_r1 = top_row;
  229. Scroll_r2 = bottom_row;
  230. }
  231. /*----------------------------------------------------------------------*\
  232. * Function: void SLtt_reset_scroll_region (void);
  233. *
  234. * reset the scrol region to be the entire screen,
  235. * ie, SLtt_set_scroll_region (0, SLtt_Screen_Rows);
  236. \*----------------------------------------------------------------------*/
  237. void SLtt_reset_scroll_region (void)
  238. {
  239. Scroll_r1 = 0;
  240. Scroll_r2 = SLtt_Screen_Rows;
  241. }
  242. /*----------------------------------------------------------------------*\
  243. * Function: void SLtt_goto_rc (int row, int col);
  244. *
  245. * move the terminal cursor to x,y position COL, ROW and record the
  246. * position in Cursor_Row, Cursor_Col
  247. \*----------------------------------------------------------------------*/
  248. void SLtt_goto_rc (int row, int col)
  249. {
  250. #ifdef WIN32
  251. COORD newPosition;
  252. newPosition.X = col;
  253. newPosition.Y = row;
  254. #endif
  255. #if !defined (USE_ASM)
  256. if (row > SLtt_Screen_Rows) row = SLtt_Screen_Rows;
  257. if (col > SLtt_Screen_Cols) col = SLtt_Screen_Cols;
  258. # if defined (EMX_VIDEO)
  259. v_gotoxy (col, Scroll_r1 + row);
  260. # else /* EMX_VIDEO_ */
  261. # if defined (__os2__)
  262. VioSetCurPos (Scroll_r1 + row, col, 0);
  263. # elif defined(WIN32)
  264. (void) SetConsoleCursorPosition(hStdout, newPosition);
  265. # else /* __os2__ */
  266. # if defined (__GO32__) || defined (__WATCOMC__)
  267. ScreenSetCursor(Scroll_r1 + row, col);
  268. # endif /* __GO32__ or __WATCOMC__ */
  269. # endif /* __os2__ */
  270. # endif /* EMX_VIDEO_ */
  271. Cursor_Row = row;
  272. Cursor_Col = col;
  273. #else /* USE_ASM */
  274. /* if (r > SLtt_Screen_Rows - 1) r = SLtt_Screen_Rows - 1; */
  275. asm mov ax, row
  276. asm mov bx, SLtt_Screen_Rows
  277. asm dec bx
  278. asm cmp ax, bx
  279. asm jle L1
  280. asm mov ax, bx
  281. L1:
  282. /* if (c > SLtt_Screen_Cols - 1) c = SLtt_Screen_Cols - 1; */
  283. asm mov cx, SLtt_Screen_Cols
  284. asm dec cx
  285. asm mov bx, col
  286. asm cmp bx, cx
  287. asm jle L2
  288. asm mov bx, cx
  289. L2:
  290. asm mov Cursor_Row, ax
  291. asm mov Cursor_Col, bx
  292. asm add ax, Scroll_r1
  293. asm xor dx, dx
  294. asm mov dh, al
  295. asm mov dl, bl
  296. asm xor bx, bx
  297. asm mov ax, 0x200
  298. asm int 0x10
  299. #endif /* USE_ASM */
  300. }
  301. /*----------------------------------------------------------------------*\
  302. * Function: static void slvid_getxy (void);
  303. *
  304. * retrieve the cursor position into Cursor_Row, Cursor_Col
  305. \*----------------------------------------------------------------------*/
  306. static void slvid_getxy (void)
  307. {
  308. #if !defined (USE_ASM)
  309. # if defined (EMX_VIDEO)
  310. v_getxy (&Cursor_Col, &Cursor_Row);
  311. # else /* EMX_VIDEO */
  312. # if defined (__os2__)
  313. VioGetCurPos ((USHORT*) &Cursor_Row, (USHORT*) &Cursor_Col, 0);
  314. # elif defined(WIN32)
  315. CONSOLE_SCREEN_BUFFER_INFO screenInfo;
  316. if (GetConsoleScreenBufferInfo(hStdout, &screenInfo) == TRUE)
  317. {
  318. Cursor_Row = screenInfo.dwCursorPosition.Y;
  319. Cursor_Col = screenInfo.dwCursorPosition.X;
  320. }
  321. # else /* __os2__ */
  322. # if defined (__GO32__) || defined (__WATCOMC__)
  323. ScreenGetCursor (&Cursor_Row, &Cursor_Col);
  324. # endif /* __GO32__ or __WATCOMC__ */
  325. # endif /* __os2__ */
  326. # endif /* EMX_VIDEO */
  327. #else /* USE_ASM */
  328. asm mov ah, 3
  329. asm mov bh, 0
  330. asm int 10h
  331. asm xor ax, ax
  332. asm mov al, dh
  333. asm mov Cursor_Row, ax
  334. asm xor ax, ax
  335. asm mov al, dl
  336. asm mov Cursor_Col, ax
  337. #endif /* USE_ASM */
  338. }
  339. /*----------------------------------------------------------------------*\
  340. * static void slvid_deleol (int x);
  341. *
  342. * write space characters from column X of row Cursor_Row through to
  343. * SLtt_Screen_Cols using the current Attribute_Byte
  344. \*----------------------------------------------------------------------*/
  345. #if defined (GO32_VIDEO)
  346. static void slvid_deleol (int x)
  347. {
  348. while (x < SLtt_Screen_Cols)
  349. ScreenPutChar (32, Attribute_Byte, x++, Cursor_Row);
  350. }
  351. #endif
  352. #if defined (EMX_VIDEO)
  353. static void slvid_deleol (int x)
  354. {
  355. unsigned char *p, *pmax;
  356. int w = mkSpaceChar ();
  357. int count = SLtt_Screen_Cols - x;
  358. p = Line_Buffer;
  359. pmax = p + 2 * count;
  360. while (p < pmax)
  361. {
  362. *p++ = (unsigned char) w;
  363. *p++ = (unsigned char) (w >> 8);
  364. }
  365. v_putline (Line_Buffer, x, Cursor_Row, count);
  366. }
  367. #endif /* EMX_VIDEO */
  368. /*----------------------------------------------------------------------*\
  369. * Function: void SLtt_begin_insert (void);
  370. *
  371. * insert a single space, moving everything right 1 character to make room
  372. \*----------------------------------------------------------------------*/
  373. void SLtt_begin_insert (void)
  374. {
  375. #if !defined (GO32_VIDEO)
  376. # if defined (HAS_LINEAR_SCREEN) || defined (USE_ASM)
  377. unsigned short *p;
  378. # if defined (HAS_LINEAR_SCREEN)
  379. unsigned short *pmin;
  380. # endif
  381. # endif
  382. int n;
  383. slvid_getxy ();
  384. n = SLtt_Screen_Cols - Cursor_Col;
  385. /* Msdos_Insert_Mode = 1; */
  386. # ifndef WIN32
  387. # if defined (EMX_VIDEO)
  388. v_getline (Line_Buffer, Cursor_Col, Cursor_Row, n);
  389. v_putline (Line_Buffer, Cursor_Col+1, Cursor_Row, n - 1);
  390. # else /* EMX_VIDEO */
  391. # if defined (__os2__)
  392. n = 2 * (n - 1);
  393. VioReadCellStr ((PCH)Line_Buffer, (USHORT*) &n, Cursor_Row, Cursor_Col, 0);
  394. VioWrtCellStr ((PCH)Line_Buffer, n, Cursor_Row, Cursor_Col + 1, 0);
  395. # else /* __os2__ */
  396. p = mkScreenPointer (Cursor_Row, SLtt_Screen_Cols - 1);
  397. # if defined (HAS_LINEAR_SCREEN)
  398. /* pmin = p - (n-1); */
  399. pmin = mkScreenPointer (Cursor_Row, Cursor_Col);
  400. while (p-- > pmin) *(p + 1) = *p;
  401. # else
  402. SNOW_CHECK;
  403. asm mov ax, ds
  404. asm mov bx, di
  405. asm mov dx, si
  406. asm mov cx, n
  407. asm les di, p
  408. asm lds si, p
  409. asm sub si, 2
  410. asm std
  411. asm rep movsw
  412. asm mov ds, ax
  413. asm mov di, bx
  414. asm mov si, dx
  415. # endif /* HAS_LINEAR_SCREEN */
  416. # endif /* __os2__ */
  417. # endif /* EMX_VIDEO */
  418. # endif /* WIN32 */
  419. #endif /* not GO32_VIDEO */
  420. }
  421. /*----------------------------------------------------------------------*\
  422. * Function: void SLtt_end_insert (void);
  423. *
  424. * any cleanup after insert a blank column
  425. \*----------------------------------------------------------------------*/
  426. void SLtt_end_insert (void)
  427. {
  428. }
  429. /*----------------------------------------------------------------------*\
  430. * Function: void SLtt_delete_char (void);
  431. *
  432. * delete a single character, moving everything left 1 column to take
  433. * up the room
  434. \*----------------------------------------------------------------------*/
  435. void SLtt_delete_char (void)
  436. {
  437. #if !defined (GO32_VIDEO)
  438. # if defined (HAS_LINEAR_SCREEN) || defined (USE_ASM)
  439. unsigned short *p;
  440. # if defined (HAS_LINEAR_SCREEN)
  441. register unsigned short *p1;
  442. # endif
  443. # endif
  444. int n;
  445. slvid_getxy ();
  446. n = SLtt_Screen_Cols - Cursor_Col - 1;
  447. # ifndef WIN32
  448. # if defined (EMX_VIDEO)
  449. v_getline (Line_Buffer, Cursor_Col+1, Cursor_Row, n);
  450. v_putline (Line_Buffer, Cursor_Col, Cursor_Row, n);
  451. # else /* EMX_VIDEO */
  452. # if defined (__os2__)
  453. n *= 2;
  454. VioReadCellStr ((PCH)Line_Buffer, (USHORT*)&n, Cursor_Row, Cursor_Col + 1, 0);
  455. VioWrtCellStr ((PCH)Line_Buffer, n, Cursor_Row, Cursor_Col, 0);
  456. return;
  457. # else /* __os2__ */
  458. p = mkScreenPointer (Cursor_Row, Cursor_Col);
  459. # if defined (HAS_LINEAR_SCREEN)
  460. while (n--)
  461. {
  462. p1 = p + 1;
  463. *p = *p1;
  464. p++;
  465. }
  466. # else /* HAS_LINEAR_SCREEN */
  467. SNOW_CHECK;
  468. asm mov ax, ds
  469. asm mov bx, si
  470. asm mov dx, di
  471. asm mov cx, n
  472. asm les di, p
  473. asm lds si, p
  474. asm add si, 2
  475. asm cld
  476. asm rep movsw
  477. asm mov ds, ax
  478. asm mov si, bx
  479. asm mov di, dx
  480. # endif /* HAS_LINEAR_SCREEN */
  481. # endif /* __os2__ */
  482. # endif /* EMX_VIDEO */
  483. # endif /* WIN32 */
  484. #endif /* not GO32_VIDEO */
  485. }
  486. /*----------------------------------------------------------------------*\
  487. * Function: void SLtt_erase_line (void);
  488. *
  489. * This function is *only* called on exit.
  490. * It sets attribute byte to Black & White
  491. \*----------------------------------------------------------------------*/
  492. void SLtt_erase_line (void)
  493. {
  494. #ifndef WIN32
  495. # if defined (GO32_VIDEO) || defined (EMX_VIDEO)
  496. Attribute_Byte = 0x07;
  497. slvid_deleol (0);
  498. # else /* GO32_VIDEO or EMX_VIDEO */
  499. # if defined (__os2__)
  500. USHORT w;
  501. Attribute_Byte = 0x07;
  502. w = mkSpaceChar ();
  503. VioWrtNCell ((BYTE*)&w, SLtt_Screen_Cols, Cursor_Row, 0, 0);
  504. # else /* __os2__ */
  505. unsigned short w;
  506. unsigned short *p = mkScreenPointer (Cursor_Row, 0);
  507. # if defined (HAS_LINEAR_SCREEN)
  508. register unsigned short *pmax = p + SLtt_Screen_Cols;
  509. Attribute_Byte = 0x07;
  510. w = mkSpaceChar ();
  511. while (p < pmax) *p++ = w;
  512. # else /* HAS_LINEAR_SCREEN */
  513. Attribute_Byte = 0x07;
  514. w = mkSpaceChar ();
  515. SNOW_CHECK;
  516. asm mov dx, di
  517. asm mov ax, w
  518. asm mov cx, SLtt_Screen_Cols
  519. asm les di, p
  520. asm cld
  521. asm rep stosw
  522. asm mov di, dx
  523. # endif /* HAS_LINEAR_SCREEN */
  524. # endif /* __os2__ */
  525. # endif /* GO32_VIDEO or EMX_VIDEO */
  526. Current_Color = JNO_COLOR; /* since we messed with attribute byte */
  527. #endif /* WIN32 */
  528. }
  529. /*----------------------------------------------------------------------*\
  530. * Function: void SLtt_delete_nlines (int nlines);
  531. *
  532. * delete NLINES by scrolling up the region <Scroll_r1, Scroll_r2>
  533. \*----------------------------------------------------------------------*/
  534. void SLtt_delete_nlines (int nlines)
  535. {
  536. SLtt_normal_video ();
  537. #ifndef WIN32
  538. # if defined (EMX_VIDEO)
  539. v_attrib (Attribute_Byte);
  540. v_scroll (0, Scroll_r1, SLtt_Screen_Cols-1, Scroll_r2, nlines, V_SCROLL_UP);
  541. # else /* EMX_VIDEO */
  542. # if defined (__os2__)
  543. {
  544. Line_Buffer[0] = ' '; Line_Buffer[1] = Attribute_Byte;
  545. VioScrollUp (Scroll_r1, 0, Scroll_r2, SLtt_Screen_Cols-1,
  546. nlines, (PCH) Line_Buffer, 0);
  547. }
  548. # else /* __os2__ */
  549. # if defined (USE_ASM)
  550. /* This has the effect of pulling all lines below it up */
  551. asm mov ax, nlines
  552. asm mov ah, 6 /* int 6h */
  553. asm xor cx, cx
  554. asm mov ch, byte ptr Scroll_r1
  555. asm mov dx, SLtt_Screen_Cols
  556. asm dec dx
  557. asm mov dh, byte ptr Scroll_r2
  558. asm mov bh, byte ptr Attribute_Byte
  559. asm int 10h
  560. # else /* USE_ASM */
  561. {
  562. union REGS r;
  563. # if defined (__WATCOMC__)
  564. r.x.eax = nlines;
  565. r.x.ecx = 0;
  566. # else
  567. r.x.ax = nlines;
  568. r.x.cx = 0;
  569. # endif
  570. r.h.ah = 6;
  571. r.h.ch = Scroll_r1;
  572. r.h.dl = SLtt_Screen_Cols - 1;
  573. r.h.dh = Scroll_r2;
  574. r.h.bh = Attribute_Byte;
  575. int86 (0x10, &r, &r);
  576. }
  577. # endif /* USE_ASM */
  578. # endif /* __os2__ */
  579. # endif /* EMX_VIDEO */
  580. #endif /* WIN32 */
  581. }
  582. /*----------------------------------------------------------------------*\
  583. * Function: void SLtt_reverse_index (int nlines);
  584. *
  585. * scroll down the region <Scroll_r1, Scroll_r2> by NLINES
  586. \*----------------------------------------------------------------------*/
  587. void SLtt_reverse_index (int nlines)
  588. {
  589. SLtt_normal_video ();
  590. #ifndef WIN32
  591. # if defined (EMX_VIDEO)
  592. v_attrib (Attribute_Byte);
  593. v_scroll (0, Scroll_r1, SLtt_Screen_Cols-1, Scroll_r2, nlines,
  594. V_SCROLL_DOWN);
  595. # else /* EMX_VIDEO */
  596. # if defined (__os2__)
  597. {
  598. Line_Buffer[0] = ' '; Line_Buffer[1] = Attribute_Byte;
  599. VioScrollDn (Scroll_r1, 0, Scroll_r2, SLtt_Screen_Cols-1,
  600. nlines, (PCH) Line_Buffer, 0);
  601. }
  602. # else /* __os2__ */
  603. # if defined (USE_ASM)
  604. asm xor cx, cx
  605. asm mov ch, byte ptr Scroll_r1
  606. asm mov dx, SLtt_Screen_Cols
  607. asm dec dx
  608. asm mov dh, byte ptr Scroll_r2
  609. asm mov bh, byte ptr Attribute_Byte
  610. asm mov ah, 7
  611. asm mov al, byte ptr nlines
  612. asm int 10h
  613. # else /* USE_ASM */
  614. {
  615. union REGS r;
  616. r.h.al = nlines;
  617. # if defined (__WATCOMC__)
  618. r.x.ecx = 0;
  619. # else
  620. r.x.cx = 0;
  621. # endif
  622. r.h.ah = 7;
  623. r.h.ch = Scroll_r1;
  624. r.h.dl = SLtt_Screen_Cols - 1;
  625. r.h.dh = Scroll_r2;
  626. r.h.bh = Attribute_Byte;
  627. int86 (0x10, &r, &r);
  628. }
  629. # endif /* USE_ASM */
  630. # endif /* __os2__ */
  631. # endif /* EMX_VIDEO */
  632. #endif /* WIN32 */
  633. }
  634. /*----------------------------------------------------------------------*\
  635. * Function: static void slvid_invert_region (int top_row, int bot_row);
  636. *
  637. * invert the display in the region, top_row <= row < bot_row
  638. \*----------------------------------------------------------------------*/
  639. static void slvid_invert_region (int top_row, int bot_row)
  640. {
  641. #ifndef WIN32
  642. # if defined (EMX_VIDEO)
  643. int row, col;
  644. for (row = top_row; row < bot_row; row++)
  645. {
  646. v_getline (Line_Buffer, 0, row, SLtt_Screen_Cols);
  647. for (col = 1; col < SLtt_Screen_Cols * 2; col += 2)
  648. Line_Buffer [col] ^= 0xff;
  649. v_putline (Line_Buffer, 0, row, SLtt_Screen_Cols);
  650. }
  651. # else /* EMX_VIDEO */
  652. # ifdef __os2__
  653. int row, col;
  654. USHORT length = SLtt_Screen_Cols * 2;
  655. for (row = top_row; row < bot_row; row++)
  656. {
  657. VioReadCellStr ((PCH)Line_Buffer, &length, row, 0, 0);
  658. for (col = 1; col < length; col += 2)
  659. Line_Buffer [col] ^= 0xff;
  660. VioWrtCellStr ((PCH)Line_Buffer, length, row, 0, 0);
  661. }
  662. # else /* __os2__ */
  663. # if defined (__GO32__) || defined (__WATCOMC__)
  664. unsigned char buf [2 * 180 * 80]; /* 180 cols x 80 rows */
  665. unsigned char *b, *bmax;
  666. b = buf + 1 + 2 * SLtt_Screen_Cols * top_row;
  667. bmax = buf + 1 + 2 * SLtt_Screen_Cols * bot_row;
  668. ScreenRetrieve (buf);
  669. while (b < bmax)
  670. {
  671. *b ^= 0xFF;
  672. b += 2;
  673. }
  674. ScreenUpdate (buf);
  675. # else /* __GO32__ or __WATCOMC__ */
  676. register unsigned short ch, sh;
  677. register unsigned short *pmin = mkScreenPointer (top_row, 0);
  678. register unsigned short *pmax = mkScreenPointer (bot_row, 0);
  679. while (pmin < pmax)
  680. {
  681. sh = *pmin;
  682. ch = sh;
  683. ch = ch ^ 0xFF00;
  684. *pmin = (ch & 0xFF00) | (sh & 0x00FF);
  685. pmin++;
  686. }
  687. # endif /* __GO32__ or __WATCOMC__ */
  688. # endif /* __os2__ */
  689. # endif /* EMX_VIDEO */
  690. #endif /* WIN32 */
  691. }
  692. /*----------------------------------------------------------------------*\
  693. * Function: void SLtt_beep (void);
  694. *
  695. * signal error by a "bell" condition, the type of signal is governed
  696. * by the value of SLtt_Ignore_Beep:
  697. *
  698. * 0 silent bell
  699. * 1 audible bell
  700. * 2 visual bell
  701. * 4 special visual bell (only flash the bottom status line)
  702. *
  703. * these may be combined:
  704. * eg, 3 = audible visual bell.
  705. * but if both the visual bell and the "special" visual bell are specified,
  706. * only the special bell is used.
  707. \*----------------------------------------------------------------------*/
  708. void SLtt_beep (void)
  709. {
  710. int audible; /* audible bell */
  711. int special = 0; /* first row to invert */
  712. int visual = 0; /* final row to invert */
  713. if (!SLtt_Ignore_Beep) return;
  714. audible = (SLtt_Ignore_Beep & 1);
  715. if ( (SLtt_Ignore_Beep & 4) )
  716. {
  717. special = SLtt_Screen_Rows - 1;
  718. visual = special--; /* only invert bottom status line */
  719. }
  720. else if ( (SLtt_Ignore_Beep & 2) )
  721. {
  722. visual = SLtt_Screen_Rows;
  723. }
  724. if (visual) slvid_invert_region (special, visual);
  725. #if defined (EMX_VIDEO)
  726. if (audible) /*sound (1500)*/; _sleep2 (100); if (audible) /* nosound () */;
  727. #else
  728. # ifdef __os2__
  729. if (audible) DosBeep (1500, 100); else DosSleep (100);
  730. # elif defined(WIN32)
  731. # else
  732. if (audible) sound (1500); delay (100); if (audible) nosound ();
  733. # endif
  734. #endif
  735. if (visual) slvid_invert_region (special, visual);
  736. }
  737. /*----------------------------------------------------------------------*\
  738. * Function: void SLtt_del_eol (void);
  739. *
  740. * delete from the current cursor position to the end of the row
  741. \*----------------------------------------------------------------------*/
  742. void SLtt_del_eol (void)
  743. {
  744. #ifndef WIN32
  745. # if defined (GO32_VIDEO) || defined (EMX_VIDEO)
  746. if (Current_Color != JNO_COLOR) SLtt_normal_video ();
  747. slvid_deleol (Cursor_Col);
  748. # else /* GO32_VIDEO or EMX_VIDEO */
  749. # ifdef __os2__
  750. USHORT w;
  751. if (Current_Color != JNO_COLOR) SLtt_normal_video ();
  752. w = mkSpaceChar ();
  753. VioWrtNCell ((BYTE*)&w, (SLtt_Screen_Cols - Cursor_Col),
  754. Cursor_Row, Cursor_Col, 0);
  755. # else /* __os2__ */
  756. unsigned short *p = mkScreenPointer (Cursor_Row, Cursor_Col);
  757. int n = SLtt_Screen_Cols - Cursor_Col;
  758. unsigned short w;
  759. # if defined (HAS_LINEAR_SCREEN)
  760. unsigned short *pmax = p + n;
  761. if (Current_Color != JNO_COLOR) SLtt_normal_video ();
  762. w = mkSpaceChar ();
  763. while (p < pmax) *p++ = w;
  764. # else /* HAS_LINEAR_SCREEN */
  765. if (Current_Color != JNO_COLOR) SLtt_normal_video ();
  766. w = mkSpaceChar ();
  767. SNOW_CHECK;
  768. asm mov dx, di
  769. asm les di, p
  770. asm mov ax, w
  771. asm mov cx, n
  772. asm cld
  773. asm rep stosw
  774. asm mov di, dx
  775. # endif /* HAS_LINEAR_SCREEN */
  776. # endif /* __os2__ */
  777. # endif /* GO32_VIDEO or EMX_VIDEO */
  778. #endif /* WIN32 */
  779. }
  780. /*----------------------------------------------------------------------*\
  781. * Function: void SLtt_reverse_video (int color);
  782. *
  783. * set Attribute_Byte corresponding to COLOR.
  784. * Use Current_Color to remember the color which was set.
  785. * convert from the COLOR number to the attribute value.
  786. \*----------------------------------------------------------------------*/
  787. void SLtt_reverse_video (int color)
  788. {
  789. Attribute_Byte = Color_Map [color];
  790. Current_Color = color;
  791. }
  792. /*----------------------------------------------------------------------*\
  793. * Function: void SLtt_normal_video (void);
  794. *
  795. * reset the attributes for normal video
  796. \*----------------------------------------------------------------------*/
  797. void SLtt_normal_video (void)
  798. {
  799. SLtt_reverse_video (JNORMAL_COLOR);
  800. }
  801. #if defined (USE_ASM)
  802. /*----------------------------------------------------------------------*\
  803. * Function: static unsigned short *video_write (register unsigned char *pp,
  804. * register unsigned char *p,
  805. * register unsigned short *pos)
  806. *
  807. * write out (P - PP) characters from the array pointed to by PP
  808. * at position (POS, Cursor_Row) in the current Attribute_Byte
  809. *
  810. * increment POS to reflect the number of characters sent and
  811. * return the it as a pointer
  812. \*----------------------------------------------------------------------*/
  813. static unsigned short *video_write (register unsigned char *pp,
  814. register unsigned char *p,
  815. register unsigned short *pos)
  816. {
  817. int n = (int) (p - pp); /* num of characters of PP to write */
  818. asm push si
  819. asm push ds
  820. asm push di
  821. /* set up register for BOTH fast and slow */
  822. asm mov bx, SLtt_Msdos_Cheap_Video
  823. /* These are the registers needed for both fast AND slow */
  824. asm mov ah, byte ptr Attribute_Byte
  825. asm mov cx, n
  826. asm lds si, dword ptr pp
  827. asm les di, dword ptr pos
  828. asm cld
  829. asm cmp bx, 0 /* cheap video test */
  830. asm je L_fast
  831. asm mov bx, ax
  832. asm mov dx, CGA_STATUS
  833. asm jg L_slow_blank
  834. /* slow video */
  835. asm cli
  836. /* wait for retrace */
  837. L_slow:
  838. asm in al, dx
  839. asm test al, 1
  840. asm jnz L_slow
  841. L_slow1:
  842. asm in al, dx
  843. asm test al, 1
  844. asm jz L_slow1
  845. /* move a character out */
  846. asm mov ah, bh
  847. asm lodsb
  848. asm stosw
  849. asm loop L_slow
  850. asm sti
  851. asm jmp done
  852. /* -------------- slow video, vertical retace and pump --------------*/
  853. L_slow_blank:
  854. L_slow_blank_loop:
  855. asm in al, dx
  856. asm test al, 8
  857. asm jnz L_slow_blank_loop
  858. L_slow_blank1:
  859. asm in al, dx
  860. asm test al, 8
  861. asm jz L_slow_blank1
  862. /* write line */
  863. asm mov ah, bh
  864. L_slow_blank2:
  865. asm lodsb
  866. asm stosw
  867. asm loop L_slow_blank2
  868. asm jmp done
  869. /*-------------- Fast video --------------*/
  870. L_fast:
  871. asm lodsb
  872. asm stosw
  873. asm loop L_fast
  874. done:
  875. asm pop di
  876. asm pop ds
  877. asm pop si
  878. return (pos + n);
  879. }
  880. #endif /* USE_ASM */
  881. /*----------------------------------------------------------------------*\
  882. * Function: static void write_attributes (unsigned short *src,
  883. * int count);
  884. *
  885. * Copy COUNT character/color pairs from the array pointed to by
  886. * SRC to the screen at position (0,Cursor_Row).
  887. * NB: SRC contains character/color pairs -- the color must be converted to
  888. * an ansi attribute.
  889. *
  890. * Write out
  891. * 1) a combination of string/attributes
  892. * 2) each string of continuous colour
  893. *
  894. * approach 2) is used for assembler output, while 1) is used when a higher
  895. * level API is available or direct to memory writing is possible: emx video
  896. * routines, os/2, go32, watcom.
  897. \*----------------------------------------------------------------------*/
  898. static void write_attributes (unsigned short *src, int count)
  899. {
  900. register unsigned char *p = Line_Buffer;
  901. register unsigned short pair;
  902. #ifdef WIN32
  903. register unsigned char * org_src = src;
  904. COORD coord;
  905. long bytes;
  906. #endif
  907. #if !defined (USE_ASM)
  908. # if defined (HAS_LINEAR_SCREEN)
  909. register unsigned short *pos = mkScreenPointer (Cursor_Row, 0);
  910. # endif
  911. int n = count;
  912. /* write into a character/attribute pair */
  913. while (n-- > 0)
  914. {
  915. pair = *(src++); /* character/color pair */
  916. SLtt_reverse_video (pair >> 8); /* color change */
  917. # if defined (HAS_LINEAR_SCREEN)
  918. *(pos++) = ((unsigned short) Attribute_Byte << 8) | pair & 0xff;
  919. # else
  920. # if defined(EMX_VIDEO) || !defined(WIN32)
  921. *(p++) = pair & 0xff; /* character byte */
  922. *(p++) = Attribute_Byte; /* attribute byte */
  923. # else
  924. /* WIN32 for now... */
  925. *(p++) = pair & 0xff;
  926. # endif
  927. # endif
  928. }
  929. # if !defined (HAS_LINEAR_SCREEN)
  930. # if defined (EMX_VIDEO)
  931. v_putline (Line_Buffer, Cursor_Col, Cursor_Row, count);
  932. # else /* EMX_VIDEO */
  933. # if defined (__os2__)
  934. VioWrtCellStr ((PCH)Line_Buffer, (USHORT)(2 * count),
  935. (USHORT)Cursor_Row, (USHORT)Cursor_Col, 0);
  936. # elif defined(WIN32)
  937. /* do color attributes later */
  938. p = Line_Buffer;
  939. coord.X = Cursor_Col;
  940. coord.Y = Cursor_Row;
  941. WriteConsoleOutputCharacter(hStdout, p, count, coord, &bytes);
  942. /* write color attributes */
  943. p = Line_Buffer;
  944. n = count;
  945. src = org_src; /* restart the src pointer */
  946. /* write into attributes only */
  947. while (n-- > 0)
  948. {
  949. pair = *(src++); /* character/color pair */
  950. SLtt_reverse_video (pair >> 8); /* color change */
  951. *(p++) = Attribute_Byte; /* attribute byte */
  952. *(p++) = 0; /* what's this for? */
  953. }
  954. WriteConsoleOutputAttribute(hStdout, Line_Buffer, count, coord, &bytes);
  955. # else /* __os2__ */
  956. /* ScreenUpdateLine (void *virtual_screen_line, int row); */
  957. p = Line_Buffer;
  958. n = Cursor_Col;
  959. while (count-- > 0)
  960. {
  961. ScreenPutChar ((int)p[0], (int)p[1], n++, Cursor_Row);
  962. p += 2;
  963. }
  964. # endif /* EMX_VIDEO */
  965. # endif /* __os2__ */
  966. # endif /* HAS_LINEAR_SCREEN */
  967. #else /* not USE_ASM */
  968. unsigned char ch, color;
  969. register unsigned short *pos = mkScreenPointer (Cursor_Row, 0);
  970. while (count--)
  971. {
  972. pair = *(src++); /* character/color pair */
  973. ch = pair & 0xff; /* character value */
  974. color = pair >> 8; /* color value */
  975. if (color != Current_Color) /* need a new color */
  976. {
  977. if (p != Line_Buffer)
  978. {
  979. pos = video_write (Line_Buffer, p, pos);
  980. p = Line_Buffer;
  981. }
  982. SLtt_reverse_video (color); /* change color */
  983. }
  984. *(p++) = ch;
  985. }
  986. pos = video_write (Line_Buffer, p, pos);
  987. #endif /* not USE_ASM */
  988. }
  989. /*----------------------------------------------------------------------*\
  990. * Function: void SLtt_smart_puts (unsigned short *new_string,
  991. * unsigned short *old_string,
  992. * int len, int row);
  993. *
  994. * puts NEW_STRING, which has length LEN, at row ROW. NEW_STRING contains
  995. * characters/colors packed in the form value = ((color << 8) | (ch));
  996. *
  997. * the puts tries to avoid overwriting the same characters/colors
  998. *
  999. * OLD_STRING is not used, maintained for compatibility with other systems
  1000. \*----------------------------------------------------------------------*/
  1001. void SLtt_smart_puts (unsigned short *new_string,
  1002. unsigned short *old_string,
  1003. int len, int row)
  1004. {
  1005. (void) old_string;
  1006. Cursor_Row = row;
  1007. Cursor_Col = 0;
  1008. write_attributes (new_string, len);
  1009. }
  1010. /*----------------------------------------------------------------------*\
  1011. * Function: void SLtt_reset_video (void);
  1012. \*----------------------------------------------------------------------*/
  1013. void SLtt_reset_video (void)
  1014. {
  1015. SLtt_goto_rc (SLtt_Screen_Rows - 1, 0);
  1016. #ifdef HAS_SAVE_SCREEN
  1017. restore_screen ();
  1018. #endif
  1019. Attribute_Byte = 0x07;
  1020. Current_Color = JNO_COLOR;
  1021. SLtt_del_eol ();
  1022. }
  1023. #if 0
  1024. void wide_width (void)
  1025. {
  1026. }
  1027. void narrow_width (void)
  1028. {
  1029. }
  1030. #endif
  1031. /*----------------------------------------------------------------------*\
  1032. * Function: void SLtt_cls (void);
  1033. \*----------------------------------------------------------------------*/
  1034. void SLtt_cls (void)
  1035. {
  1036. #ifdef WIN32
  1037. long bytes;
  1038. COORD coord;
  1039. char ch;
  1040. #endif
  1041. SLtt_normal_video ();
  1042. #if defined (__GO32__) || defined (__WATCOMC__) || defined (EMX_VIDEO)
  1043. SLtt_reset_scroll_region ();
  1044. SLtt_goto_rc (0, 0);
  1045. SLtt_delete_nlines (SLtt_Screen_Rows);
  1046. #else /* __GO32__ or __WATCOMC__ or EMX_VIDEO */
  1047. # ifdef __os2__
  1048. {
  1049. Line_Buffer [0] = ' '; Line_Buffer [1] = Attribute_Byte;
  1050. VioScrollUp (0, 0, -1, -1, -1, (PCH)Line_Buffer, 0);
  1051. }
  1052. # elif defined(WIN32)
  1053. /* clear the WIN32 screen in one shot */
  1054. coord.X = 0;
  1055. coord.Y = 0;
  1056. ch = ' ';
  1057. (void) FillConsoleOutputCharacter(hStdout,
  1058. ch,
  1059. csbiInfo.dwSize.Y * csbiInfo.dwSize.X,
  1060. coord,
  1061. &bytes);
  1062. /* now set screen to the current attribute */
  1063. ch = Attribute_Byte;
  1064. (void) FillConsoleOutputAttribute(hStdout,
  1065. ch,
  1066. csbiInfo.dwSize.Y * csbiInfo.dwSize.X,
  1067. coord,
  1068. &bytes);
  1069. # else /* __os2__ */
  1070. asm mov dx, SLtt_Screen_Cols
  1071. asm dec dx
  1072. asm mov ax, SLtt_Screen_Rows
  1073. asm dec ax
  1074. asm mov dh, al
  1075. asm xor cx, cx
  1076. asm xor ax, ax
  1077. asm mov ah, 7
  1078. asm mov bh, byte ptr Attribute_Byte
  1079. asm int 10h
  1080. # endif /* __os2__ */
  1081. #endif /* __GO32__ or __WATCOMC__ or EMX_VIDEO */
  1082. }
  1083. /*----------------------------------------------------------------------*\
  1084. * Function: void SLtt_putchar (char ch);
  1085. *
  1086. * put CH on the screen in the current position.
  1087. * this function is called assuming that cursor is in correct position
  1088. \*----------------------------------------------------------------------*/
  1089. void SLtt_putchar (char ch)
  1090. {
  1091. #if !defined (GO32_VIDEO) && !defined (EMX_VIDEO)
  1092. unsigned short p, *pp;
  1093. # if defined(WIN32)
  1094. long bytes;
  1095. # endif
  1096. #endif
  1097. if (Current_Color) SLtt_normal_video ();
  1098. slvid_getxy (); /* get current position */
  1099. switch (ch)
  1100. {
  1101. case 7: /* ^G - break */
  1102. SLtt_beep (); break;
  1103. case 8: /* ^H - backspace */
  1104. SLtt_goto_rc (Cursor_Row, Cursor_Col - 1); break;
  1105. case 13: /* ^M - carriage return */
  1106. SLtt_goto_rc (Cursor_Row, 0); break;
  1107. default: /* write character to screen */
  1108. #if defined (EMX_VIDEO)
  1109. v_putn (ch, 1);
  1110. #else /* EMX_VIDEO */
  1111. # ifdef __os2__
  1112. VioWrtCharStrAtt (&ch, 1, Cursor_Row, Cursor_Col,
  1113. (BYTE*)&Attribute_Byte, 0);
  1114. # elif defined(WIN32)
  1115. WriteConsole(hStdout, &ch, 1, &bytes, NULL);
  1116. # else /* __os2__ */
  1117. # ifdef GO32_VIDEO
  1118. ScreenPutChar ((int) ch, Attribute_Byte, Cursor_Col, Cursor_Row);
  1119. # else /* GO32_VIDEO */
  1120. pp = mkScreenPointer (Cursor_Row, Cursor_Col);
  1121. p = (Attribute_Byte << 8) | (unsigned char) ch;
  1122. # ifdef USE_ASM
  1123. SNOW_CHECK;
  1124. # endif
  1125. *pp = p;
  1126. # endif /* GO32_VIDEO */
  1127. # endif /* __os2__ */
  1128. #endif /* EMX_VIDEO */
  1129. SLtt_goto_rc (Cursor_Row, Cursor_Col + 1);
  1130. }
  1131. }
  1132. /*----------------------------------------------------------------------*\
  1133. * Function: void SLtt_set_color (int obj, char *what, char *fg, char *bg);
  1134. *
  1135. * set foreground and background colors of OBJ to the attributes which
  1136. * correspond to the names FG and BG, respectively.
  1137. *
  1138. * WHAT is the name corresponding to the object OBJ, but is not used in
  1139. * this routine.
  1140. \*----------------------------------------------------------------------*/
  1141. void SLtt_set_color (int obj, char *what, char *fg, char *bg)
  1142. {
  1143. int i, b = -1, f = -1;
  1144. #ifdef WIN32
  1145. int newcolor;
  1146. #endif
  1147. (void) what;
  1148. if ( !IsColor || (obj < 0) || (obj >= JMAX_COLORS))
  1149. return;
  1150. for (i = 0; i < JMAX_COLOR_NAMES; i++ )
  1151. {
  1152. if (!strcmp (fg, Color_Names [i]))
  1153. {
  1154. f = i;
  1155. break;
  1156. }
  1157. }
  1158. for (i = 0; i < JMAX_COLOR_NAMES; i++)
  1159. {
  1160. if (!strcmp (bg, Color_Names [i]))
  1161. {
  1162. if (Blink_Killed) b = i; else b = i & 0x7;
  1163. break;
  1164. }
  1165. }
  1166. if ((f == -1) || (b == -1) || (f == b)) return;
  1167. #if 1
  1168. Color_Map [obj] = (b << 4) | f;
  1169. #else
  1170. /*
  1171. 0 1 2 3
  1172. "black", "blue", "green", "cyan",
  1173. 4 5 6 7
  1174. "red", "magenta", "brown", "lightgray",
  1175. 8 9 10 11
  1176. "gray", "brightblue", "brightgreen", "brightcyan",
  1177. 12 13 14 15
  1178. "brightred", "brightmagenta", "yellow", "white"
  1179. */
  1180. /* these aren't all right yet */
  1181. switch (f)
  1182. {
  1183. case 0: newcolor = 0; break;
  1184. case 1: newcolor = FOREGROUND_BLUE; break;
  1185. case 2: newcolor = FOREGROUND_GREEN; break;
  1186. case 3: newcolor = FOREGROUND_GREEN | FOREGROUND_BLUE; break;
  1187. case 4: newcolor = FOREGROUND_RED; break;
  1188. case 5: newcolor = FOREGROUND_RED | FOREGROUND_BLUE; break;
  1189. case 6: newcolor = FOREGROUND_GREEN | FOREGROUND_RED; break;
  1190. case 7: newcolor = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
  1191. case 8: newcolor = FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN; break;
  1192. case 9: newcolor = FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
  1193. case 10: newcolor = FOREGROUND_GREEN | FOREGROUND_INTENSITY; break;
  1194. case 11: newcolor = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
  1195. case 12: newcolor = FOREGROUND_RED | FOREGROUND_INTENSITY; break;
  1196. case 13: newcolor = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
  1197. case 14: newcolor = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
  1198. case 15: newcolor = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
  1199. }
  1200. /* switch (f) */
  1201. /*
  1202. 0 1 2 3
  1203. "black", "blue", "green", "cyan",
  1204. 4 5 6 7
  1205. "red", "magenta", "brown", "lightgray",
  1206. 8 9 10 11
  1207. "gray", "brightblue", "brightgreen", "brightcyan",
  1208. 12 13 14 15
  1209. "brightred", "brightmagenta", "yellow", "white"
  1210. */
  1211. switch (b)
  1212. {
  1213. case 0: newcolor |= 0; break;
  1214. case 1: newcolor |= BACKGROUND_BLUE; break;
  1215. case 2: newcolor |= BACKGROUND_GREEN; break;
  1216. case 3: newcolor |= BACKGROUND_GREEN | BACKGROUND_BLUE; break;
  1217. case 4: newcolor |= BACKGROUND_RED; break;
  1218. case 5: newcolor |= BACKGROUND_RED | BACKGROUND_BLUE; break;
  1219. case 6: newcolor |= BACKGROUND_GREEN | BACKGROUND_RED; break;
  1220. case 7: newcolor |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
  1221. case 8: newcolor |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
  1222. case 9: newcolor |= BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
  1223. case 10: newcolor |= BACKGROUND_GREEN | BACKGROUND_INTENSITY; break;
  1224. case 11: newcolor |= BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
  1225. case 12: newcolor |= BACKGROUND_RED | BACKGROUND_INTENSITY; break;
  1226. case 13: newcolor |= BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
  1227. case 14: newcolor |= BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
  1228. case 15: newcolor |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
  1229. }
  1230. /* switch (b) */
  1231. Color_Map [obj] = newcolor;
  1232. #endif
  1233. /* if we're setting the normal color, and the attribute byte hasn't
  1234. been set yet, set it to the new color */
  1235. if ((obj == 0) && (Attribute_Byte == 0))
  1236. SLtt_reverse_video (0);
  1237. }
  1238. /*----------------------------------------------------------------------*\
  1239. * Function: void SLtt_get_terminfo (void)
  1240. \*----------------------------------------------------------------------*/
  1241. void SLtt_get_terminfo (void)
  1242. {
  1243. #ifdef WIN32
  1244. SLtt_Screen_Rows = csbiInfo.dwSize.Y;
  1245. SLtt_Screen_Cols = csbiInfo.dwSize.X;
  1246. #endif
  1247. #ifdef GO32_VIDEO
  1248. SLtt_Screen_Rows = ScreenRows ();
  1249. SLtt_Screen_Cols = ScreenCols ();
  1250. #endif
  1251. }
  1252. /*----------------------------------------------------------------------*\
  1253. * Function: void SLtt_init_video (void);
  1254. \*----------------------------------------------------------------------*/
  1255. void SLtt_init_video (void)
  1256. {
  1257. #if defined (EMX_VIDEO)
  1258. int OldCol, OldRow;
  1259. #endif
  1260. #ifdef HAS_SAVE_SCREEN
  1261. save_screen ();
  1262. #endif
  1263. Cursor_Row = Cursor_Col = 0;
  1264. #if defined (EMX_VIDEO)
  1265. v_init ();
  1266. if ( v_hardware () != V_MONOCHROME ) IsColor = 1; else IsColor = 0;
  1267. v_getxy(&OldCol,&OldRow);
  1268. v_gotoxy (0, 0);
  1269. if (IsColor)
  1270. {
  1271. if (_osmode == OS2_MODE)
  1272. {
  1273. # if 0
  1274. /* Enable high-intensity background colors */
  1275. VIOINTENSITY RequestBlock;
  1276. RequestBlock.cb = sizeof (RequestBlock);
  1277. RequestBlock.type = 2; RequestBlock.fs = 1;
  1278. VioSetState (&RequestBlock, 0); /* nop if !fullscreen */
  1279. # endif
  1280. Blink_Killed = 1;
  1281. }
  1282. else
  1283. {
  1284. Blink_Killed = 1; /* seems to work */
  1285. }
  1286. }
  1287. if (!Attribute_Byte)
  1288. {
  1289. /* find the attribute currently under the cursor */
  1290. v_getline (Line_Buffer, OldCol, OldRow, 1);
  1291. Attribute_Byte = Line_Buffer[1];
  1292. set_color_from_attribute (Attribute_Byte);
  1293. }
  1294. v_attrib (Attribute_Byte);
  1295. /* SLtt_Term_Cannot_Insert = 1; */
  1296. #else /* EMX_VIDEO */
  1297. # ifdef __os2__
  1298. IsColor = 1; /* is it really? */
  1299. {
  1300. /* Enable high-intensity background colors */
  1301. VIOINTENSITY RequestBlock;
  1302. RequestBlock.cb = sizeof (RequestBlock);
  1303. RequestBlock.type = 2; RequestBlock.fs = 1;
  1304. VioSetState (&RequestBlock, 0); /* nop if !fullscreen */
  1305. Blink_Killed = 1;
  1306. }
  1307. if (!Attribute_Byte)
  1308. {
  1309. /* find the attribute currently under the cursor */
  1310. USHORT Length = 2, Row, Col;
  1311. VioGetCurPos (&Row, &Col, 0);
  1312. VioReadCellStr ((PCH)Line_Buffer, &Length, Row, Col, 0);
  1313. Attribute_Byte = Line_Buffer[1];
  1314. set_color_from_attribute (Attribute_Byte);
  1315. }
  1316. # elif defined(WIN32)
  1317. /* initialize the WIN32 console */
  1318. IsColor = 1; /* yes, the WIN32 console can do color (on a color monitor) */
  1319. # else
  1320. # if defined (__GO32__) || defined (__WATCOMC__)
  1321. # ifdef GO32_VIDEO
  1322. SLtt_Term_Cannot_Insert = 1;
  1323. # else
  1324. Video_Base = (unsigned char *) ScreenPrimary;
  1325. # endif
  1326. if (!Attribute_Byte) Attribute_Byte = 0x17;
  1327. IsColor = 1; /* is it really? */
  1328. if (IsColor)
  1329. {
  1330. union REGS r;
  1331. # ifdef __WATCOMC__
  1332. r.x.eax = 0x1003; r.x.ebx = 0;
  1333. # else
  1334. r.x.ax = 0x1003; r.x.bx = 0;
  1335. # endif
  1336. int86 (0x10, &r, &r);
  1337. Blink_Killed = 1;
  1338. }
  1339. # else /* (__GO32__ or __WATCOMC__ */
  1340. {
  1341. unsigned char *p = (unsigned char far *) 0x00400049L;
  1342. if (*p == 7)
  1343. {
  1344. Video_Status_Port = MONO_STATUS;
  1345. Video_Base = (unsigned char *) MK_FP (0xb000,0000);
  1346. IsColor = 0;
  1347. }
  1348. else
  1349. {
  1350. Video_Status_Port = CGA_STATUS;
  1351. Video_Base = (unsigned char *) MK_FP (0xb800,0000);
  1352. IsColor = 1;
  1353. }
  1354. }
  1355. /* test for video adapter type. Of primary interest is whether there is
  1356. * snow or not. Assume snow if the card is color and not EGA or greater.
  1357. */
  1358. /* Use Ralf Brown test for EGA or greater */
  1359. asm mov ah, 0x12
  1360. asm mov bl, 0x10
  1361. asm mov bh, 0xFF
  1362. asm int 10h
  1363. asm cmp bh, 0xFF
  1364. asm je L1
  1365. /* (V)EGA */
  1366. asm xor bx, bx
  1367. asm mov SLtt_Msdos_Cheap_Video, bx
  1368. asm mov ax, Attribute_Byte
  1369. asm cmp ax, bx
  1370. asm jne L2
  1371. asm mov ax, 0x17
  1372. asm mov Attribute_Byte, ax
  1373. asm jmp L2
  1374. L1:
  1375. /* Not (V)EGA */
  1376. asm mov ah, 0x0F
  1377. asm int 10h
  1378. asm cmp al, 7
  1379. asm je L3
  1380. asm mov ax, 1
  1381. asm mov SLtt_Msdos_Cheap_Video, ax
  1382. L3:
  1383. asm mov ax, Attribute_Byte
  1384. asm cmp ax, 0
  1385. asm jne L2
  1386. asm mov ax, 0x07
  1387. asm mov Attribute_Byte, ax
  1388. L2:
  1389. /* toggle the blink bit so we can use hi intensity background */
  1390. if (IsColor && !SLtt_Msdos_Cheap_Video)
  1391. {
  1392. asm mov ax, 0x1003
  1393. asm mov bx, 0
  1394. asm int 0x10
  1395. Blink_Killed = 1;
  1396. }
  1397. # endif /* __GO32__ or __WATCOMC__ */
  1398. # endif /* __os2__ */
  1399. #endif /* EMX_VIDEO */
  1400. SLtt_set_scroll_region (0, SLtt_Screen_Rows);
  1401. SLtt_Use_Ansi_Colors = IsColor;
  1402. }
  1403. /*----------------------------------------------------------------------*\
  1404. * Function: int SLtt_flush_output (void);
  1405. \*----------------------------------------------------------------------*/
  1406. int SLtt_flush_output (void)
  1407. {
  1408. fflush (stdout);
  1409. return -1;
  1410. }
  1411. int SLtt_set_cursor_visibility (int show)
  1412. {
  1413. (void) show;
  1414. return -1;
  1415. }
  1416. void SLtt_set_mono (int obj_unused, char *unused, SLtt_Char_Type c_unused)
  1417. {
  1418. (void) obj_unused;
  1419. (void) unused;
  1420. (void) c_unused;
  1421. }
  1422. /* /////////////////////// end of file (c source) ///////////////////// */