This presentation is the property of its rightful owner.
Sponsored Links
1 / 150

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


  • 174 Views
  • Uploaded on
  • Presentation posted in: General

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

Download Presentation

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

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


3

3


3

ASCII0~601

AH

AL

ASCII

ASCII

/

ASCII

0

3

INT 9HROMBIOSASCIIASCIIAX


3

3

bios.hbioskey()

int86()BIOSINT 16H

0AH

conio.hkbhit()


3

3

int bioskey(int cmd)/*cmd*/

cmd=0

bioskey()28ASCII808ASCII


3

3

int bioskey(int cmd)/*cmd*/

cmd=1

bioskey()00


3

3

int bioskey(int cmd)/*cmd*/

cmd=2

bioskey()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

3

/* */

int getKeySCode()

{

union REGS rg;

rg.h.ah=0;

int86(0x16,&rg,&rg);

return rg.h.ah;

}


3

3

int kbhit(void);

10


3

3

DOSTurbo C 2.0INT 33H


3

3

/**/

void cursorOn()

{

union REGS r

struct SREGS s

r.x.ax1; /* 1: */

msvisibleTRUE

int86x(0x33&r&r&s)

}


3

3

/**/

void cursorOff()

{

union REGS r

struct SREGS s

r.x.ax2; /* 2: */

msvisibleFALSE

int86x(0x33&r&r&s)

}


3

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

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

3

/**/

void wait(int i)

{

do {

mouseread();

} while(mousekey==i);

}


3

3


3

3


3

3


3

3

(VRAM)VRAMASCIIROMVRAMVRAM


3

Turbo C

3


3

3

Turbo C

void textmode(int newmode)


3

void textbackground(int color)/**/

void textcolor(int color) /**/

void textattr(int attr)/**/

3


3

3

Turbo C

void window(int left, int top, int right, int bottom)

lefttoprightbottom


3

3

int cprintf(char *format)

int cputs(char *str)

int putch(int ch)

/**/

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


3

3

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

void clreol(void); /*

*/

void delline(void); /**/


3

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

3

tab


3

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

xy

3


3

3


3

enum graphics_driver{DETECTCGAMCGAEGAEGA64EGAMONOIBM 8514HERCMONOATT400VGAPC3270}

3

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


3

3

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


3

3

void far detectgraph(int far *pdriverint far *pmode)

graphdriverDETECT initgraph()detectgraph()

int graphdriver=DETECT,graphmode

initgraph(&graphdriver,&graphmode,"");


3

3

void far cleardevice(void)

void far closegraph(void)

initgraph()


3

3

void far setcolor(int color)

void far setbkcolor(int color)


3

3

void far setcolor(int color)

void far setbkcolor(int color)


3

3

CGA


3

3

CGA


3

setcolor(color)color

0

1616

3

64/256

EGA/VGA


3

void far setallpalette(struct palettetype far *palette);

#define MAXCOLORS l5

struct palattetype {

unsigned char size

signed char colors[MAXCOLORS+1]

};

3

voidfar setpalette(int index, int actual_color);

EGA/VGA


3

3

EGA/VGA


3

3

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

(x1y1)(x2y2)clipflagclipflag0

void far clearviewport(void)


3

3

void far outtext(char far *textstring)

void far outtextxy(int xint ychar far *textstring)

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


3

3

void far settextjustify(int horizint vert);


3

3

void far settextstyle(int fontint directionint char size)


3

3

#include <graphics.h>

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

3


3

3

void far moveto(int xint y)

(xy)

void far moverel(int dxint dy)

(xy)(x+dxy+dx)

int far getx(void)

x

int far gety(void)

y


3

3

void far putpixel(int xint yint color);

xycolor

int far getpixel(int xint y)

putpixel()(xy)


3

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

setlinestyle(40xF3D01)

3

void far setlinestyle(int linestyleunsigned upatternint thickness)


3

3

BIOS

BIOS10HAH

AH=00HALAL=13HVGA256320200

AH=0CHALCXDX


3

3

  • BIOS

256

inreg.h.al=i; /**/

inreg.h.ch=0; /**/

inreg.h.cl=i;

inreg.h.dh=0;

inreg.h.dl=j;

int86(0x10,&inreg,&outreg);

}

getch();

inreg.h.ah=0;

inreg.h.al=2; /**/

