home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <dos.h>
- #include <string.h>
- #include "screen.h"
-
- go_to( row, column)
- int row;
- int column;
- {
- union REGS inregs;
- union REGS outregs;
-
- inregs.h.ah=2;
- inregs.h.bh=0;
- inregs.h.dh=row;
- inregs.h.dl=column;
- int86(0x10,&inregs,&outregs);
- return(1);
- }
-
- now_cursor(x,y)
- int *x,*y;
- {
- union REGS r;
-
- r.h.ah=3;
- r.h.bh=0;
- int86(0x10,&r,&r);
- *x = r.h.dh;
- *y = r.h.dl;
- return;
- }
-
- color_puts(s,color)
- char *s;
- int color;
- {
- union REGS r;
- int x,y,z;
-
- now_cursor(&x,&z);
- y=z;
- while (*s) {
- if (*s=='\n') {
- s++;
- x++;
- y=z;
- continue;
- }
- go_to(x,y);
- r.h.ah=9;
- r.h.al=*s++;
- r.h.bl=color;
- r.h.bh=0;
- r.x.cx=1;
- int86(0x10,&r,&r);
- y++;
- }
- go_to(x,y);
- return;
- }
- getcc(){
- union REGS r;
- r.h.ah=0;
- int86(0x16,&r,&r);
- if (r.h.al==27) exit(0);
- if (r.h.al) return(r.h.al);
- return(r.x.ax);
- }
-
- clear_win(startx,starty,endx,endy,action,line)
- int startx,starty;
- int endx,endy;
- int action,line;
- {
- union REGS r;
-
- r.h.ah=action;
- r.h.al=line;
- r.x.bx=0x0700;
- r.h.ch=startx;
- r.h.cl=starty;
- r.h.dh=endx;
- r.h.dl=endy;
- int86(0x10,&r,&r);
- return;
- }
-
-
- gframe(startx,starty,endx,endy,sss,color)
- int startx,starty;
- int endx,endy;
- int sss;
- int color;
- {
- static char dd[3][6][3]={
- "⌐Ñ","⌐º","⌐│","⌐╖","⌐╗","⌐┐",
- "⌐ñ","⌐ª","⌐░","⌐┤","⌐╕","⌐╝" ,
- " "," "," "," "," "," "
- };
- int row,col;
- char *s;
-
- clear_win(startx,starty,endx,endy,6,0);
- go_to(startx,starty);
- color_puts(dd[sss][2],color);
- for(col=starty+2; col<endy; col+=2){
- go_to(startx,col);
- color_puts(dd[sss][0],color);
- }
- go_to(startx,endy);
- color_puts(dd[sss][3],color);
-
- for(row=startx+1; row<endx; ++row){
- go_to(row,starty);
- color_puts(dd[sss][1],color);
- go_to(row,endy);
- color_puts(dd[sss][1],color);
- go_to(row,starty+2);
- }
- go_to(endx,starty);
- color_puts(dd[sss][4],color);
-
- for(col=starty+2; col<endy; ++col,++col){
- go_to(endx,col);
- color_puts(dd[sss][0],color);
- }
- go_to(endx,endy);
- color_puts(dd[sss][5],color);
- return;
- }
- read_string(string,length)
- char *string;
- int length;
- {
- char middstr[41];
- int ctc,charact;
- int x,y;
- for (ctc=0;ctc<20;ctc++) middstr[ctc]='\0';
- ctc=0;
- while (ctc<length-1)
- {
- charact=getchb();
- if (charact==13) break;
- if ((charact==8)&&(ctc>0)) {
- now_cursor(&x,&y);
- go_to(x,y-1); printf(" ");
- go_to(x,y-1); middstr[--ctc]='\0';
- continue;
- }
- if (charact<=30 || charact>=128) continue;
- printf("%c",charact);
- middstr[ctc++]=charact;
- }
- if (strcmp(middstr,NULL)!=0)
- strcpy(string,middstr);
- return(0);
- }
-
- getchb()
- {
- union REGS regs;
- int t,m;
- regs.x.ax=0;
- int86(0x16,®s,®s);
- t=regs.x.ax & 0x00ff;
- m=(regs.x.ax-t)/256;
- if (t!=0) return(t);
- return(m+200);
- }
- oneline(pos,fixlen,dislen,fldin)
- int pos,fixlen,dislen;
- char *fldin;
- {
- int in,count=0,i,insert=1,sum;
- int row,col;
- char *str;
- char *tstr;
- in=strlen(fldin);
- if (in!=0){
- for (in=0;fldin[in]!='\0'&&fldin[in]!='\n';in++);
- fldin[in]='\0';}
- tstr=(char *)malloc(sizeof(char)*(dislen+1));
- ncpy(tstr,fldin,0,dislen);
- row=pos/100;
- col=pos%100;
- printf("\033[25;1H\033[0;34;41m%79s\033[25;5Hí√,í· ╥╞╢»╣Γ▒Ω Del ╔╛│²╫╓╖√ Ins ▓σ╚δ/╕▓╕╟ ESC ═╦│÷"," ");
- printf("\033[25;70H\033[0;0;0mIns");
- printf("\033[0;0;0m\033[%u;%uH%-.*s",row,col,dislen,tstr);
- for(;;)
- {
- printf("\033[%u;%uH",row,col);
- in=get_key();
- switch(in)
- {
- case KEY_RIGHT:
- if(fldin[col-pos%100+count]=='\0')
- {
- printf("\007");
- continue;
- }
- else
- {
- if(col<(pos%100+dislen-1))
- {
- col++;
- continue;
- }
- else
- {
- count++;
- if(count<strlen(fldin))
- ncpy(tstr,fldin,count,dislen);
- else
- ncpy(tstr,fldin,count,strlen(fldin));
- }
- }
- printf("\033[0;0;0m\033[%u;%uH%-.*s",pos/100,pos%100,dislen,tstr);
- continue;
- case KEY_LEFT:
- if(col==pos%100 && count==0)
- {
- printf("\007");
- continue;
- }
- else
- {
- if(col>pos%100)
- {
- col--;
- continue;
- }
- else
- {
- count--;
- ncpy(tstr,fldin,count,dislen);
- }
- }
- printf("\033[0;0;0m\033[%u;%uH%-.*s",pos/100,pos%100,dislen,tstr);
- continue;
- case KEY_INSERT : if (insert==0)
- {
- printf("\033[25;70H\033[0;0;0mIns\033[0;33;46m");
- insert=1;
- }
- else
- {
- printf("\033[25;70H\033[0;37;41m \033[0;33;46m");
- insert=0;
- }
- break;
- case Del:
- for(i=0;fldin[i]!='\0';i++);sum=i;
- if(sum==0||fldin[col-(pos%100)+count]=='\0')
- {
- printf("\007");
- continue;
- }
- for(i=col-(pos%100)+count;i<sum;i++)
- fldin[i]=fldin[i+1];
- ncpy(tstr,fldin,count,dislen);
- printf("\033[0;0;0m\033[%u;%uH%-.*s ",pos/100,pos%100,dislen,tstr);
- continue;
- case Backspace:
- for(i=0;fldin[i]!='\0';i++);sum=i;
- if(sum==0)
- {
- printf("\007");
- continue;
- }
- if(col<=pos%100)
- {
- printf("\007");
- continue;
- }
- for(i=col-(pos%100)+count;i<=sum;i++)
- fldin[i-1]=fldin[i];
- fldin[i-1]='\0';
- ncpy(tstr,fldin,count,dislen);
- printf("\033[0;0;0m\033[%u;%uH%-.*s ",pos/100,pos%100,dislen,tstr);
- col--;
- continue;
- case KEY_ESC:
- case KEY_ENTER:free(tstr);return(0);
- default:if((in&0x00ff)==13) {free(tstr);return(0);} /* Another Enter Key */
- if((unsigned char)in==0)continue;
- for(i=0;fldin[i]!='\0'&&fldin[0]!='\0';i++);sum=i;
- if(sum>=fixlen)
- {
- printf("\033[25;1H\033[1;36;41m┐φ╢╚│¼│÷╖╢╬º\033[0;0;7m\007");
- continue;
- }
- if(insert==1)
- {
- for(i=sum;i>=col-pos%100+count;i--)
- fldin[i+1]=fldin[i];
- fldin[i+1]=(char)in;
- ncpy(tstr,fldin,count,dislen);
- }
- else
- {
- fldin[col-pos%100+count]=(char)in;
- ncpy(tstr,fldin,count,dislen);
- fldin[sum+1]='\0';
- }
- if(col++==(pos%100+dislen))
- {
- col=pos%100+dislen;
- count++;
- if(count<strlen(fldin))
- ncpy(tstr,fldin,count,dislen);
- else
- ncpy(tstr,fldin,count,strlen(fldin));
- }
- printf("\033[0;0;0m\033[%u;%uH%-.*s",pos/100,pos%100,dislen,tstr);
- continue;
- }
- }
- }
-
-
- ncpy(tstr,fldin,start,no)
- char *tstr,*fldin;
- int start,no;
- {int i=0;
- if(start!=0) for(i=0;i<start;i++) fldin++;
- for(i=start;(i<start+no && (*fldin)!='\0');i++) *tstr++=*fldin++;
- *tstr='\0';
- }
-
- get_key()
- { union REGS r;
- r.h.ah=0;
- int86(0x16,&r,&r);
- return(r.x.ax);
- }