嵌入汇编的绘图程序_C Programm_转载

#include"graphics.h"
int fir[14],sec[18],thi[18],fou[18],fiv[18],six[18],sev[18],eig[14];
fir[]={110,225,142,225,142,305,157,305,157,340,110,340,110,225};
sec[]={157,305,172,305,172,225,190,225,190,305,205,305,205,340,157,340,157,305};
thi[]={205,305,220,305,220,225,237,225,237,305,252,305,252,340,205,340,205,305};
fou[]={252,305,267,305,267,225,285,225,285,305,300,305,300,340,252,340,252,305};
fiv[]={300,305,315,305,315,225,333,225,333,305,348,305,348,340,300,340,300,305};
six[]={348,305,363,305,363,225,380,225,380,305,395,305,395,340,348,340,348,305};
sev[]={395,305,410,305,410,225,427,225,427,305hui,442,305,442,340,395,340,395,305};
eig[]={442,305,457,305,457,225,490,225,490,340,442,340,442,305};

/*定义正弦波数据数据区*/
asm    data1 db 80h,96h,0aeh,0c5h,0d8h,0e9h,0f5h,0fdh;
asm          db  0ffh,0fdh,0f5h,0e9h,0d8h,0c5h,0aeh,96h;
asm          db  80h,66h,4eh,38h,25h,15h,09h,04h;
asm          db  00h,04h,09h,15h,25h,38h,4eh,66h;
asm    time  db  120,106,94,89,79,70,63,59;
asm    msg  db    "Press ESC  EXIT:",0dh,0ah,24h;
asm    num  db  ?;
/*8个白键的矩形框的各顶点坐标存储空间*/
char  button;

void postpone_waiting1();
void postpone_waiting2();
void main(){
    int gdetect,gmode;
char *character_string="    PIANO  HEAVEN    ";
gdetect=DETECT;
initgraph(&gdetect,&gmode,"");
    setcolor(11);
settextstyle(0,0,3);
outtextxy(180,88,character_string);
    setcolor(11);
setlinestyle(0,0,3);
rectangle(95,145,505,355);
    setcolor(15);
setlinestyle(0,0,0);
rectangle(100,160,500,350);
setfillstyle(1,0);
bar(285,225,315,305);
bar(190,225,220,305);
bar(142,225,172,305);
bar(237,225,267,305);
bar(380,225,410,305);
bar(427,225,457,305);
bar(333,225,363,305);
    setfillstyle(1,15);
fillpoly(7,fir);
fillpoly(9,sec);
fillpoly(9,thi);
fillpoly(9,fou);
fillpoly(9,fiv);
fillpoly(9,six);
fillpoly(9,sev);
fillpoly(7,eig);
setcolor(0);
    line(300,305,300,340);
line(205,305,205,340);
line(157,305,157,340);
line(252,305,252,340);
line(395,305,395,340);
line(442,305,442,340);
line(348,305,348,340);
setcolor(1);
rectangle(110,225,490,340);
asm    mov dx,offset msg;
asm    mov ah,9;
asm    int 21h;
sss:
asm    mov ah,7;
asm    int 21h;
asm    mov button,al;
        if  (button=='1')
  { setfillstyle(1,4);
  fillpoly(7,fir);
  delay(2500);
  setfillstyle(1,15);
  fillpoly(7,fir);
  asm  jmp drawrec;
                }    
 
        if (button=='2')
  {setfillstyle(1,4);
                        fillpoly(9,sec);
  delay(2500);
  setfillstyle(1,15);
  fillpoly(9,sec);
  asm  jmp drawrec;
                        }
 
      if (button=='3')
  {setfillstyle(1,4);
                        fillpoly(9,thi);
    delay(2500);
    setfillstyle(1,15);
    fillpoly(9,thi);
    asm  jmp drawrec;
          }
      if (button=='4')
  {setfillstyle(1,4);
                        fillpoly(9,fou);
  delay(2500);
  setfillstyle(1,15);
  fillpoly(9,fou);
  asm  jmp drawrec;
          }
    if (button=='5')
  {setfillstyle(1,4);
                        fillpoly(9,fiv);
  delay(2500);
  setfillstyle(1,15);
  fillpoly(9,fiv);
  asm  jmp drawrec;
          }
        if (button=='6')
  {setfillstyle(1,4);
                        fillpoly(9,six);
  delay(2500);
  setfillstyle(1,15);
  fillpoly(9,six);
  asm jmp drawrec;
          }
    if (button=='7')
  {setfillstyle(1,4);
                        fillpoly(9,sev);
  delay(2500);
  setfillstyle(1,15);
  fillpoly(9,sev);
  asm  jmp drawrec;
          }
        if (button=='8')
  {setfillstyle(1,4);
                        fillpoly(7,eig);
    delay(2500);
    setfillstyle(1,15);
    fillpoly(7,eig);
  asm  jmp drawrec;
          }
        if (button=='r')
  {setfillstyle(1,4);
  bar(285,225,315,305);
  delay(2500);
  setfillstyle(1,0);
  bar(285,225,315,305);
  asm  jmp drawrec;
          }
          if (button=='w')
  {setfillstyle(1,4);
                        bar(190,225,220,305);
    delay(2500);
    setfillstyle(1,0);
    bar(190,225,220,305);
    asm  jmp drawrec;
          }
        if (button=='q')
  {setfillstyle(1,4);
                        bar(142,225,172,305);
    delay(2500);
    setfillstyle(1,0);
    bar(142,225,172,305);
    asm  jmp drawrec;
          }
      if (button=='e')
  {setfillstyle(1,4);
                        bar(237,225,267,305);
    delay(2500);
    setfillstyle(1,0);
    bar(237,225,267,305);
    asm  jmp drawrec;
    }
        
    if (button=='y')
  {setfillstyle(1,4);
                        bar(380,225,410,305);
    delay(2500);
    setfillstyle(1,0);
    bar(380,225,410,305);
    asm  jmp drawrec;
        
                        }
  if (button=='u')
  {setfillstyle(1,4);
                        bar(427,225,457,305);
    delay(2500);
    setfillstyle(1,0);
    bar(427,225,457,305);
    asm  jmp drawrec;
          }
      if (button=='t')
  { setfillstyle(1,4);
                          bar(333,225,363,305);
    delay(2500);
    setfillstyle(1,0);
    bar(333,225,363,305);
    asm  jmp drawrec;
                        }        
}
          rectangle(110,225,490,340);
