home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / bios / mono.c < prev    next >
Text File  |  1998-06-08  |  9KB  |  450 lines

  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.  
  63. #pragma off (unreferenced)
  64. static char rcsid[] = "$Id: mono.c 1.12 1995/02/23 11:59:57 john Exp $";
  65. #pragma on (unreferenced)
  66.  
  67. // Library functions for printing to mono card.
  68.  
  69. #include <stdio.h>
  70. #include <stdlib.h>
  71. #include <stdarg.h>
  72. #include <string.h>
  73. #include <dos.h>
  74. #include <conio.h>
  75.  
  76. #include "key.h"
  77.  
  78. void mono_int_3();
  79. #pragma aux mono_int_3 = "int 3";
  80.  
  81. #define MAX_NUM_WINDOWS 2
  82.  
  83. struct mono_element {
  84.     unsigned char character;
  85.     unsigned char attribute;
  86. };
  87.  
  88. typedef struct  {
  89.     short   first_row;
  90.     short   height;
  91.     short   first_col;
  92.     short   width;
  93.     short   cursor_row;
  94.     short   cursor_col;
  95.     short   open;
  96.     struct  mono_element save_buf[25][80];
  97.     struct  mono_element text[25][80];
  98. } WINDOW;
  99.  
  100.  
  101. void scroll( short n );
  102. void drawbox( short n );
  103.  
  104. #define ROW             Window[n].first_row
  105. #define HEIGHT          Window[n].height
  106. #define COL             Window[n].first_col
  107. #define WIDTH           Window[n].width
  108. #define CROW            Window[n].cursor_row
  109. #define CCOL            Window[n].cursor_col
  110. #define OPEN            Window[n].open
  111. #define CHAR(r,c)       (*monoscreen)[ROW+(r)][COL+(c)].character
  112. #define ATTR(r,c)       (*monoscreen)[ROW+(r)][COL+(c)].attribute
  113. #define XCHAR(r,c)      Window[n].text[ROW+(r)][COL+(c)].character
  114. #define XATTR(r,c)      Window[n].text[ROW+(r)][COL+(c)].attribute
  115.  
  116. static WINDOW Window[MAX_NUM_WINDOWS];
  117.  
  118. struct mono_element (*monoscreen)[25][80];
  119.  
  120. void mputc( short n, char c )
  121. {
  122.     if (!OPEN) return;
  123.  
  124. //    if (keyd_pressed[KEY_BACKSP]) 
  125. //        mono_int_3();
  126.  
  127.     switch (c)
  128.     {
  129.     case 8:
  130.         if (CCOL > 0) CCOL--;
  131.         break;
  132.     case 9:
  133.         CHAR( CROW, CCOL ) = ' ';
  134.         ATTR( CROW, CCOL ) = XATTR( CROW, CCOL );
  135.         XCHAR( CROW, CCOL ) = ' ';
  136.         CCOL++;
  137.         while (CCOL % 4) {
  138.             CHAR( CROW, CCOL ) = ' ';
  139.             ATTR( CROW, CCOL ) = XATTR( CROW, CCOL );
  140.             XCHAR( CROW, CCOL ) = ' ';
  141.             CCOL++;
  142.         }
  143.         break;
  144.     case 10:
  145.     case 13:
  146.         CCOL = 0;
  147.         CROW++;
  148.         break;
  149.     default:
  150.         CHAR( CROW, CCOL ) = c;
  151.         ATTR( CROW, CCOL ) = XATTR( CROW, CCOL );
  152.         XCHAR( CROW, CCOL ) = c;
  153.         CCOL++;
  154.     }
  155.  
  156.     if ( CCOL >= WIDTH )    {
  157.         CCOL = 0;
  158.         CROW++;
  159.     }
  160.     if ( CROW >= HEIGHT )   {
  161.         CROW--;
  162.         scroll(n);
  163.     }
  164.  
  165.     msetcursor( ROW+CROW, COL+CCOL );
  166.  
  167. }
  168.  
  169. void mputc_at( short n, short row, short col, char c )
  170. {
  171.     CROW = row;
  172.     CCOL = col;
  173.  
  174.     if (!OPEN) return;
  175.  
  176.     mputc( n, c );
  177.  
  178. }
  179.  
  180.  
  181. void copy_row(int nwords,short *src, short *dest1, short *dest2 );
  182. #pragma aux copy_row parm [ecx] [esi] [ebx] [edx] modify exact [eax ebx ecx edx esi] = \
  183. "                shr        ecx, 1"                 \
  184. "                jnc        even_num"            \
  185. "                mov        ax, [esi]"            \
  186. "                add        esi, 2"                \
  187. "                mov        [ebx], ax"            \
  188. "                add        ebx, 2"                \
  189. "                mov        [edx], ax"            \
  190. "                add        edx, 2"                \
  191. "even_num:    cmp        ecx, 0"                \
  192. "                je            done"                    \
  193. "rowloop:    mov        eax, [esi]"            \
  194. "                add        esi, 4"                \
  195. "                mov        [edx], eax"            \
  196. "                add        edx, 4"                \
  197. "                mov        [ebx], eax"            \
  198. "                add        ebx, 4"                \
  199. "                loop        rowloop"                \
  200. "done:    "
  201.  
  202.  
  203. void scroll( short n )
  204. {
  205.     register row, col;
  206.  
  207.     if (!OPEN) return;
  208.  
  209.     col = 0;
  210.     for ( row = 0; row < (HEIGHT-1); row++ )
  211.         copy_row( WIDTH, (short *)&XCHAR(row+1,col), (short *)&CHAR(row,col), (short *)&XCHAR(row,col) );
  212.  
  213. //        for ( col = 0; col < WIDTH; col++ )
  214. //        {
  215. //            CHAR( row, col ) = XCHAR( row+1, col );
  216. //            ATTR( row, col ) = XATTR( row+1, col );
  217. //            XCHAR( row, col ) = XCHAR( row+1, col );
  218. //            XATTR( row, col ) = XATTR( row+1, col );
  219. //        }
  220.  
  221.     for ( col = 0; col < WIDTH; col++ )
  222.     {
  223.         CHAR( HEIGHT-1, col ) = ' ';
  224.         ATTR( HEIGHT-1, col ) = XATTR( HEIGHT-1, col );
  225.         XCHAR( HEIGHT-1, col ) = ' ';
  226.     }
  227.  
  228. }
  229.  
  230. void msetcursor(short row, short col)
  231. {
  232.     int pos = row*80+col;
  233.  
  234.     outp( 0x3b4, 15 );
  235.     outp( 0x3b5, pos & 0xFF );
  236.     outp( 0x3b4, 14 );
  237.     outp( 0x3b5, (pos >> 8) & 0xff );
  238. }
  239.  
  240. static char temp_m_buffer[1000];
  241. void _mprintf( short n, char * format, ... )
  242. {
  243.     char *ptr=temp_m_buffer;
  244.     va_list args;
  245.  
  246.     if (!OPEN) return;
  247.  
  248.     va_start(args, format );
  249.     vsprintf(temp_m_buffer,format,args);
  250.     while( *ptr )
  251.         mputc( n, *ptr++ );
  252.  
  253. }
  254.  
  255. void _mprintf_at( short n, short row, short col, char * format, ... )
  256. {
  257.     int r,c;
  258.     char buffer[1000], *ptr=buffer;
  259.     va_list args;
  260.  
  261.     if (!OPEN) return;
  262.  
  263.     r = CROW; c = CCOL;
  264.  
  265.     CROW = row;
  266.     CCOL = col;
  267.  
  268.     va_start(args, format );
  269.     vsprintf(buffer,format,args);
  270.     while( *ptr )
  271.         mputc( n, *ptr++ );
  272.  
  273.  
  274.     CROW = r; CCOL = c;
  275.  
  276.     msetcursor( ROW+CROW, COL+CCOL );
  277.  
  278. }
  279.  
  280.  
  281. void drawbox(short n)
  282. {
  283.     short row, col;
  284.  
  285.     if (!OPEN) return;
  286.  
  287.     for (row=0; row <HEIGHT; row++ )    {
  288.         CHAR( row, -1 ) = 179;
  289.         CHAR( row, WIDTH ) = 179;
  290.         XCHAR( row, -1 ) = 179;
  291.         XCHAR( row, WIDTH ) = 179;
  292.     }
  293.  
  294.     for (col=0; col < WIDTH; col++ )  {
  295.         CHAR( -1, col ) = 196;
  296.         CHAR( HEIGHT, col ) = 196;
  297.         XCHAR( -1, col ) = 196;
  298.         XCHAR( HEIGHT, col ) = 196;
  299.     }
  300.  
  301.     CHAR( -1,-1 ) = 218;
  302.     CHAR( -1, WIDTH ) = 191;
  303.     CHAR( HEIGHT, -1 ) = 192;
  304.     CHAR( HEIGHT, WIDTH ) = 217;
  305.     XCHAR( -1,-1 ) = 218;
  306.     XCHAR( -1, WIDTH ) = 191;
  307.     XCHAR( HEIGHT, -1 ) = 192;
  308.     XCHAR( HEIGHT, WIDTH ) = 217;
  309.  
  310. }
  311.  
  312. void mclear( short n )
  313. {
  314.     short row, col;
  315.  
  316.     if (!OPEN) return;
  317.  
  318.     for (row=0; row<HEIGHT; row++ )
  319.         for (col=0; col<WIDTH; col++ )  {
  320.             CHAR(row,col) = 32;
  321.             ATTR(row,col) = 7;
  322.             XCHAR(row,col) = 32;
  323.             XATTR(row,col) = 7;
  324.         }
  325.     CCOL = 0;
  326.     CROW = 0;
  327. }
  328.  
  329. void mclose(short n)
  330. {
  331.     short row, col;
  332.  
  333.     if (!OPEN) return;
  334.  
  335.     for (row=-1; row<HEIGHT+1; row++ )
  336.         for (col=-1; col<WIDTH+1; col++ )  {
  337.             CHAR(row,col) = 32;
  338.             ATTR(row,col) = 7;
  339.         }
  340.     OPEN = 0;
  341.     CCOL = 0;
  342.     CROW = 0;
  343.  
  344.     msetcursor(0,0);
  345.  
  346. }
  347.  
  348. void mrefresh(short n)
  349. {
  350.     short row, col;
  351.  
  352.     if (!OPEN) return;
  353.  
  354.     for (row=-1; row<HEIGHT+1; row++ )
  355.         for (col=-1; col<WIDTH+1; col++ )  {
  356.             CHAR(row,col) = XCHAR(row,col);
  357.             ATTR(row,col) = XATTR(row,col);
  358.         }
  359.  
  360.     msetcursor( ROW+CROW, COL+CCOL );
  361.  
  362. }
  363.  
  364.  
  365. int mono_present();        //return true if mono monitor in system
  366.  
  367.  
  368. void mopen( short n, short row, short col, short width, short height, char * title )
  369. {
  370. //    if (n==0) return;
  371.  
  372.     if (! mono_present()) return;    //error! no mono card
  373.  
  374.     if (OPEN) mclose(n);
  375.  
  376.     OPEN = 1;
  377.     ROW = row;
  378.     COL = col;
  379.     WIDTH = width;
  380.     HEIGHT = height;
  381.  
  382.     for (row=-1; row<HEIGHT+1; row++ )
  383.         for (col=-1; col<WIDTH+1; col++ )  {
  384.             CHAR(row,col) = 32;
  385.             ATTR(row,col) = 7;
  386.             XCHAR(row,col) = 32;
  387.             XATTR(row,col) = 7;
  388.         }
  389.  
  390.     drawbox(n);
  391.     CROW=-1; CCOL=0;
  392.     _mprintf( n, title );
  393.     CROW=0; CCOL=0;
  394.     msetcursor( ROW+CROW, COL+CCOL );
  395.  
  396. }
  397.  
  398. #pragma aux mono_present value [eax] modify [bx] = \
  399.     "mov    ax,1a00h"    \
  400.     "int    10h"            \    
  401.     "mov    eax,-1"        \    
  402.     "cmp    bl,1"            \
  403.     "je    got_it"        \
  404.     "cmp    bh,1"            \
  405.     "je    got_it"        \
  406.     "xor    eax,eax"        \    
  407. "got_it:";
  408.  
  409.  
  410. int minit()
  411. {
  412.     short n;
  413.     static initialized=0;
  414.     //short col, row;
  415.  
  416.     if (! mono_present()) return 0;    //error! no mono card
  417.  
  418.     if (initialized)
  419.         return 1;
  420.  
  421.     initialized=1;
  422.  
  423.     monoscreen = (struct mono_element (*)[25][80])0xB0000;
  424.  
  425.     n=0;
  426.     OPEN=1;
  427.     ROW=2;
  428.     COL=0;
  429.     WIDTH=80;
  430.     HEIGHT=24;
  431.     CCOL=0;
  432.     CROW=0;
  433.  
  434.     mclear(0);
  435.  
  436.     for (n=1; n<MAX_NUM_WINDOWS; n++ )  {
  437.         OPEN = 0;
  438.         ROW = 2;
  439.         COL = 1;
  440.         WIDTH=78;
  441.         HEIGHT=23;
  442.         CROW=0;
  443.         CCOL=0;
  444.     }
  445.  
  446.     return -1;    //everything ok
  447. }
  448.  
  449. 
  450.