/* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* * $Source: /cvsroot/dxx-rebirth/d2x-rebirth/arch/dos/mono.c,v $ * $Revision: 1.1.1.1 $ * $Author: zicodxx $ * $Date: 2006/03/17 19:52:46 $ * * Library functions for printing to mono card. * */ #ifdef RCS static char rcsid[] = "$Id: mono.c,v 1.1.1.1 2006/03/17 19:52:46 zicodxx Exp $"; #endif // Library functions for printing to mono card. #include #include #include #include #include #include #include "key.h" //#define MONO_IS_STDERR #ifndef __GNUC__ void mono_int_3(); #pragma aux mono_int_3 = "int 3"; #else static inline void mono_int_3() { asm("int $3"); } #endif void msetcursor(short row, short col); #define MAX_NUM_WINDOWS 2 struct mono_element { unsigned char character; unsigned char attribute; }; typedef struct { short first_row; short height; short first_col; short width; short cursor_row; short cursor_col; short open; struct mono_element save_buf[25][80]; struct mono_element text[25][80]; } WINDOW; void scroll( short n ); void drawbox( short n ); #define ROW Window[n].first_row #define HEIGHT Window[n].height #define COL Window[n].first_col #define WIDTH Window[n].width #define CROW Window[n].cursor_row #define CCOL Window[n].cursor_col #define OPEN Window[n].open #define CHAR(r,c) (*monoscreen)[ROW+(r)][COL+(c)].character #define ATTR(r,c) (*monoscreen)[ROW+(r)][COL+(c)].attribute #define XCHAR(r,c) Window[n].text[ROW+(r)][COL+(c)].character #define XATTR(r,c) Window[n].text[ROW+(r)][COL+(c)].attribute static WINDOW Window[MAX_NUM_WINDOWS]; struct mono_element (*monoscreen)[25][80]; void mputc( short n, char c ) { if (!OPEN) return; // if (keyd_pressed[KEY_BACKSP]) // mono_int_3(); switch (c) { case 8: if (CCOL > 0) CCOL--; break; case 9: CHAR( CROW, CCOL ) = ' '; ATTR( CROW, CCOL ) = XATTR( CROW, CCOL ); XCHAR( CROW, CCOL ) = ' '; CCOL++; while (CCOL % 4) { CHAR( CROW, CCOL ) = ' '; ATTR( CROW, CCOL ) = XATTR( CROW, CCOL ); XCHAR( CROW, CCOL ) = ' '; CCOL++; } break; case 10: case 13: CCOL = 0; CROW++; break; default: CHAR( CROW, CCOL ) = c; ATTR( CROW, CCOL ) = XATTR( CROW, CCOL ); XCHAR( CROW, CCOL ) = c; CCOL++; } if ( CCOL >= WIDTH ) { CCOL = 0; CROW++; } if ( CROW >= HEIGHT ) { CROW--; scroll(n); } msetcursor( ROW+CROW, COL+CCOL ); } void mputc_at( short n, short row, short col, char c ) { CROW = row; CCOL = col; if (!OPEN) return; mputc( n, c ); } #ifdef __WATCOMC__ void copy_row(int nwords,short *src, short *dest1, short *dest2 ); #pragma aux copy_row parm [ecx] [esi] [ebx] [edx] modify exact [eax ebx ecx edx esi] = \ " shr ecx, 1" \ " jnc even_num" \ " mov ax, [esi]" \ " add esi, 2" \ " mov [ebx], ax" \ " add ebx, 2" \ " mov [edx], ax" \ " add edx, 2" \ "even_num: cmp ecx, 0" \ " je done" \ "rowloop: mov eax, [esi]" \ " add esi, 4" \ " mov [edx], eax" \ " add edx, 4" \ " mov [ebx], eax" \ " add ebx, 4" \ " loop rowloop" \ "done: " #else void copy_row(int nwords,short *src, short *dest1, short *dest2 ) { while (nwords--) *(dest1++) = *(dest2++) = *(src++); } #endif void scroll( short n ) { register int row, col; if (!OPEN) return; col = 0; for ( row = 0; row < (HEIGHT-1); row++ ) copy_row( WIDTH, (short *)&XCHAR(row+1,col), (short *)&CHAR(row,col), (short *)&XCHAR(row,col) ); // for ( col = 0; col < WIDTH; col++ ) // { // CHAR( row, col ) = XCHAR( row+1, col ); // ATTR( row, col ) = XATTR( row+1, col ); // XCHAR( row, col ) = XCHAR( row+1, col ); // XATTR( row, col ) = XATTR( row+1, col ); // } for ( col = 0; col < WIDTH; col++ ) { CHAR( HEIGHT-1, col ) = ' '; ATTR( HEIGHT-1, col ) = XATTR( HEIGHT-1, col ); XCHAR( HEIGHT-1, col ) = ' '; } } void msetcursor(short row, short col) { int pos = row*80+col; outp( 0x3b4, 15 ); outp( 0x3b5, pos & 0xFF ); outp( 0x3b4, 14 ); outp( 0x3b5, (pos >> 8) & 0xff ); } static char temp_m_buffer[1000]; void _mprintf( short n, char * format, ... ) { #ifdef MONO_IS_STDERR va_list args; va_start(args, format ); vfprintf(stderr, format, args); #else char *ptr=temp_m_buffer; va_list args; if (!OPEN) return; va_start(args, format ); vsprintf(temp_m_buffer,format,args); while( *ptr ) mputc( n, *ptr++ ); #endif } void _mprintf_at( short n, short row, short col, char * format, ... ) { int r,c; char buffer[1000], *ptr=buffer; va_list args; if (!OPEN) return; r = CROW; c = CCOL; CROW = row; CCOL = col; va_start(args, format ); vsprintf(buffer,format,args); while( *ptr ) mputc( n, *ptr++ ); CROW = r; CCOL = c; msetcursor( ROW+CROW, COL+CCOL ); } void drawbox(short n) { short row, col; if (!OPEN) return; for (row=0; row