home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / REND.LZH / REND / CRTVGA.C < prev    next >
C/C++ Source or Header  |  1996-07-24  |  3KB  |  159 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4. #include <stdarg.h>
  5.  
  6. #include "reader.h"
  7. #include "glib.h"
  8. #include "rend.h"
  9.  
  10. #include <grdriver.h>
  11. #include <grx20.h>
  12.  
  13. char    *program = "Do-GA C.G.A System Rendering Program for AT/VGA+go32" ;
  14.  
  15. #define TOPLINE 64
  16.  
  17. int width, height;
  18. static int textx, texty;
  19. static    int        video_mode  = 0;
  20. static int initflag = FALSE;
  21.  
  22. static int cBlack, cWhite;
  23.  
  24. void crtexit(void)
  25. {
  26.     if (initflag != FALSE) {
  27.         union    REGS    regs ;
  28.  
  29. /*        GrSetMode(GR_default_text);*/
  30.  
  31.         regs.h.ah = 0 ;
  32.         regs.h.al = video_mode ;
  33.         int86( 0x10, ®s, ®s );
  34.  
  35.         initflag = FALSE;
  36.     }
  37. }
  38.  
  39. /*    CRTの初期化    */
  40. void    crtinit( line )
  41. int        line ;
  42. {
  43. #if 0
  44.     video_mode = *(char*)( 0xE0000000 | 0x449 );
  45.     GrSetMode(GR_width_height_color_graphics, 640, 480, 256);
  46.     GrSetRGBcolorMode();
  47. /*
  48.     width = GrScreenX();
  49.     height = GrScreenY();
  50. */
  51.  
  52.     width = 640;
  53.     height = 480;
  54.     GrFilledBox(0, 0, width-1, height-1, 0);
  55. #else
  56.     union REGS regs;
  57.  
  58.     regs.h.ah = 0x0f;
  59.     int86(0x10, ®s, ®s);
  60.     video_mode = regs.h.al;
  61.  
  62.     atexit(crtexit);
  63.  
  64.     regs.h.ah = 0;
  65.     regs.h.al = 0x01;
  66.     int86(0x10,®s,®s);
  67.  
  68. #ifdef COLOR256
  69.     GrSetMode(GR_width_height_color_graphics, 640, 480, 256);
  70. #else
  71.     GrSetMode(GR_width_height_color_graphics, 640, 480, 32768);
  72. #endif
  73.     GrSetRGBcolorMode();
  74.  
  75.     width = GrScreenX();
  76.     height = GrScreenY();
  77.  
  78.     GrClearScreen(GrBlack());
  79. /*    atexit(crtexit);*/
  80. #endif
  81.     initflag = TRUE;
  82. }
  83.  
  84. void crtmessage(char *str)
  85. {
  86.     extern int uflag;
  87.     if (uflag) {
  88.         fputs(str, stderr);
  89.         fputc('\n', stderr);
  90.     } else {
  91.         GrTextXY(textx, texty, str, GrWhite(), 0);
  92.         texty+=16;
  93.     }
  94. }
  95.  
  96. /*    CRTのクリア    */
  97. void    crtclr()
  98. {
  99.     GrClearScreen(GrBlack());
  100.     textx = texty = 0;
  101. }
  102.  
  103. static inline int X68tobyte(unsigned short c)
  104. {
  105.     return ((c & 0xe000) >> 11) | ((c & 0x0700) >> 3) | ((c & 0x0030) >> 4);
  106. }
  107.  
  108. static inline int X68toshort(unsigned short c)
  109. {
  110.     return ((c & 0xf800) >> 6) | ((c & 0x07c0) << 4) | ((c & 0x003e) >> 1);
  111. }
  112.  
  113. /*    CRT出力    */
  114. void    crtout( framebuf, xlen, y )
  115. unsigned short    *framebuf ;
  116. int        xlen ;
  117. int        y ;
  118. {
  119.     int x;
  120.     for (x = 0; x < xlen; ++x) {
  121. #ifdef COLOR256
  122.         GrPlot(x, y+TOPLINE, X68tobyte(*framebuf++));
  123. #else
  124.         GrPlotNC(x, y+TOPLINE, X68toshort(*framebuf++));
  125. #endif
  126.     }
  127. }
  128.  
  129.  
  130.  
  131.  
  132. void    crtline( x1, y1, x2, y2 )
  133. int        x1, y1, x2, y2 ;
  134. {
  135.     GrLineNC(x1, y1+TOPLINE, x2, y2+TOPLINE, GrWhite());
  136. }
  137.  
  138. static char buf[1024];
  139.  
  140.  
  141. int     fprintf(FILE * fp, const char * format, ...)
  142. {
  143.     int l;
  144.     va_list arglist;
  145.  
  146.     va_start(arglist, format);
  147.     l = vsprintf(buf, format, arglist);
  148.     va_end(arglist);
  149.  
  150.     if (initflag && (fp == stderr || fp == stdout)) {
  151.         crtmessage(buf);
  152.     } else {
  153.         fputs(buf, fp);
  154.     }
  155.     return l;
  156. }
  157.  
  158.  
  159.