#include #include #include #include #include #include #include #include #include "kbd_keys.h" #include "ml.h" void printscreen(FILE *F, int x1, int y1, int x2, int y2, int ramka, char *header) #define put(c) fputc(c,F) #define NORMAL_WIDTH (18) #ifndef _ESC #define _ESC 27 #endif { int i,j,k,m,l1,l2,from,len,l; int b,mod,div; from = y1; l1 = y2; l2 = x2-x1+1; len = l2-1; len= (len / 8 + 1)*8; /* setvbuf(F,buffer,_IOFBF,BUF_LEN-10); */ mod = (len % 256); div =(len / 256); fprintf(F,"%c@%cA%c",_ESC,_ESC,8); if(ramka) { fputc(201,F); for(i=0; i < len/12; i++) fputc(205,F); fputc(187,F); fprintf(F,"\n"); } for(i = from/8; i <= l1/8; i++){ if(ramka) fputc(186,F); put(_ESC); put('L'); put(mod); put(div); for(j=x1; j < x1+len; j++) { for(k = 0,b = 0; k < 8 ; k++) b = b | ((((getpixel(j,i*8+k) != 0) && i*8+k < y2 && j < x2) << (7-k))); fputc(b,F); } if(ramka) fputc(186,F); fprintf(F,"%c2%cA%c\n",_ESC,_ESC,8); } if(ramka) { fputc(200,F); m=len/12; l=strlen(header); for(i=0; i < m; i++) { if(i >= m/2-l/2 && i < m/2-l/2+l) fputc(header[i+l/2-m/2],F); else fputc(205,F); } fputc(188,F); fprintf(F,"\n"); } fprintf(F,"\n%c",NORMAL_WIDTH); } void save_screen(char *fname, int x1, int y1, int x2, int y2) { int i,j; void *buf; FILE *F=fopen(fname,"wb"); buf=malloc(10000); if(buf) setvbuf(F,buf,_IOFBF,9990); fprintf(F,"%d %d %d %d;",x1,y1,x2,y2); for(i=x1; i <= x2; i++) for(j=y1; j <= y2; j++) fputc('a'+getpixel(i,j),F); fclose(F); if(buf) free(buf); } static int gr_initialized=0; void init_graph(char *path) { int gd,gm,gr; if(gr_initialized) return; gd=DETECT; gm=0; initgraph(&gd,&gm,path); if(gr=graphresult()) error(grapherrormsg(gr)); gr_initialized=1; } void close_graph(void) { if(gr_initialized) { closegraph(); gr_initialized=0; } } void show_sprite(int x, int y, POINT *sprite, char *pix_mem) { int i,xi,yi; for(i=0; sprite[i].x != END_SPRITE; i++) { xi=x+sprite[i].x; yi=y+sprite[i].y; pix_mem[i]=getpixel(xi,yi); putpixel(xi,yi,LIGHTRED); } } void restore_sprite(int x, int y, POINT *sprite, char *pix_mem) { int i,xi,yi; for(i=0; sprite[i].x != END_SPRITE; i++) { xi=x+sprite[i].x; yi=y+sprite[i].y; putpixel(xi,yi,pix_mem[i]); } } int sprite_len(POINT *sprite) { int i; for(i=0; sprite[i].x != END_SPRITE; i++); return i; }