int86(0x10,&inreg,&outreg);

}

#include<dos.h>

#include<conio.h>

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<256;i++)

for(j=0;j<200;j++)

{

inreg.h.ah=0x0c;/**/


3

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


3

3

Windows2000/XPINT 331line()


3

3


3

3

void far setfillstyle(int patternint color)

colorpattern


3

3

void far setfillstyle(int patternint color)


3

3

void far setfillpattern(char upattefnint color)

colorupattern888881color0


3

3

void far fillsettings(struct fillsettingstype far *fillinfo);

void far getfillpattern(char *upattern)


3

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

3

void far floodfill(int xint yint border)

(xy)border


3

3

#include <graphics.h>

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

3


3

3

:

1 VRAMVRAM

2


3

3

VRAM

VRAM


3

3

VRAM

  • CGAVRAMB8000HVGAEGAA0000H

  • CGAVRAM16KVGAEGAVRAM256K464K0-364KVRAM44

  • SVGA512KVRAM64KA0000H


3

3

  • 0x3ce40x3cf

  • outportb(0x3ce, 4); /*4*

  • /outportb(0x3cf, n); /*n*/


3

3

  • 0x3c420x3c5

  • outportb(0x3c4, 2); /*2*/

  • outportb(0x3c5, k); /**/


3

3

VRAM

  • CGA4320200B0000HVRAM02VRAM

  • 16KVRAMB800:0000B800:1000


3

3

VRAM

  • VGAA0000H1664048084416


3

3

VRAM

  • 256320200SVGA256


3

3


3

3

3-13

COPY_PUT

0

XOR_PUT

1

OR_PUT

2

AND_PUT

3

NOT_PUT

4


3

3

16pic.datpic.datVGA


3

3

VGAVRAMA0000H0xA000:0x0000

VRAMptr=(charfar*)0xa0000000L;

VGAHI6404801618A0000H38400

0


3

3

/**/

void save_pic(char *fname)

{

FILE *fp;

int i;

long j;

char far *ptr;

fp=fopen(fname,"wb");

for (i=0;i<4; i++)

{

outportb(0x3ce, 4);

/**/

outportb(0x3cf, i);

/*i*/

ptr=(char far*)0xa0000000L;

/*VGAVRAM*/

for (j=0;j<38400L;j++)

{

fputc(*ptr, fp);

ptr++;

}

}

fclose(fp);

outport(0x3cf,0);

}


3

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<4; i++)

{

outportb(0x3c4, 2);

/**/

outportb(0x3c5, k);

/**/

ptr=(char far*)0xa0000000L;

/*VGAVRAM*/

for (j=0;j<38400L;j++)

/**/

{

*ptr=fgetc(fp);

/* VRAM*/

ptr++;

/*1*/

}

k=k*2;

}

fclose(fp);

getch();

outport(0x3c5,0xf);

/**/

}


3

3

  • BMPJPEGGIFTIFF


3

3

BMP

  • BMP4

  • RGB


3

3

BMP

  • 4DWORD


3

3

BMP

  • BMP

  • 8256BMPRGB

  • 1624RGB


3

3

BMP


3

3

BMP


3

3

BMP


3

3

BMP

  • Turbo CBGI

    • VGA

  • VRAM


3

3

BMP

  • 256

    • VGA320200

    • SVGA6404808006001024768

  • BIOSSVGA

  • SVGAVESAWindowsXPVESA


3

3

BMP

  • VESA

  • SVGAVRAM(256)

  • VRAM64KBVRAM(I/O)


3

3

SVGABMP

256640480 SVGABMP


3

3

SVGABMP

/*bmp*/

typedef struct tagBITMAPFILEHEADER

{

int bfType; /* 'BM' OS/2*/

long bfSize; /* */

int bfReserved1; /*0*/

int bfReserved2; /*0*/

long bfOffBits; /**/

/**/

/**/

/* */

} BITMAPFILEHEADER;


3

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

3

SVGABMP

/**/

typedef struct tagRGBQUAD

{

char rgbBlue; /**/

char rgbGreen; /**/

char rgbRed; /**/

char rgbReserved;

} RGBQUAD;


3

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

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

3

SVGABMP

/*SVGA*/

unsigned int get_SVGA_mode()

