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.
14 * $Source: /cvs/cvsroot/d2x/arch/dos/mono.c,v $
15 * $Revision: 1.1.1.1 $
17 * $Date: 2001-01-19 03:30:15 $
19 * Library functions for printing to mono card.
21 * $Log: not supported by cvs2svn $
22 * Revision 1.1.1.1 1999/06/14 21:58:35 donut
23 * Import of d1x 1.37 source.
25 * Revision 1.12 1995/02/23 11:59:57 john
26 * Made the windows smaller so they don't overwrite the debug file menus.
28 * Revision 1.11 1994/11/27 23:07:50 matt
29 * Made changes needed to be able to compile out monochrome debugging code
31 * Revision 1.10 1994/10/26 22:23:43 john
32 * Limited windows to 2. Took away saving what was under
35 * Revision 1.9 1994/07/14 23:25:44 matt
36 * Allow window 0 to be opened; don't allow mono to be initialized twice
38 * Revision 1.8 1994/03/09 10:45:38 john
41 * Revision 1.7 1994/01/26 08:56:55 mike
42 * Comment out int3 in mputc.
44 * Revision 1.6 1994/01/12 15:56:34 john
45 * made backspace do an int3 during mono stuff.
48 * Revision 1.5 1993/12/07 12:33:23 john
49 * *** empty log message ***
51 * Revision 1.4 1993/10/15 10:10:25 john
52 * *** empty log message ***
54 * Revision 1.3 1993/09/14 20:55:13 matt
55 * Made minit() and mopen() check for presence of mono card in machine.
57 * Revision 1.2 1993/07/22 13:10:21 john
58 * *** empty log message ***
60 * Revision 1.1 1993/07/10 13:10:38 matt
67 static char rcsid[] = "$Id: mono.c,v 1.1.1.1 2001-01-19 03:30:15 bradleyb Exp $";
70 // Library functions for printing to mono card.
81 //#define MONO_IS_STDERR
84 #pragma aux mono_int_3 = "int 3";
86 static inline void mono_int_3() { asm("int $3"); }
88 void msetcursor(short row, short col);
90 #define MAX_NUM_WINDOWS 2
93 unsigned char character;
94 unsigned char attribute;
105 struct mono_element save_buf[25][80];
106 struct mono_element text[25][80];
110 void scroll( short n );
111 void drawbox( short n );
113 #define ROW Window[n].first_row
114 #define HEIGHT Window[n].height
115 #define COL Window[n].first_col
116 #define WIDTH Window[n].width
117 #define CROW Window[n].cursor_row
118 #define CCOL Window[n].cursor_col
119 #define OPEN Window[n].open
120 #define CHAR(r,c) (*monoscreen)[ROW+(r)][COL+(c)].character
121 #define ATTR(r,c) (*monoscreen)[ROW+(r)][COL+(c)].attribute
122 #define XCHAR(r,c) Window[n].text[ROW+(r)][COL+(c)].character
123 #define XATTR(r,c) Window[n].text[ROW+(r)][COL+(c)].attribute
125 static WINDOW Window[MAX_NUM_WINDOWS];
127 struct mono_element (*monoscreen)[25][80];
129 void mputc( short n, char c )
133 // if (keyd_pressed[KEY_BACKSP])
139 if (CCOL > 0) CCOL--;
142 CHAR( CROW, CCOL ) = ' ';
143 ATTR( CROW, CCOL ) = XATTR( CROW, CCOL );
144 XCHAR( CROW, CCOL ) = ' ';
147 CHAR( CROW, CCOL ) = ' ';
148 ATTR( CROW, CCOL ) = XATTR( CROW, CCOL );
149 XCHAR( CROW, CCOL ) = ' ';
159 CHAR( CROW, CCOL ) = c;
160 ATTR( CROW, CCOL ) = XATTR( CROW, CCOL );
161 XCHAR( CROW, CCOL ) = c;
165 if ( CCOL >= WIDTH ) {
169 if ( CROW >= HEIGHT ) {
174 msetcursor( ROW+CROW, COL+CCOL );
178 void mputc_at( short n, short row, short col, char c )
190 void copy_row(int nwords,short *src, short *dest1, short *dest2 );
191 #pragma aux copy_row parm [ecx] [esi] [ebx] [edx] modify exact [eax ebx ecx edx esi] = \
200 "even_num: cmp ecx, 0" \
202 "rowloop: mov eax, [esi]" \
211 void copy_row(int nwords,short *src, short *dest1, short *dest2 ) {
213 *(dest1++) = *(dest2++) = *(src++);
217 void scroll( short n )
219 register int row, col;
224 for ( row = 0; row < (HEIGHT-1); row++ )
225 copy_row( WIDTH, (short *)&XCHAR(row+1,col), (short *)&CHAR(row,col), (short *)&XCHAR(row,col) );
227 // for ( col = 0; col < WIDTH; col++ )
229 // CHAR( row, col ) = XCHAR( row+1, col );
230 // ATTR( row, col ) = XATTR( row+1, col );
231 // XCHAR( row, col ) = XCHAR( row+1, col );
232 // XATTR( row, col ) = XATTR( row+1, col );
235 for ( col = 0; col < WIDTH; col++ )
237 CHAR( HEIGHT-1, col ) = ' ';
238 ATTR( HEIGHT-1, col ) = XATTR( HEIGHT-1, col );
239 XCHAR( HEIGHT-1, col ) = ' ';
244 void msetcursor(short row, short col)
246 int pos = row*80+col;
249 outp( 0x3b5, pos & 0xFF );
251 outp( 0x3b5, (pos >> 8) & 0xff );
254 static char temp_m_buffer[1000];
255 void _mprintf( short n, char * format, ... )
257 #ifdef MONO_IS_STDERR
259 va_start(args, format );
260 vfprintf(stderr, format, args);
262 char *ptr=temp_m_buffer;
267 va_start(args, format );
268 vsprintf(temp_m_buffer,format,args);
274 void _mprintf_at( short n, short row, short col, char * format, ... )
277 char buffer[1000], *ptr=buffer;
287 va_start(args, format );
288 vsprintf(buffer,format,args);
295 msetcursor( ROW+CROW, COL+CCOL );
300 void drawbox(short n)
306 for (row=0; row <HEIGHT; row++ ) {
307 CHAR( row, -1 ) = 179;
308 CHAR( row, WIDTH ) = 179;
309 XCHAR( row, -1 ) = 179;
310 XCHAR( row, WIDTH ) = 179;
313 for (col=0; col < WIDTH; col++ ) {
314 CHAR( -1, col ) = 196;
315 CHAR( HEIGHT, col ) = 196;
316 XCHAR( -1, col ) = 196;
317 XCHAR( HEIGHT, col ) = 196;
321 CHAR( -1, WIDTH ) = 191;
322 CHAR( HEIGHT, -1 ) = 192;
323 CHAR( HEIGHT, WIDTH ) = 217;
324 XCHAR( -1,-1 ) = 218;
325 XCHAR( -1, WIDTH ) = 191;
326 XCHAR( HEIGHT, -1 ) = 192;
327 XCHAR( HEIGHT, WIDTH ) = 217;
331 void mclear( short n )
337 for (row=0; row<HEIGHT; row++ )
338 for (col=0; col<WIDTH; col++ ) {
354 for (row=-1; row<HEIGHT+1; row++ )
355 for (col=-1; col<WIDTH+1; col++ ) {
367 void mrefresh(short n)
373 for (row=-1; row<HEIGHT+1; row++ )
374 for (col=-1; col<WIDTH+1; col++ ) {
375 CHAR(row,col) = XCHAR(row,col);
376 ATTR(row,col) = XATTR(row,col);
379 msetcursor( ROW+CROW, COL+CCOL );
384 int mono_present(); //return true if mono monitor in system
387 void mopen( short n, short row, short col, short width, short height, char * title )
391 if (! mono_present()) return; //error! no mono card
401 for (row=-1; row<HEIGHT+1; row++ )
402 for (col=-1; col<WIDTH+1; col++ ) {
411 _mprintf( n, title );
413 msetcursor( ROW+CROW, COL+CCOL );
418 #pragma aux mono_present value [eax] modify [bx] = \
429 int mono_present() { return 0; }
435 static int initialized=0;
438 if (! mono_present()) return 0; //error! no mono card
445 monoscreen = (struct mono_element (*)[25][80])0xB0000;
458 for (n=1; n<MAX_NUM_WINDOWS; n++ ) {
468 return -1; //everything ok