/* LOADSCRN.C */ /* Restore cursor location and screen from file */ /* Coding for TC 2.0 */ /* Coding by Albert Stein, Chemical Bank, 212-310-3927 Software Ideology PO Box 305, Brooklyn, NY 11204 Any comments are welcome. Enjoy! */ #include #include #include #include #include #include #define SETCUR 2 #define STATE 15 #define COLOR 1 #define MONO 0 #define COLOR_SEG 0xB800 #define MONO_SEG 0xB000 void load_data (unsigned char *filename); void read_screensize (int *rows, int *cols,int type); void read_screentype (int *type); void goyx (int row, int col); void syntax(void); int type; int row,col; int rows,cols; void main(int argc, char *argv[]) { if (argc == 1) { syntax(); exit (0); } read_screentype (&type); read_screensize (&rows,&cols,0); load_data (argv[1]); goyx (row,col); exit (0); } void load_data (unsigned char *filename) { FILE *inp; unsigned int seg,off; unsigned int line[266]; /* store up to 133 columns w/ attribs */ unsigned char far *pline = (void far *)line; unsigned int linesize; unsigned int i; if ( (inp=fopen (filename,"rb")) == NULL) { printf ("Fatal error on opening '%s'\n",filename); exit (1); } fread (&row,2,1,inp); fread (&col,2,1,inp); seg = (type == COLOR) ? COLOR_SEG : MONO_SEG; linesize = cols * 2; for (i=off=0; i < rows; i++,off += linesize) { fread (line,linesize,1,inp); movedata (FP_SEG(pline),FP_OFF(pline),seg,off,linesize); } fclose (inp); unlink (filename); } void read_screensize (int *rows, int *cols,int type) { union REGS regs; unsigned int value; unsigned int far *pvalue = &value; if (type == 1) { regs.h.ah = 0x0F; int86(0x10,®s,®s); *cols = regs.h.ah; switch (regs.h.al) { case 0x00: case 0x01: case 0x02: case 0x03: case 0x07: *rows = 25; break; default: printf ("Unexpected mode=0x%02x\n",regs.h.al); getch(); } } else { movedata (0x000,0x044A,FP_SEG(pvalue),FP_OFF(pvalue),2); *cols = *pvalue; /* this will return the total memory space in use */ movedata (0x000,0x044C,FP_SEG(pvalue),FP_OFF(pvalue),2); *rows = *pvalue / (*cols * 2); } } void goyx(int row, int col) /* uses bios call to position cursor at row,col */ { union REGS regs; regs.h.dh = row; regs.h.dl = col; regs.h.ah = SETCUR; regs.h.bh = 0x00; /* page # */ int86(0x10,®s,®s); } void read_screentype (int *type) { union REGS regs; regs.h.ah = 0x0F; int86(0x10,®s,®s); switch (regs.h.al) { case 0x00: case 0x01: case 0x02: case 0x03: *type = COLOR; break; case 0x07: *type = MONO; break; default: printf ("Unexpected mode=0x%02x\n",regs.h.al); getch(); } } void syntax() { printf ("Syntax: LOADSCRN filename\n" "Purpose: Restore cursor location and screen from a file\n" " Will work with 40/43/50 line screens too!\n"); }