第 3 章 高级编程技术的实现

Click here to load reader

download 第 3 章 高级编程技术的实现

of 150

description

主要内容. 第 3 章 高级编程技术的实现 . 操作手段 显示方式 图形绘制技术 图像技术 动画技术 发声技术 汉字显示技术 精确的时间控制技术 . 它不是 ASCII 码;其0~6位标识了每个键在键盘上的位置,最高位为0对应该键是被按下;1对应松开;它并不能区别大小写字母,而且一些特殊键不产生扫描码直接引起中断调用 . 键名. AH. AL. 字符键. ASCII 码. ASCII 码. 功能键/组合键. 扩充码的 ASCII 码. 0. 第 3 章 高级编程技术的实现. ——原理. 操作手段:键盘. - PowerPoint PPT Presentation

Transcript of 第 3 章 高级编程技术的实现

  • 3 *

  • 3

    INT 9HROMBIOSASCIIASCIIAX *

  • 3

    bios.hbioskey()int86()BIOSINT 16H 0AH conio.hkbhit()*

  • 3

    int bioskey(int cmd)/*cmd*/cmd=0bioskey()28ASCII808ASCII*

  • 3

    int bioskey(int cmd)/*cmd*/cmd=1bioskey()00*

  • 3

    int bioskey(int cmd)/*cmd*/cmd=2bioskey()8 16 0 0x01shift 1 0x02 shift 2 0x04Ctrl 3 0x08 Alt 4 0x10 Scroll Lock 5 0x20Num Lock 6 0x40Caps Lock 7 0x80 Insert*

  • 3

    /* */int getKeySCode(){union REGS rg; rg.h.ah=0;int86(0x16,&rg,&rg);return rg.h.ah;} *

  • 3

    int kbhit(void); 10 *

  • 3

    DOSTurbo C 2.0INT 33H*

  • 3

    /**/void cursorOn(){ union REGS r struct SREGS s r.x.ax1; /* 1: */ msvisibleTRUE int86x(0x33&r&r&s)} *

  • 3 /**/void cursorOff(){ union REGS r struct SREGS s r.x.ax2; /* 2: */ msvisibleFALSE int86x(0x33&r&r&s)}

    *

  • 3 /**/void cursorXY(unsigned int x, unsigned int y){ union REGS r; struct SREG s; r.x.ax=4; /* 4: */ r.x.cx=x; /* x */ r.x.dx=y; /* y */ int86x(0x33&r&r&s); mousex=x; mousey=y;}

    *

  • 3 /**/void mouseRead(){ union REGS rl,r2; struct SREGS s; r1.x.ax=3; /* 3: */ int86x(0x33&r1r2&s) mousex=r2.x.cx;/*x*/ mousey=r2.x.dx;/*y*/ mousekey=r2.x.bx;/**/} *

  • 3 /**/void wait(int i){ do { mouseread(); } while(mousekey==i);}

    *

  • 3 *

  • 3

    *

  • 3

    *

  • 3

    (VRAM)VRAMASCIIROMVRAMVRAM *

  • 3

    *

  • 3

    Turbo C void textmode(int newmode) *

  • 3

    *

  • 3

    Turbo C void window(int left, int top, int right, int bottom)lefttoprightbottom *

  • 3

    int cprintf(char *format) int cputs(char *str) int putch(int ch)/**/

    void gotoxy(int x, int y); /*(x,y)*/

    *

  • 3

    void clrscr(void); /*(1,1)*/

    void clreol(void); /* */

    void delline(void); /**/*

  • 3

    void movetext(int x1, int y1, int x2, int y2, int x3, int y3);void gettext(int x1, int y1, int x2, int y2, void *buffer);void puttext(int x1, int y1, int x2, int y2, void *buffer);

    *

  • 3

    tab *

  • 3

    window (int x1, int y1, int x2, int y2)textcolor (int color)textbackground (int color)clrscr (void)tabgettext (int left, int top, int right, int bottom, void * buf)bufputtext (int left, int top, int right, int bottom, void * buf)bufgotoxy (int x, int y) *

  • 3

    *

  • 3

    *

  • 3

    *

  • 3

    void far initgraph(int far *pdriverint far *pmodechar far *ppath_for_driver)*

  • 3

    void far initgraph(int far *pdriverint far *pmodechar far *ppath_for_driver)*

  • 3

    void far detectgraph(int far *pdriverint far *pmode) graphdriverDETECT initgraph()detectgraph() int graphdriver=DETECT,graphmodeinitgraph(&graphdriver,&graphmode,""); *

  • 3

    void far cleardevice(void) void far closegraph(void) initgraph()*

  • 3

    void far setcolor(int color) void far setbkcolor(int color)

    *

  • 3

    void far setcolor(int color) void far setbkcolor(int color)

    *

  • 3

    CGA

    *

  • 3

    CGA

    *

  • 3

    EGA/VGA

    64/256*

  • 3

    EGA/VGA

    voidfar setpalette(int index, int actual_color); *

  • 3

    EGA/VGA

    *

  • 3

    void far setviewport(int xlint y1int x2int y2, clipflag); (x1y1)(x2y2)clipflagclipflag0

    void far clearviewport(void)*

  • 3

    void far outtext(char far *textstring)

    void far outtextxy(int xint ychar far *textstring)

    int sprintf(char *string, char *format[, argument, ]);*

  • 3

    void far settextjustify(int horizint vert); *

  • 3

    void far settextstyle(int fontint directionint char size) *

  • 3 #include main(){ int i,graphdriver,graphmode,size,page; char s[30]; graphdriver=DETECT; initgraph(&graphdriver,&graphmode,""); cleardevice(); settextstyle(DEFAULT_FONT,HORIZ_DIR,2); settextjustify(LEFT_TEXT,0); outtextxy(220,20,"Defaut font"); settextstyle(TRIPLEX_FONT,HORIZ_DIR, 2); settextjustify(LEFT_TEXT,0); outtextxy(220,50,"Triplex font"); settextstyle(SMALL_FONT,HORIZ_DIR, 2);settextjustify(LEFT_TEXT,0);outtextxy(220,80,"Smallfont");settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);settextjustify(LEFT_TEXT,0);outtextxy(220,110,"Sans serif font");settextstyle(GOTHIC_FONT,HORIZ_DIR, 2);settextjustify(LEFT_TEXT,0);outtextxy(220,140,"gothic font");getch(); closegraph(); }

    *

  • 3 *

  • 3 *

  • 3

    void far moveto(int xint y)(xy)void far moverel(int dxint dy)(xy)(x+dxy+dx)

    int far getx(void)xint far gety(void)y

    *

  • 3

    void far putpixel(int xint yint color);xycolor int far getpixel(int xint y)putpixel()(xy) *

  • 3

    void far line(int x0int y0int x1int y1)(x0y0)(x1y1)

    void far lineto(int xint y)(xy)

    void far linerel(int dxint dy) (xy) (x+dxy+dy) *

  • 3 void far setlinestyle(int linestyleunsigned upatternint thickness)

    *

  • 3 BIOS10HAH AH=00HALAL=13HVGA256320200 AH=0CHALCXDX

    BIOS*

  • 3 #include#include int main(){ int i,j; union REGS inreg,outreg; inreg.h.ah=0; /**/ inreg.h.al=0x13; /* VGA256320200 */ int86(0x10,&inreg,&outreg); /*0x10*/ for (i=0;i
  • 3 void far rectangle(int xlint y1int x2int y2)

    void ellipse(int xint yint stangleint endangel int xradiusint yradius) void far circle(int xint yint radius) void far arc(int xint yint stangleint endangle int radius)*

  • 3 *

  • 3 Windows2000/XPINT 331line() *

  • 3 *

  • 3 void far setfillstyle(int patternint color)colorpattern *

  • 3 void far setfillstyle(int patternint color)*

  • 3 void far setfillpattern(char upattefnint color)colorupattern888881color0 *

  • 3 void far fillsettings(struct fillsettingstype far *fillinfo); void far getfillpattern(char *upattern) *

  • 3 (setfillstyle ) void bar(int x1int y1int x2int y2) void far pieslice(int xint yint stangleint endangleint radius) void far bar3d(int x1int y1int x2int y2int depthint topflag)void far sector(int xint yint stangleint endang1eint xradiusint yradius)void far fillellipse(int xint yint xradiusint yradius) void far fillpoly(int numpointsint far polypoints)*

  • 3 void far floodfill(int xint yint border) (xy)border *

  • 3 #include main(){ int i, graphdriver,graphmode,size,page; char s[30]; graphdriver=DETECT; initgraph(&graphdriver,&graphmode,""); cleardevice(); setbkcolor(BLUE); setviewport(40,40,600,440,1); /**/ setfillstyle(1,2); setcolor(YELLOW); rectangle(0,0,560,400); floodfill(50,50,14); /**/ rectangle(20,20,540,380); setfillstyle(1,13); floodfill(2l,300,14); /**/ setcolor(BLACK); settextstyle(1,0,6); /*,*/ outtextxy(100,60,"Welcom You"); setviewport(100,200,540,380,0); setcolor(14); setfillstyle(1,12); rectangle(20,20,420,120); settextstyle(2,0,9); floodfill(21,100,14); /**/ sprintf(s,Lets study Turbo C); setcolor(YELLOW); outtextxy(60,40, s);/**/ setcolor(1); settextstyle(4,0,3); outtextxy(110,80,s); getch(); closegraph();} *

  • 3 *

  • 3 *

  • 3 :

    1 VRAMVRAM 2*

  • 3 VRAM

    VRAM

    *

  • 3 VRAM

    CGAVRAMB8000HVGAEGAA0000HCGAVRAM16KVGAEGAVRAM256K464K0-364KVRAM44 SVGA512KVRAM64KA0000H *

  • 3

    0x3ce40x3cfoutportb(0x3ce, 4); /*4*/outportb(0x3cf, n); /*n*/

    *

  • 3

    0x3c420x3c5outportb(0x3c4, 2); /*2*/outportb(0x3c5, k); /**/

    *

  • 3 VRAM

    CGA4320200B0000HVRAM02VRAM16KVRAMB800:0000B800:1000*

  • 3 VRAM

    VGAA0000H1664048084416*

  • 3 VRAM

    256320200SVGA256 *

  • 3

    *

    unsigned far imagesize(int x1int y1int x2int y2)void far getimage(int x1int y1int x2int y2void far *bitmap)void far putimage(int x1int y1void far *bitmapint op)

  • 3

    *

  • 3

    16pic.datpic.datVGA *

  • 3

    VGAVRAMA0000H0xA000:0x0000 VRAMptr=(charfar*)0xa0000000L; VGAHI6404801618A0000H384000 *

  • 3

    /**/

    void save_pic(char *fname){ FILE *fp; int i; long j; char far *ptr; fp=fopen(fname,"wb"); for (i=0;i

  • 3

    /**/void load_pic(char *fname){ FILE *fp; int i,k=1; long j; char far *ptr; fp=fopen(fname,"rb"); for (i=0;i

  • 3

    BMPJPEGGIFTIFF *

  • 3 BMP

    BMP4RGB

    *

  • 3 BMP

    4DWORD*

  • 3 BMP

    BMP8256BMPRGB1624RGB*

  • 3 BMP

    *

    0000h2 bytesBMP 0002hFile Size1 dword0006hReserved1 dword0000AhBitmap Data Offset1 dword000EhBitmap Header Size1 dword(Bitmap Info Header)0012hWidth1 dword0016hHeight1 dword001AhPlanes1 word1

  • 3 BMP

    *

    001ChBits Per Pixel1 word1 - 4 - 16 8 - 256 16 - 16bit 24 - 24bit 32 - 32bit 001EhCompression1 dword0 - 0022hBitmap Data Size1 dword40026hHResolution1 dword/002AhVResolution1 dword/002EhColors1 dword8-/100h 256.0032hImportant Colors1 dword0

  • 3 BMP

    *

    BMPPaletteN * 4 byte4RGBBMPBitmap Dataxxx bytesRGB

  • 3 BMP

    Turbo CBGIVGA

    VRAM

    *

  • 3 BMP

    256VGA320200SVGA6404808006001024768BIOSSVGASVGAVESAWindowsXPVESA*

  • 3 BMP

    VESASVGAVRAM(256)VRAM64KBVRAM(I/O)

    *

  • 3 SVGABMP

    256640480 SVGABMP *

  • 3 SVGABMP

    /*bmp*/typedef struct tagBITMAPFILEHEADER{ int bfType; /* 'BM' OS/2*/ long bfSize; /* */ int bfReserved1; /*0*/ int bfReserved2; /*0*/ long bfOffBits; /**//**//**//* */} BITMAPFILEHEADER;

    *

  • 3 SVGABMP

    /**/typedef struct tagBITMAPINFOHEADER{ long biSize; /* */ long biWidth; /* */ long biHeight; /* */ int biPlanes; /* 1 */ int biBitCount; /* 1, 4, 824 */ long biCompression; /* */ long biSizeImage; /* 4 */ long biXPelsPerMeter; /* */ long biYPelsPerMeter; /* */ long biClrUsed; /* */ long biClrImportant; /* */} BITMAPINFOHEADER; *

  • 3 SVGABMP

    /**/typedef struct tagRGBQUAD{ char rgbBlue; /**/ char rgbGreen; /**/ char rgbRed; /**/ char rgbReserved;} RGBQUAD; *

  • 3 SVGABMP

    /**/void selectpage(register char page) {union REGS r;r.x.ax=0x4f05;r.x.bx=0;r.x.dx=page; /**/int86(0x10,&r,&r);} *

  • 3 SVGABMP

    /*SVGA*//*101H----256640480*//*103H----256800600*//*105H----2561024768*/unsigned char set_SVGA_mode(int vmode){union REGS r;r.x.ax=0x4f02;r.x.bx=vmode;int86(0x10,&r,&r);return(r.h.ah);} *

  • 3 SVGABMP

    /*SVGA*/unsigned int get_SVGA_mode(){union REGS r;r.x.ax=0x4f03;int86(0x10,&r,&r);return(r.x.bx);} *

  • 3 SVGABMP

    /**/void set_SVGA_palette(unsigned char r[], unsigned char g[], unsigned char b[]){int k; for (k = 0; k < 256; k++) { outportb(0x03C8,k);outportb(0x03C9,r[k]>>2);outportb(0x03C9,g[k]>>2);outportb(0x03C9,b[k]>>2);}} *

  • 3 *

  • 3

    25

    *

  • 3

    cleardevice()delay() *

  • 3

    xx(setviewpot())()*

  • 3

    #include #include main(){ int i,graphdriver,graphmode; graphdriver=DETECT; initgraph(&graphdriver,&graphmode,); for(i=0;i

  • 3 xxclearviewportmovebardelay(250000)xx *

  • 3

    *

  • 3

    getimage()putimage()*

  • 3 VRAM64KVRAM Turbo C4(EGALO)(CGA)()0*

  • 3 0*

  • 3 void far setactivepage(int pagenum); void far setvisualpage(int pagenum);EGAVGApagenum*

  • 3

    l(0)00doldelay(2000)2000202delay *

  • 3

    #include #include main(){ int i,graphdriver,graphmode,size,page; graphdriver=DETECT; initgraph(&graphdriver,&graphmode,""); cleardevice(); setactivepage(1);/*l*/ setbkcolor(BLUE); setcolor(RED); setfillstyle(1,10); circle(130,270,30);/**/ floodfill(130,270,4);/**/ setactivepage(0);/*0*/ cleardevice();/*0*/ setfillstyle(1,5); bar(100,210,160,270);/**/ setvisualpage(0); /*0*/ page=1; do { setvisualpage(page);/**/ delay(2000); /*2000ms*/ page=page-1; if(page

  • 3 *

  • 3

    void sound(unsigned frequency) void nosound(void) *

  • 3

    void sound(unsigned frequency) void nosound(void) void delay (unsigned milliseconds) *

  • 3

    10000 milliseconds pc5000hz/*10000 milliseconds pc5000hz */#includemain(){ int freq; for(freq=50;freq

  • 3

    sounddelay

    *

  • 3

    3006009001200EHML*

  • 3

    0.5 600 H1 0.5 H1 0.5 H1 0.5 M7 0.5 M6 1 H3 1 H2 0.5 H3 0.5 H2 0.5 M6 0.5 H2 1*

  • 3

    *

    11311262152311047214722962587211753165333036593131941764349469941397519653925784515686220644068806176072477494798871976

  • 3

    freq[96]dely[96]printtext()Welcome !Please press any key to start ......Enjoy yourself !Press any key to end ! Thank you! Bye Bye ......conio.h kbhit()0 *

  • 3

    i=0; while(i

  • 3 *

  • 3

    ASCIIASCII128GB2312 => GBK => GB18030*

  • 3

    70ASCII13473H0 0 1 1 0 1 0 0 0 1 1 1 0 0 1 1B4F3H1 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1*

  • 3

    10T00FE101010101010*

  • 3

    161624243232484864641616132*

  • 3

    16161616949494*

  • 3

    QhWhQhWh161632OffsetOffset =94Qh-1+Wh-132 *

  • 3

    h2h1l2l1QhWhQh= h2h1-0xa0; Wh= l2l1-0xa0dld2Qh=dl-l60Wh=d2-160qwqw=100* QhWh;qwQh=qw/100 Wh=qw-100*Qh;*

  • 3 /**/void open_hzk(){ hzk_p=fopen(d:/zy/tc/hzk16,rb); if (!hzk_p){ printf("The file HZK16 not exist! Enter to system\n"); getch(); closegraph(); exit(1); }}*

  • 3 /**/ void get_hz(char incode[],char bytes[]){ unsigned char qh,wh; unsigned long offset; qh=incode[0]-0xa0;/**/ wh=incode[1]-0xa0;/**/ offset=(94*(qh-1)+(wh-1))*32L;/**/ fseek(hzk_p,offset,SEEK_SET); /**/ fread(bytes,32,1,hzk_p); /*32*/}*

  • 3 void dishz(int x0,int y0,char code[],int color){ unsigned char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; /**/ int i,j,x,y,pos; char mat[32]; get_hz(code,mat); y=y0; for (i=0;i
  • 3 dishz()dishz()mask[]0putpixel(x,y,color)xycolor0mask[]mask[j%8]&mat[pos+j/8][pos+j/8][j%8]*

  • 3 *

  • 3

    Turbo Cdelay()*

  • 3

    Turbo C*

  • 3

    Turbo Cinterruptmypvoid interrupt myp(unsigned bpunsiened diunsigned siunsigned dsunsigned es,unsigned dxunsigned cxunsigned bxunsigned axunsigned ip,unsigned csunsigned flags);

    *

  • 3

    void interrupt myp(){}*

  • 3

    0x200x20outportb(0x200x20) disable()enable()*

  • 3

    *

  • 3

    void install(void interrupt (*faddr)()int inum){ disable() setvect(inumfaddr); enable();} faddr inum setvect()*

  • 3

    (outportb(,)*

  • 3

    1) geninterrupt() setvectgeninterrupt()2) setvect(myp)myp()(* myp)();*

  • 3

    3) Turbo Csetvect (inummyp)...asm int inum...

    *

  • 3

    4getvect()j=(char *)getvect(inum)jinumsetvect(inumj)*

  • 3

    18.2HzIRQ80x1c0x1c*

  • 3

    volatile int target_cycle; /* volatile */ volatile int actual_cycle;

    do { /* */ if (target_cycle>actual_cycle || (target_cycle0)) { action_loop(); /* */ actual_cycle++; } if (exit_flag==1) { /* */ } } while (1);

    /* 0x1c */ void far interrupt new_timer(void) { extern volatile int target_cycle; target_cycle++; outportb(0x20, 0x20); }*

  • 3

    0x3da(inportb(0x3da)&0x08)460Hz24Hz10*

  • 3

    do { /* */

    /* (60Hz) */ if ((inportb(0x3da)&0x08)!=0 && action_flag==0) /* */ { /* */ action_flag=1; } else if ((inportb(0x3da)&0x08)==0 && action_flag==1) /* */ { /* */ action_flag=0; } } while (1);*