drawrec:        rectangle(110,225,490,340);
asm    mov al,button;
asm    cmp al,1bh;  //ESC 退出
asm    je  exit;
asm    cmp al,30h;
asm    jg  jump;
asm    jmp sss;
jump:
asm    cmp al,38h;
asm    jg  compare;
asm    sub al,31h;
asm    mov num,al;
asm    mov cx,50;
asm    jmp  ddd;
compare:
asm    cmp al,71h;
asm    je result1;
asm    cmp al,77h;
asm    je result2;
asm    cmp al,65h;
asm    je result3;
asm    cmp al,72h;
asm    je result4;
asm    cmp al,74h;
asm    je result5;
asm    cmp al,79h;
asm    je result6;
asm    cmp al,75h;
asm    je result7;
asm    jmp sss;
result1:
asm    mov ah,239;
asm    call postpone_waiting2();
result2:
asm    mov ah,213;
asm    call postpone_waiting2();
result3:
asm    mov ah,189;
asm    call postpone_waiting2();
result4:
asm    mov ah,179;
asm    call postpone_waiting2();
result5:
asm    mov ah,159;
asm    call postpone_waiting2();
result6:
asm    mov ah,142;
asm    call postpone_waiting2();
result7:
asm    mov ah,127;
asm    jmp sss;
ddd:
asm    mov si,0;
lll:
asm    mov al,data1[si];
asm    mov dx,290h;
asm    out dx,al;
asm    call postpone_waiting1();
asm    inc si;
asm    cmp si,32;
asm    jl  lll;
asm    loop ddd;
asm    jmp sss;
exit:
asm    mov ah,4ch;  //返回DOS
asm    int 21h;
}
void postpone_waiting1(){
ccc:
asm      mov bx,offset time;  
asm      mov dx,283h; /*8253计数器0,工作方式0*/
asm      mov al,10h;
asm      out dx,al;
asm      mov dx,28bh; /*8255A口输入*/
asm      mov al,9bh;
asm      out dx,al;
asm      mov al,num;
asm      xlat;        //把(bx)+(al)-->al寄存器
asm      mov dx,280h;
asm      out dx,al;
kkk:
asm      mov dx,288h; //从8255 A口读一个字节
asm      in al,dx;  
asm      test al,01; //测试PA0口是不是1
asm      jz kkk;  //若为0就跳道kkk继续测试PA0口
}

void postpone_waiting2(){
asm      mov cx,60;  //总循环次数为60次
reset_si:
asm      mov si,0;  //si寄存器清0
read_0832:
asm      mov al,data1[si]; //取正弦波数据
asm      mov dx,290h; //DAC 0832模拟信号输出口地址
asm      out dx,al; //放音
asm      mov dx,283h; //初始化8253控制寄存器
asm      mov al,10h;  //8253计数器0为方式0
asm      out dx,al;
asm      mov dx,28bh; //初始化8255控制寄存器
asm      mov al,9bh; //8255A口输入
asm      out dx,al;
asm      mov dx,280h; //8253计数器0地址
asm      mov al,ah;
asm      out dx,al;
test_PA0:
asm      mov dx,288h;
asm      in al,dx;
asm      test al,01;
asm      jz  test_PA0;
asm      inc si;
asm      cmp si,32;
asm      jl read_0832;
asm      loop reset_si;
}

没有更多推荐了,返回首页