Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабораторная работа №2

.CPP
Скачиваний:
13
Добавлен:
01.05.2014
Размер:
1.62 Кб
Скачать
#include "conio.h"
#include "dos.h"
#include "mem.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
union word{
  struct{
    char fh:8;
    char fl:8;
   }b;
  int fx:16;
};

char getcurpage()
{
  char _t;
  asm{
   mov ah,0xf
   int 0x10
   mov _t,bh;
  };
  return _t;
};

void movexybios(char x, char y)
{
  char _t=getcurpage();
  asm{
      mov ah,0x02
      mov bh,_t
      mov dh, y
      mov dl, x
      int 0x10
  };
};

void printchar(char ch1,char attr)
{
  char _t=getcurpage();
  asm{
    mov ah,0x09
    mov al,ch1
    mov bl,attr
    mov bh,_t
    mov cx,0x1
    int 0x10
  };
};

char getmode()
{
  char a;
  movedata(0x0040,0x0049,FP_SEG(a),FP_OFF(a),1);
  return a;
};

void setmode(char m)
{
  asm{
    mov ah,0
    mov al,m
    int 0x10
  };
};

int main(void)
{
  char string[30];
  char vm,_vm;
  int di=1;
  int bb=0,b=0,c=0;
  for(char rep=' ';rep!=27;rep=getch())
  {
    printf("Enter string: ");
    scanf("%19s",string);
    int i=1;
    _vm=getmode();
    setmode(2);
    for(char ch=' ';ch!=27;(kbhit())&&(ch=getch()))
    {
      c+=(ch=='1')*(-1)+(ch=='2');
      ch=' ';
      for(int k=0;k<strlen(string);k++)
      {
	movexybios(5,i+k);
	printchar(string[k],(char)(c));
      };
      delay(90);
      for(k=0;k<strlen(string);k++)
      {
	movexybios(5,i+k);
	printchar('ю',0x00);
      };
      if((i+k>24)||(!i))
	di*=(-1);
      i+=di;
    };
    setmode(_vm);
    movexybios(1,1);
    printf("repeat? yes - any key; no - ESC");
    fflush(stdin);
  };
  return 0;
};