home *** CD-ROM | disk | FTP | other *** search
- #include "stdio.h"
- #include "conio.h"
- #include "dos.h"
- #include "process.h"
- #include "malloc.h"
- #include "io.h"
-
- void main(int,char *[]);
- void print_byte(char);
- void draw_point(int,int,int);
- void set_mode(int);
-
- void main ( argc , argv )
-
- int argc;
- char *argv[];
- {
- FILE *handle;
- long filesize;
- char *buffer , *ptr;
- unsigned idx , line_num , pixel;
- unsigned char first_byte , second_byte;
- unsigned char mask , color , first_bit , second_bit;
-
- /* MAKE SURE A FILE NAME WAS SPECIFIED ON THE COMMAND LINE. */
-
- if (argc < 2)
- {
- printf("\nMust specify name of file to be printed.");
- exit(1);
- }
-
- /* OPEN THE FILE. */
-
- if ((handle = fopen(argv[1],"rb")) == NULL)
- {
- printf("\nCannot open %s.",argv[1]);
- exit(1);
- }
-
- /* DETERMINE THE FILE SIZE, AND ALLOCATE A BUFFER TO HOLD IT. */
-
- filesize = filelength(fileno(handle));
- if ((filesize > 65535L) || ((buffer = malloc((unsigned)filesize)) == NULL))
- {
- printf("\nInsufficient memory.");
- fclose(handle);
- exit(1);
- }
-
- /* READ THE FILE INTO THE BUFFER. */
-
- if (fread(buffer,sizeof(char),(unsigned)filesize,handle) != (unsigned)filesize)
- {
- printf("\nError reading %s.",argv[1]);
- fclose(handle);
- exit(1);
- }
-
- /* CLOSE THE FILE. */
-
- fclose(handle);
-
- /* PRINT THE FIRST THREE BYTES OF THE FILE,
- WHICH SET THE LINE SPACING ON THE PRINTER. */
-
- for (idx = 0 , ptr = buffer; idx < 3; idx++ , ptr++)
- print_byte(*ptr);
-
- /* SET THE VIDEO MODE. */
-
- set_mode(4);
-
- /* THE IMAGE IS DIVIDED INTO 25 LINES, EACH OF WHICH IS EIGHT PIXELS HIGH.
- GO THROUGH ALL 25, PRINTING AND DISPLAYING. */
-
- for (line_num = 0; line_num < 25; line_num++)
- {
-
- /* THE FIRST THING ON EACH LINE IS A FOUR-BYTE CONTROL SEQUENCE,
- WHICH SETS UP THE PROPER GRAPHICS MODE ON THE PRINTER. */
-
- for (idx = 0; idx < 4; idx++ , ptr++)
- print_byte(*ptr);
-
- /* THE NEXT 640 BYTES OF THE LINE CONSISTS OF 320 PAIRS OF BYTES.
- BY LOOKING AT A PARTICULAR BIT FROM THE FIRST BYTE, AND THE
- CORRESPONDING BIT FROM THE SECOND BYTE, YOU CAN TELL WHAT
- COLOR THE PIXEL ON THE SCREEN SHOULD BE. */
-
- for (idx = 0; idx < 320; idx++ , ptr += 2)
- {
- print_byte(first_byte = *ptr);
- print_byte(second_byte = *(ptr+1));
-
- for (pixel = 0 , mask = 0x80; pixel < 8; pixel++ , mask >>= 1)
- {
- first_bit = (first_byte & mask) >> (7-pixel);
- second_bit = (second_byte & mask) >> (7-pixel);
- color = (first_bit << 1) | second_bit;
- draw_point(idx,line_num*8+pixel,color);
- }
- } /* END OF FOR (IDX) */
-
- /* THE LAST THING ON EACH LINE IS A CARRIAGE RETURN AND LINE FEED. */
-
- for (idx = 0; idx < 2; idx++ , ptr++)
- print_byte(*ptr);
- } /* END OF FOR (LINE_NUM) */
-
- /* NOW PRINT THE LAST THREE BYTES OF THE FILE,
- WHICH RESET THE LINE SPACING ON THE PRINTER. */
-
- for (idx = 0; idx < 3; idx++ , ptr++)
- print_byte(*ptr);
-
- /* FREE THE BUFFER. */
-
- free(buffer);
-
- /* WAIT FOR A KEYSTROKE, AND THEN EXIT. */
-
- getch();
- exit(0);
- } /* END OF MAIN */
-
- void print_byte ( ch )
-
- char ch;
- {
- union REGS regs;
-
- regs.x.dx = 0;
- regs.h.ah = 0;
- regs.h.al = ch;
- int86(0x17,®s,®s);
-
- return;
- } /* END OF PRINT_BYTE */
-
-
- void draw_point( col , row , color)
-
- int col;
- int row;
- int color;
- {
- union REGS registers;
-
- registers.x.dx = row;
- registers.x.cx = col;
- registers.h.al = (unsigned char)color;
- registers.h.ah = 0x0C;
-
- int86(0x10,®isters,®isters);
- return;
- }
-
- void set_mode ( mode )
-
- int mode;
- {
- union REGS registers;
-
- registers.h.ah = 0;
- registers.h.al = (unsigned char)mode;
-
- int86(0x10,®isters,®isters);
- return;
- }
-
-
-