home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctech / hlsrc / hlstart.c < prev    next >
C/C++ Source or Header  |  1988-09-09  |  3KB  |  169 lines

  1. /*+
  2.     Name:    hlstart.c
  3.     Date:    12-Jul-1988
  4.     Author:    Kent J. Quirk
  5.         (c) Copyright 1988 Ziff Communications Co.
  6.     Abstract:    Displays the starting screen for the PC Tech Journal
  7.         benchmarks.
  8.     History:    09-Sep-88   kjq     Version 1.00
  9. -*/    
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <graph.h>
  14. #include <conio.h>
  15.  
  16. #include "hl.h"
  17.  
  18. typedef unsigned char BYTE;
  19. typedef unsigned int WORD;
  20.  
  21. typedef struct {
  22.     BYTE pcx_id;
  23.     BYTE version;
  24.     BYTE encoding;
  25.     BYTE bpp;
  26.     WORD upleftx, uplefty;
  27.     WORD lorightx, lorighty;
  28.     WORD display_xres, display_yres;
  29.     BYTE palette[48];
  30.     BYTE reserved;
  31.     BYTE nplanes;
  32.     WORD bytesperline;
  33.     BYTE reserved2[60];
  34. } PCX_HDR;
  35.  
  36. PCX_HDR header;
  37. struct videoconfig config;
  38. struct videoconfig far *configp = &config;
  39.  
  40. #define COMPRESSED 0xC0
  41. #define MASK 0x3F
  42.  
  43. int line, bc;
  44.  
  45. /**** d r a w d a t a ****
  46.     Abstract:    Given a byte and a length, this draws that number of
  47.         pixels onto the screen.
  48. ****************************/
  49. void drawdata(BYTE c, int len)
  50. {
  51.     int ls, start, end;
  52.  
  53.     _setcolor(0xFF);
  54.     ls = ((int)c << 8) + c;
  55.     _setlinestyle(ls);
  56.     start = bc * 8;
  57.     end = start + len * 8;
  58.     if (end <= header.bytesperline * 8)
  59.     {
  60.     _moveto(start+1, line);
  61.     _lineto(end, line);
  62.     bc += len;
  63.     }
  64.     else
  65.     {
  66.     _moveto(start+1, line);
  67.     _lineto(header.bytesperline * 8, line);
  68.     _moveto(1, ++line);
  69.     bc = (end - (header.bytesperline * 8)) / 8;
  70.     _lineto(bc * 8, line);
  71.     ++bc;
  72.     }
  73.     if (bc >= header.bytesperline)
  74.     {
  75.     bc = 0;
  76.     ++line;
  77.     }
  78. }
  79.  
  80. /**** d i s p l a y _ p i c t u r e ****
  81.     Abstract:    Reads a PCX file and displays its data
  82. ****************************/
  83. void display_picture(FILE *f, long datalen)
  84. {
  85.     int len;
  86.     char c;
  87.     char *data, *endptr;
  88.  
  89.     data = malloc((int)datalen);
  90.     endptr = data + datalen;
  91.     fread(data, 1, (int)datalen, f);
  92.     _clearscreen(_GCLEARSCREEN);
  93.     
  94.     line = 1;
  95.     bc = 0;
  96.     while (data < endptr)
  97.     {
  98.     c = *data++;
  99.     if ((c & COMPRESSED) == COMPRESSED)
  100.     {
  101.         len = c & MASK;
  102.         c = *data++;
  103.         drawdata((char)c, len);
  104.     }
  105.     else
  106.     {
  107.         drawdata((char)c, 1);
  108.     }
  109.     }
  110. }
  111.  
  112. main(int argc, char *argv[])
  113. {
  114.     FILE *f;
  115.     int i;
  116.     char fname[64];
  117.     long flen;
  118.  
  119.     if (argc > 1)
  120.     {
  121.     i = atoi(argv[1]);
  122.     if (_setvideomode(i) == 0)
  123.         return(1);
  124.     _getvideoconfig(&config);
  125.     }
  126.     else
  127.     {    
  128.     if (!init_video(configp))
  129.         return(1);
  130.     if (config.numxpixels == 320)        /* if low res CGA mode */
  131.     {
  132.         if (_setvideomode(_HRESBW) == 0)
  133.         return(1);
  134.         _getvideoconfig(&config);
  135.     }
  136.     }
  137.  
  138.     sprintf(fname, "TJ640%d.PCX", config.numypixels);
  139.  
  140.     if ((f = fopen(fname, "rb")) == NULL)
  141.     {     
  142.     _setvideomode(_DEFAULTMODE);
  143.     return(1);                /* can't find file */
  144.     }
  145.     fseek(f, 0L, SEEK_END);            /* measure length of file */
  146.     flen = ftell(f);
  147.     fseek(f, 0L, SEEK_SET);            /* and go back to top */
  148.     fread(&header, sizeof(header), 1, f);
  149.     
  150.     /* if made with color image, or wrong kind of file, abort */
  151.     if ((header.pcx_id != 0x0A) || (header.nplanes != 1))
  152.     {     
  153.     fclose(f);
  154.     _setvideomode(_DEFAULTMODE);
  155.     return(1);
  156.     }
  157.     
  158.     display_picture(f, flen - sizeof(header));
  159.     fclose(f);
  160.     while (!kbhit())
  161.     ;
  162.     
  163.     _setvideomode(_DEFAULTMODE);
  164.     if (getch() == 27)
  165.     return(2);
  166.     else
  167.     return(0);
  168. }
  169.