MONO.C 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/bios/rcs/mono.c $
  15. * $Revision: 1.12 $
  16. * $Author: john $
  17. * $Date: 1995/02/23 11:59:57 $
  18. *
  19. * Library functions for printing to mono card.
  20. *
  21. * $Log: mono.c $
  22. * Revision 1.12 1995/02/23 11:59:57 john
  23. * Made the windows smaller so they don't overwrite the debug file menus.
  24. *
  25. * Revision 1.11 1994/11/27 23:07:50 matt
  26. * Made changes needed to be able to compile out monochrome debugging code
  27. *
  28. * Revision 1.10 1994/10/26 22:23:43 john
  29. * Limited windows to 2. Took away saving what was under
  30. * a window.
  31. *
  32. * Revision 1.9 1994/07/14 23:25:44 matt
  33. * Allow window 0 to be opened; don't allow mono to be initialized twice
  34. *
  35. * Revision 1.8 1994/03/09 10:45:38 john
  36. * Sped up scroll.
  37. *
  38. * Revision 1.7 1994/01/26 08:56:55 mike
  39. * Comment out int3 in mputc.
  40. *
  41. * Revision 1.6 1994/01/12 15:56:34 john
  42. * made backspace do an int3 during mono stuff.
  43. * .,
  44. *
  45. * Revision 1.5 1993/12/07 12:33:23 john
  46. * *** empty log message ***
  47. *
  48. * Revision 1.4 1993/10/15 10:10:25 john
  49. * *** empty log message ***
  50. *
  51. * Revision 1.3 1993/09/14 20:55:13 matt
  52. * Made minit() and mopen() check for presence of mono card in machine.
  53. *
  54. * Revision 1.2 1993/07/22 13:10:21 john
  55. * *** empty log message ***
  56. *
  57. * Revision 1.1 1993/07/10 13:10:38 matt
  58. * Initial revision
  59. *
  60. *
  61. */
  62. #pragma off (unreferenced)
  63. static char rcsid[] = "$Id: mono.c 1.12 1995/02/23 11:59:57 john Exp $";
  64. #pragma on (unreferenced)
  65. // Library functions for printing to mono card.
  66. #include <stdio.h>
  67. #include <stdlib.h>
  68. #include <stdarg.h>
  69. #include <string.h>
  70. #include <dos.h>
  71. #include <conio.h>
  72. #include "key.h"
  73. void mono_int_3();
  74. #pragma aux mono_int_3 = "int 3";
  75. #define MAX_NUM_WINDOWS 2
  76. struct mono_element {
  77. unsigned char character;
  78. unsigned char attribute;
  79. };
  80. typedef struct {
  81. short first_row;
  82. short height;
  83. short first_col;
  84. short width;
  85. short cursor_row;
  86. short cursor_col;
  87. short open;
  88. struct mono_element save_buf[25][80];
  89. struct mono_element text[25][80];
  90. } WINDOW;
  91. void scroll( short n );
  92. void drawbox( short n );
  93. #define ROW Window[n].first_row
  94. #define HEIGHT Window[n].height
  95. #define COL Window[n].first_col
  96. #define WIDTH Window[n].width
  97. #define CROW Window[n].cursor_row
  98. #define CCOL Window[n].cursor_col
  99. #define OPEN Window[n].open
  100. #define CHAR(r,c) (*monoscreen)[ROW+(r)][COL+(c)].character
  101. #define ATTR(r,c) (*monoscreen)[ROW+(r)][COL+(c)].attribute
  102. #define XCHAR(r,c) Window[n].text[ROW+(r)][COL+(c)].character
  103. #define XATTR(r,c) Window[n].text[ROW+(r)][COL+(c)].attribute
  104. static WINDOW Window[MAX_NUM_WINDOWS];
  105. struct mono_element (*monoscreen)[25][80];
  106. void mputc( short n, char c )
  107. {
  108. if (!OPEN) return;
  109. // if (keyd_pressed[KEY_BACKSP])
  110. // mono_int_3();
  111. switch (c)
  112. {
  113. case 8:
  114. if (CCOL > 0) CCOL--;
  115. break;
  116. case 9:
  117. CHAR( CROW, CCOL ) = ' ';
  118. ATTR( CROW, CCOL ) = XATTR( CROW, CCOL );
  119. XCHAR( CROW, CCOL ) = ' ';
  120. CCOL++;
  121. while (CCOL % 4) {
  122. CHAR( CROW, CCOL ) = ' ';
  123. ATTR( CROW, CCOL ) = XATTR( CROW, CCOL );
  124. XCHAR( CROW, CCOL ) = ' ';
  125. CCOL++;
  126. }
  127. break;
  128. case 10:
  129. case 13:
  130. CCOL = 0;
  131. CROW++;
  132. break;
  133. default:
  134. CHAR( CROW, CCOL ) = c;
  135. ATTR( CROW, CCOL ) = XATTR( CROW, CCOL );
  136. XCHAR( CROW, CCOL ) = c;
  137. CCOL++;
  138. }
  139. if ( CCOL >= WIDTH ) {
  140. CCOL = 0;
  141. CROW++;
  142. }
  143. if ( CROW >= HEIGHT ) {
  144. CROW--;
  145. scroll(n);
  146. }
  147. msetcursor( ROW+CROW, COL+CCOL );
  148. }
  149. void mputc_at( short n, short row, short col, char c )
  150. {
  151. CROW = row;
  152. CCOL = col;
  153. if (!OPEN) return;
  154. mputc( n, c );
  155. }
  156. void copy_row(int nwords,short *src, short *dest1, short *dest2 );
  157. #pragma aux copy_row parm [ecx] [esi] [ebx] [edx] modify exact [eax ebx ecx edx esi] = \
  158. " shr ecx, 1" \
  159. " jnc even_num" \
  160. " mov ax, [esi]" \
  161. " add esi, 2" \
  162. " mov [ebx], ax" \
  163. " add ebx, 2" \
  164. " mov [edx], ax" \
  165. " add edx, 2" \
  166. "even_num: cmp ecx, 0" \
  167. " je done" \
  168. "rowloop: mov eax, [esi]" \
  169. " add esi, 4" \
  170. " mov [edx], eax" \
  171. " add edx, 4" \
  172. " mov [ebx], eax" \
  173. " add ebx, 4" \
  174. " loop rowloop" \
  175. "done: "
  176. void scroll( short n )
  177. {
  178. register row, col;
  179. if (!OPEN) return;
  180. col = 0;
  181. for ( row = 0; row < (HEIGHT-1); row++ )
  182. copy_row( WIDTH, (short *)&XCHAR(row+1,col), (short *)&CHAR(row,col), (short *)&XCHAR(row,col) );
  183. // for ( col = 0; col < WIDTH; col++ )
  184. // {
  185. // CHAR( row, col ) = XCHAR( row+1, col );
  186. // ATTR( row, col ) = XATTR( row+1, col );
  187. // XCHAR( row, col ) = XCHAR( row+1, col );
  188. // XATTR( row, col ) = XATTR( row+1, col );
  189. // }
  190. for ( col = 0; col < WIDTH; col++ )
  191. {
  192. CHAR( HEIGHT-1, col ) = ' ';
  193. ATTR( HEIGHT-1, col ) = XATTR( HEIGHT-1, col );
  194. XCHAR( HEIGHT-1, col ) = ' ';
  195. }
  196. }
  197. void msetcursor(short row, short col)
  198. {
  199. int pos = row*80+col;
  200. outp( 0x3b4, 15 );
  201. outp( 0x3b5, pos & 0xFF );
  202. outp( 0x3b4, 14 );
  203. outp( 0x3b5, (pos >> 8) & 0xff );
  204. }
  205. static char temp_m_buffer[1000];
  206. void _mprintf( short n, char * format, ... )
  207. {
  208. char *ptr=temp_m_buffer;
  209. va_list args;
  210. if (!OPEN) return;
  211. va_start(args, format );
  212. vsprintf(temp_m_buffer,format,args);
  213. while( *ptr )
  214. mputc( n, *ptr++ );
  215. }
  216. void _mprintf_at( short n, short row, short col, char * format, ... )
  217. {
  218. int r,c;
  219. char buffer[1000], *ptr=buffer;
  220. va_list args;
  221. if (!OPEN) return;
  222. r = CROW; c = CCOL;
  223. CROW = row;
  224. CCOL = col;
  225. va_start(args, format );
  226. vsprintf(buffer,format,args);
  227. while( *ptr )
  228. mputc( n, *ptr++ );
  229. CROW = r; CCOL = c;
  230. msetcursor( ROW+CROW, COL+CCOL );
  231. }
  232. void drawbox(short n)
  233. {
  234. short row, col;
  235. if (!OPEN) return;
  236. for (row=0; row <HEIGHT; row++ ) {
  237. CHAR( row, -1 ) = 179;
  238. CHAR( row, WIDTH ) = 179;
  239. XCHAR( row, -1 ) = 179;
  240. XCHAR( row, WIDTH ) = 179;
  241. }
  242. for (col=0; col < WIDTH; col++ ) {
  243. CHAR( -1, col ) = 196;
  244. CHAR( HEIGHT, col ) = 196;
  245. XCHAR( -1, col ) = 196;
  246. XCHAR( HEIGHT, col ) = 196;
  247. }
  248. CHAR( -1,-1 ) = 218;
  249. CHAR( -1, WIDTH ) = 191;
  250. CHAR( HEIGHT, -1 ) = 192;
  251. CHAR( HEIGHT, WIDTH ) = 217;
  252. XCHAR( -1,-1 ) = 218;
  253. XCHAR( -1, WIDTH ) = 191;
  254. XCHAR( HEIGHT, -1 ) = 192;
  255. XCHAR( HEIGHT, WIDTH ) = 217;
  256. }
  257. void mclear( short n )
  258. {
  259. short row, col;
  260. if (!OPEN) return;
  261. for (row=0; row<HEIGHT; row++ )
  262. for (col=0; col<WIDTH; col++ ) {
  263. CHAR(row,col) = 32;
  264. ATTR(row,col) = 7;
  265. XCHAR(row,col) = 32;
  266. XATTR(row,col) = 7;
  267. }
  268. CCOL = 0;
  269. CROW = 0;
  270. }
  271. void mclose(short n)
  272. {
  273. short row, col;
  274. if (!OPEN) return;
  275. for (row=-1; row<HEIGHT+1; row++ )
  276. for (col=-1; col<WIDTH+1; col++ ) {
  277. CHAR(row,col) = 32;
  278. ATTR(row,col) = 7;
  279. }
  280. OPEN = 0;
  281. CCOL = 0;
  282. CROW = 0;
  283. msetcursor(0,0);
  284. }
  285. void mrefresh(short n)
  286. {
  287. short row, col;
  288. if (!OPEN) return;
  289. for (row=-1; row<HEIGHT+1; row++ )
  290. for (col=-1; col<WIDTH+1; col++ ) {
  291. CHAR(row,col) = XCHAR(row,col);
  292. ATTR(row,col) = XATTR(row,col);
  293. }
  294. msetcursor( ROW+CROW, COL+CCOL );
  295. }
  296. int mono_present(); //return true if mono monitor in system
  297. void mopen( short n, short row, short col, short width, short height, char * title )
  298. {
  299. // if (n==0) return;
  300. if (! mono_present()) return; //error! no mono card
  301. if (OPEN) mclose(n);
  302. OPEN = 1;
  303. ROW = row;
  304. COL = col;
  305. WIDTH = width;
  306. HEIGHT = height;
  307. for (row=-1; row<HEIGHT+1; row++ )
  308. for (col=-1; col<WIDTH+1; col++ ) {
  309. CHAR(row,col) = 32;
  310. ATTR(row,col) = 7;
  311. XCHAR(row,col) = 32;
  312. XATTR(row,col) = 7;
  313. }
  314. drawbox(n);
  315. CROW=-1; CCOL=0;
  316. _mprintf( n, title );
  317. CROW=0; CCOL=0;
  318. msetcursor( ROW+CROW, COL+CCOL );
  319. }
  320. #pragma aux mono_present value [eax] modify [bx] = \
  321. "mov ax,1a00h" \
  322. "int 10h" \
  323. "mov eax,-1" \
  324. "cmp bl,1" \
  325. "je got_it" \
  326. "cmp bh,1" \
  327. "je got_it" \
  328. "xor eax,eax" \
  329. "got_it:";
  330. int minit()
  331. {
  332. short n;
  333. static initialized=0;
  334. //short col, row;
  335. if (! mono_present()) return 0; //error! no mono card
  336. if (initialized)
  337. return 1;
  338. initialized=1;
  339. monoscreen = (struct mono_element (*)[25][80])0xB0000;
  340. n=0;
  341. OPEN=1;
  342. ROW=2;
  343. COL=0;
  344. WIDTH=80;
  345. HEIGHT=24;
  346. CCOL=0;
  347. CROW=0;
  348. mclear(0);
  349. for (n=1; n<MAX_NUM_WINDOWS; n++ ) {
  350. OPEN = 0;
  351. ROW = 2;
  352. COL = 1;
  353. WIDTH=78;
  354. HEIGHT=23;
  355. CROW=0;
  356. CCOL=0;
  357. }
  358. return -1; //everything ok
  359. }
  360.