{

union REGS r;

r.x.ax=0x4f03;

int86(0x10,&r,&r);

return(r.x.bx);

}


3

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


3

3

  • 25


3

3

cleardevice()delay()


3

3

    • xx

  • (setviewpot())()


3

3

movebar(int xorig) /**/

{

setviewport(xorig,0,639,199,1);

setcolor(5);

bar3d(10,120,60,150,40,1);

floodfill(70,130,5);

floodfill(30,110,5);

delay(250000);

clearviewport();

}

#include <graphics.h>

#include <dos.h>

main()

{

int i,graphdriver,graphmode;

graphdriver=DETECT;

initgraph(&graphdriver,&graphmode,);

for(i=0;i<25;i++)

{

setfillstyle(1,i);

movebar(i * 20);

}

closegraph();

}


3

3

xxclearviewportmovebardelay(250000)xx


3

3


3

3

getimage()putimage()


3

3

  • VRAM64KVRAM

  • Turbo C4(EGALO)(CGA)()0


3

3

0


3

3

    • void far setactivepage(int pagenum);

    • void far setvisualpage(int pagenum);

  • EGAVGApagenum


3

3

l(0)00doldelay(2000)2000202delay


3

3

#include <graphics.h>

#include <dos.h>

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<0)

page=1;

} while(!kbhit());

getch();

closegraph();

}


3

3


3

3

void sound(unsigned frequency)

void nosound(void)


3

3

void sound(unsigned frequency)

void nosound(void)

void delay (unsigned milliseconds)


3

3

10000 milliseconds pc5000hz

/*10000 milliseconds pc5000hz */

#include<dos.h>

main()

{

int freq;

for(freq=50;freq<5000;freq+=50)

{

sound (freq);

delay(10000);

}

nosound();

}


3

3

sound

delay


3

3

  • 3006009001200

    • E

    • H

    • M

    • L


3

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

3


3

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

3

i=0;

while(i<96&&!kbhit())

{

sound(freq[i]); /**/

delay(1100*dely[i]); /* */

i++;

}

nosound();


3

3


3

3

  • ASCII

  • ASCII128

  • GB2312 => GBK => GB18030


3

3

  • 70

  • ASCII1

  • 3473H0 0 1 1 0 1 0 0 0 1 1 1 0 0 1 1

  • B4F3H1 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1


3

3

10

T00FE101010101010


3

3

161624243232484864641616132


3

3

  • 16161616

  • 949494


3

3

QhWhQhWh161632Offset

Offset =94Qh-1+Wh-132


3

3

  • h2h1l2l1QhWh

  • Qh= h2h1-0xa0; Wh= l2l1-0xa0

  • dld2

  • Qh=dl-l60Wh=d2-160

  • qw

  • qw=100* QhWh;

  • qw

  • Qh=qw/100 Wh=qw-100*Qh;


3

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

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

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<16;++i) {

x=x0;

pos=2*i;

for(j=0;j<16;++j){

/*1*/

if ((mask[j%8]&mat[pos+j/8])!=NULL)

putpixel(x,y,color);

++x;

}

++y;

}

}


3

3

dishz()

dishz()mask[]0putpixel(x,y,color)xycolor0mask[]mask[j%8]&mat[pos+j/8][pos+j/8][j%8]


3

3


3

3

Turbo Cdelay()


3

3

Turbo C


3

3

Turbo Cinterruptmyp

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


3

3

  • void interrupt myp()

  • {

  • }


3

3

  • 0x200x20

  • outportb(0x200x20)

  • disable()enable()


3

3


3

3

  • void install(void interrupt (*faddr)()int inum)

  • {

  • disable()

  • setvect(inumfaddr);

  • enable();

  • }

  • faddr

  • inum

  • setvect()


3

3

(outportb(,)


3

3

1) geninterrupt()

setvectgeninterrupt()

2)

setvect(myp)myp()

(* myp)();


3

3

3) Turbo C

setvect (inummyp)

...

asm int inum

...


3

3

4

getvect()j=(char *)getvect(inum)jinum

setvect(inumj)


3

3

18.2HzIRQ80x1c0x1c


3

3

volatile int target_cycle; /* volatile */

volatile int actual_cycle;

do { /* */

if (target_cycle>actual_cycle || (target_cycle<0 && actual_cycle>0)) {

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

3

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


3

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);


  • Login