Delphi & Pascal (česká wiki)
/***************************************************************************** * * * Subor OKNO.C * * * *****************************************************************************/ #include <dos.h> #include <stdlib.h> #include <alloc.h> #include "glob.h" #include "menu.h" #include "video.h" #include "okno.h" #include "util.h" struct Okno far * _okno=NULL; struct Rmenu Rmenu={0,{NULL}}; char far *_ramcek[]={ " ", "ÚÄżłŮÄŔł", "Ő͸łžÍÔł", "ÉÍťşźÍČş"}; //************************************************************************// // ZISTI_SURADNICE // // 30.10.1997 // //************************************************************************// void zisti_suradnice(struct Menu *menu,int *zx,int *zy,int *rx,int *ry) { *zx=menu->lavy; *zy=menu->horny; *rx=zisti_sirku_okna(menu->polozky); *ry=zisti_vysku_okna(menu->polozky); if(*rx>=_stlpcov) *rx=_stlpcov-2; if(*ry>=_riadkov) *rx=_riadkov; if(*zx+*rx>=_stlpcov) *zx-=(*zx+*rx)-_stlpcov; if(*zy+*ry>=_riadkov) *zy-=(*zy+*ry)-_riadkov; } //************************************************************************// // ZARAD_MENU // // 30.10.1997 // //************************************************************************// void zarad_menu(Menu *menu) { if(Rmenu.pocet <MAXRMENU) Rmenu.menu[Rmenu.pocet++]=menu; } //************************************************************************// // ZRUS_MENU // // 30.10.1997 // //************************************************************************// void zrus_menu(void) { if(Rmenu.pocet >0) Rmenu.pocet--; } //************************************************************************// // REDRAW_MENU // // 30.10.1997 // //************************************************************************// void redraw_menu(void) { int i; tlac_vodorovne_menu(&hlavne_menu); zvyrazni_vodorovne_menu(&hlavne_menu); tlac_riadok_help(hlavne_menu.polozky[hlavne_menu.posledna_volba].spodny_riadok,hlavne_menu.attr_spodneho_riadku,hlavne_menu.attr_hot_key); for(i=0;i<Rmenu.pocet;++i) redraw_podmenu(Rmenu.menu[i]); } //************************************************************************// // REDRAW_PODMENU // // 30.10.1997 // //************************************************************************// void redraw_podmenu(Menu *menu) { register int i; int zx,zy,rx,ry; if(menu == NULL) return; zisti_suradnice(menu,&zx,&zy,&rx,&ry); nakresli_okno(zx,zy,zx+rx,zy+ry,menu->attr_okna,menu->attr_okraja,menu->typ_okraja); i=0; while(menu->polozky[i].text!=NULL) tlac_riadok_menu(menu->lavy,menu->horny,i++,menu,rx-2); } //************************************************************************// // NAKRESLI_OKNO // // 30.10.1997 // //************************************************************************// void nakresli_okno(unsigned int lavy,unsigned int horny, unsigned int pravy,unsigned int dolny, unsigned char attr_okna,unsigned char attr_okraja, unsigned char typ_okraja) { vypln_okno(lavy+1,horny+1,pravy-1,dolny-1,' ',attr_okna); ramcek(lavy,horny,pravy-lavy,dolny-horny,attr_okraja,typ_okraja); tien(lavy,horny,pravy-lavy,dolny-horny,0x08); } //************************************************************************// // OTVOR_OKNO // // 30.10.1997 // //************************************************************************// int otvor_okno(unsigned int lavy,unsigned int horny, unsigned int pravy,unsigned int dolny, unsigned char attr_okna,unsigned char attr_okraja, unsigned char typ_okraja) { if(zarad_okno(lavy,horny,pravy-lavy+2,dolny-horny+1)!=TRUE)return FALSE; nakresli_okno(lavy,horny,pravy,dolny,attr_okna,attr_okraja,typ_okraja); return TRUE; } //************************************************************************// // ZARAD_OKNO // // 30.10.1997 // //************************************************************************// int zarad_okno(unsigned int lavy,unsigned int horny,unsigned int sirka,unsigned int vyska) { struct Okno far *p; if((p=(struct Okno far *)farmalloc(sizeof(Okno)))==NULL)return FALSE; if((p->data=(unsigned int far *)farmalloc(sirka*vyska*sizeof(int)))==NULL) { farfree(p); pamet(); return FALSE; } pamet(); p->lavy=lavy; p->horny=horny; p->sirka=sirka; p->vyska=vyska; uloz_okno(lavy,horny,sirka,vyska,p->data); p->prev=_okno; _okno=p; return TRUE; } //************************************************************************// // ZATVOR_OKNO // // 30.10.1997 // //************************************************************************// int zatvor_okno(void) { struct Okno far * p; if(_okno!=NULL) { obnov_okno(_okno->lavy,_okno->horny,_okno->sirka,_okno->vyska,_okno->data); p=_okno; _okno=_okno->prev; farfree(p->data); farfree(p); pamet(); return TRUE; } return FALSE; } //************************************************************************// // ZATVOR_OKNO1 // // // 30.10.1997 // //************************************************************************// int zatvor_okno1(void) { struct Okno far * p; if(_okno!=NULL) { obnov_okno1(_okno->lavy,_okno->horny,_okno->sirka,_okno->vyska,_okno->data); p=_okno; _okno=_okno->prev; farfree(p->data); farfree(p); pamet(); return TRUE; } return FALSE; } //************************************************************************// // ULOZ_OKNO // // 30.10.1997 // //************************************************************************// void uloz_okno(unsigned int lavy,unsigned int horny,unsigned int sirka,unsigned int vyska,unsigned int far *mem) { _BX=2*(_stlpcov*horny+lavy); _CH=sirka; _CL=(_stlpcov-sirka)*2; _DL=vyska; _DH=_CH; _SI=FP_OFF(mem); asm push es asm push ds _ES=VIDEOSEGMENT; _DS=FP_SEG(mem); n1: asm mov ch,dh n2: asm mov ax,es:[bx] asm mov ds:[si],ax asm inc si asm inc si asm inc bx asm inc bx asm dec ch asm jnz n2 asm add bx,cx asm dec dl asm jnz n1 asm pop ds asm pop es return; } //************************************************************************// // OBNOV_OKNO // // // 30.10.1997 // //************************************************************************// void obnov_okno(unsigned int lavy,unsigned int horny,unsigned int sirka,unsigned int vyska,unsigned int far *mem) { _BX=2*(_stlpcov*horny+lavy); _CH=sirka; _CL=(_stlpcov-sirka)*2; _DL=vyska; _DH=_CH; _SI=FP_OFF(mem); asm push es asm push ds _ES=VIDEOSEGMENT; _DS=FP_SEG(mem); n1: asm mov ch,dh n2: asm mov ax,ds:[si] asm mov es:[bx],ax asm inc si asm inc si asm inc bx asm inc bx asm dec ch asm jnz n2 asm add bx,cx asm dec dl asm jnz n1 asm pop ds asm pop es return; } //************************************************************************// // OBNOV_OKNO1 // // 30.10.1997 // //************************************************************************// void obnov_okno1(unsigned int lavy,unsigned int horny,unsigned int sirka,unsigned int vyska,unsigned int far *mem) { register unsigned int r; register unsigned int s; while(1) { _BX=2*(_stlpcov*horny+lavy); _CH=sirka; _CL=(_stlpcov-sirka)*2; _DL=vyska; _DH=_CH; _SI=FP_OFF(mem); asm push es asm push ds _ES=VIDEOSEGMENT; _DS=FP_SEG(mem); n1: asm mov ch,dh n2: asm mov ax,ds:[si] asm cmp ax,es:[bx] asm jnz n3 asm inc si asm inc si asm inc bx asm inc bx asm dec ch asm jnz n2 asm add bx,cx asm dec dl asm jnz n1 asm pop ds asm pop es return; n3: asm pop ds asm pop es n4: s=rand()%sirka; r=rand()%vyska; if(peek(VIDEOSEGMENT,2*(_stlpcov*(horny+r)+lavy+s))!=peek(FP_SEG(mem),FP_OFF(mem)+2*(sirka*r+s))) poke(VIDEOSEGMENT,2*(_stlpcov*(horny+r)+lavy+s),peek(FP_SEG(mem),FP_OFF(mem)+2*(sirka*r+s))); else goto n4; delay(1); } } //************************************************************************// // RAMCEK // // 30.10.1997 // //************************************************************************// void ramcek(unsigned int lavy,unsigned int horny,unsigned int sirka,unsigned int vyska,unsigned char attr,unsigned char typ_ramceka) { _SI=FP_OFF(_ramcek[typ_ramceka]); _DI=FP_SEG(_ramcek[typ_ramceka]); _BX=2*(_stlpcov*horny+lavy); _CL=sirka-2; _DX=(_stlpcov-sirka+1)*2; _CH=vyska-2; asm push es asm push ds _ES=VIDEOSEGMENT; _AH=attr; asm mov ds,di asm push cx asm mov ch,0 asm inc cl asm shl cx,1 asm mov di,cx asm pop cx asm mov al,ds:[si] asm mov es:[bx],ax asm inc bx asm inc bx asm mov al,ds:1[si] asm push cx n1: asm mov es:[bx],ax asm inc bx asm inc bx asm dec cl asm jnz n1 asm pop cx asm mov al,ds:2[si] asm mov es:[bx],ax asm add bx,dx asm mov al,ds:3[si] n2: asm mov es:[bx],ax asm add bx,di asm mov es:[bx],ax asm add bx,dx asm dec ch asm jnz n2 asm mov al,ds:6[si] asm mov es:[bx],ax asm inc bx asm inc bx asm mov al,ds:5[si] n3: asm mov es:[bx],ax asm inc bx asm inc bx asm dec cl asm jnz n3 asm mov al,ds:4[si] asm mov es:[bx],ax asm add bx,dx asm mov al,ds:7[si] asm pop ds asm pop es } //************************************************************************// // TIEN // // 30.10.1997 // //************************************************************************// void tien(unsigned int lavy,unsigned int horny,unsigned int sirka,unsigned int vyska,unsigned char attr) { _DI=sirka*2-2; _BX=2*(_stlpcov*(horny+1)+lavy+sirka)+1; _DX=(_stlpcov-2)*2; _CH=vyska-1; _CL=sirka+1; asm push es _ES=VIDEOSEGMENT; _AL=attr; n1: asm mov es:[bx],al asm inc bx asm inc bx asm mov es:[bx],al asm inc bx asm inc bx asm add bx,dx asm dec ch asm jnz n1 asm sub bx,di n2: asm mov es:[bx],al asm inc bx asm inc bx asm dec cl asm jnz n2 asm pop es } /*---------------------------------END--------------------------------------*/